feat: 新增通过 id 查询新闻

11111
winter 10 months ago
parent 94ac4286c3
commit 29f1fed4f1

@ -32,6 +32,14 @@ public class NewsController {
return R.success(Newss);
}
@GetMapping("get/{newsId}")
@ApiOperation("根据id查询新闻")
public R<News> getNewsById(@PathVariable String newsId) {
News news = newsService.getNewsById(newsId);
return R.success(news);
}
@PostMapping("create")
@ApiOperation("创建新闻")
public R<News> createNews(@RequestBody @Valid CreateNewsDto createNewsDto) {

@ -20,4 +20,6 @@ public interface NewsService {
News updateNews(UpdateNewsDto updateNewsDto);
void deleteNews(IdRequest idRequest);
News getNewsById(String newsId);
}

@ -83,4 +83,11 @@ public class NewsServiceImpl implements NewsService {
throw new ServiceException(ErrorCode.NO_AUTH_ERROR.getCode(), "您没有权限删除该新闻");
}
}
@Override
public News getNewsById(String newsId) {
String schoolId = SecurityUtil.getLoginUser().getSchoolId();
News news = newsRepository.findById(newsId, PK.buildOf(PK.NEWS, schoolId)).orElse(null);
return news;
}
}

@ -144,13 +144,13 @@ public class TestWithoutSpring {
@Test
public void testLocalDateTime() {
List<School.Semester> semesters = Arrays.asList(
new School.Semester("1", "下学期", 1, 2, 1), // 2024-3 , 正确: 2023-3
new School.Semester("17f85c96-253d-4f84-84ad-c819f0b605s2", "下学期", 0, 2, 17), // 2024-3 , 正确: 2023-3
// new School.Semester("2", "下学期", 0, 5, 1),
new School.Semester("3", "上学期", 0, 8, 1)
new School.Semester("08b81e76-e7d2-4001-8b4c-e7c789ef4bs1", "上学期", 1, 8, 1)
// new School.Semester("4", "下学期", 0, 11, 1)
);
LocalDate currentDate = LocalDate.of(2024, 1, 1);
LocalDate currentDate = LocalDate.of(2024, 2, 21);
// String id = SchoolDateUtil.calculateAcademicYearId(semesters, currentDate);
System.out.println(SchoolDateUtil.getSemesterByNow(semesters, currentDate));

Loading…
Cancel
Save