From 29f1fed4f159295ea778635dce555cecc1e8798c Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Tue, 27 Feb 2024 17:17:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=80=9A=E8=BF=87=20?= =?UTF-8?q?id=20=E6=9F=A5=E8=AF=A2=E6=96=B0=E9=97=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/teammodel/controller/frontend/NewsController.java | 8 ++++++++ src/main/java/cn/teammodel/service/NewsService.java | 2 ++ .../java/cn/teammodel/service/impl/NewsServiceImpl.java | 7 +++++++ src/test/java/cn/teammodel/TestWithoutSpring.java | 6 +++--- 4 files changed, 20 insertions(+), 3 deletions(-) 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));