diff --git a/src/main/java/cn/teammodel/controller/frontend/NewsController.java b/src/main/java/cn/teammodel/controller/frontend/NewsController.java index dacac5a..f30d468 100644 --- a/src/main/java/cn/teammodel/controller/frontend/NewsController.java +++ b/src/main/java/cn/teammodel/controller/frontend/NewsController.java @@ -32,6 +32,14 @@ public class NewsController { return R.success(Newss); } + @GetMapping("get/{newsId}") + @ApiOperation("根据id查询新闻") + public R getNewsById(@PathVariable String newsId) { + News news = newsService.getNewsById(newsId); + return R.success(news); + } + + @PostMapping("create") @ApiOperation("创建新闻") public R createNews(@RequestBody @Valid CreateNewsDto createNewsDto) { diff --git a/src/main/java/cn/teammodel/service/NewsService.java b/src/main/java/cn/teammodel/service/NewsService.java index 79b6e7a..bd351d0 100644 --- a/src/main/java/cn/teammodel/service/NewsService.java +++ b/src/main/java/cn/teammodel/service/NewsService.java @@ -20,4 +20,6 @@ public interface NewsService { News updateNews(UpdateNewsDto updateNewsDto); void deleteNews(IdRequest idRequest); + + News getNewsById(String newsId); } diff --git a/src/main/java/cn/teammodel/service/impl/NewsServiceImpl.java b/src/main/java/cn/teammodel/service/impl/NewsServiceImpl.java index da8ed3c..5c0642f 100644 --- a/src/main/java/cn/teammodel/service/impl/NewsServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/NewsServiceImpl.java @@ -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; + } } diff --git a/src/test/java/cn/teammodel/TestWithoutSpring.java b/src/test/java/cn/teammodel/TestWithoutSpring.java index 21568bc..5ebe81a 100644 --- a/src/test/java/cn/teammodel/TestWithoutSpring.java +++ b/src/test/java/cn/teammodel/TestWithoutSpring.java @@ -144,13 +144,13 @@ public class TestWithoutSpring { @Test public void testLocalDateTime() { List 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));