11package com .example .Jinus .controller .v2 ;
22
33import com .example .Jinus .dto .request .RequestDto ;
4- import com .example .Jinus .dto .response .*;
5- import com .example .Jinus .entity .notice .NoticeCategoryEntity ;
64import com .example .Jinus .service .v2 .notice .CategoryServiceV2 ;
75import com .example .Jinus .service .v2 .notice .NoticeServiceV2 ;
86import com .example .Jinus .service .v2 .userInfo .DepartmentServiceV2 ;
97import com .example .Jinus .service .v2 .userInfo .UserServiceV2 ;
10- import com .example .Jinus .utility .JsonUtils ;
11- import com .example .Jinus .utility .TextCardResponse ;
8+ import lombok .RequiredArgsConstructor ;
129import org .springframework .web .bind .annotation .PostMapping ;
1310import org .springframework .web .bind .annotation .RequestBody ;
1411import org .springframework .web .bind .annotation .RequestMapping ;
1512import org .springframework .web .bind .annotation .RestController ;
1613
17- import java .util .ArrayList ;
18- import java .util .List ;
19-
20- import static java .lang .String .valueOf ;
21-
2214@ RestController
15+ @ RequiredArgsConstructor
2316@ RequestMapping ("/api/spring" )
2417public class NoticeControllerV2 {
2518
2619 private final NoticeServiceV2 noticeServiceV2 ;
27- private final CategoryServiceV2 noticeCategoryServiceV2 ;
2820 private final DepartmentServiceV2 departmentServiceV2 ;
2921 private final UserServiceV2 userServiceV2 ;
3022
31- public NoticeControllerV2 (NoticeServiceV2 noticeServiceV2 ,
32- CategoryServiceV2 noticeCategoryServiceV2 ,
33- DepartmentServiceV2 departmentServiceV2 ,
34- UserServiceV2 userServiceV2 ) {
35- this .noticeServiceV2 = noticeServiceV2 ;
36- this .noticeCategoryServiceV2 = noticeCategoryServiceV2 ;
37- this .departmentServiceV2 = departmentServiceV2 ;
38- this .userServiceV2 = userServiceV2 ;
39- }
40-
4123 // 학교 공지사항 조회
4224 @ PostMapping ("/v2/main-notice" )
4325 public String getMainNotice () {
4426 int departmentId = 117 ; // 학교 공지사항 id
4527 String departmentEng = "main" ; // 학과 영문명
46- return existUserReturnNotice (departmentEng , departmentId );
28+ return noticeServiceV2 . existUserReturnNotice (departmentEng , departmentId );
4729 }
4830
4931 // 학과 공지사항 조회
@@ -55,64 +37,9 @@ public String responseDepartmentNotice(@RequestBody RequestDto requestDto) {
5537 String departmentEng = departmentServiceV2 .getDepartmentEng (departmentId );
5638 // 사용자 학과 정보가 존재한다면
5739 if (departmentId != -1 ) {
58- return existUserReturnNotice (departmentEng , departmentId );
59- } else {
60- return doesNotExistUserReturnBlock ();
61- }
62- }
63-
64- // db에 학과정보가 있는 경우 -> 공지리스트 반환
65- public String existUserReturnNotice (String departmentEng , int departmentId ) {
66- // 학과 공지 카테고리들 가져오기
67- List <NoticeCategoryEntity > categoryEntities = noticeCategoryServiceV2 .getCategoryEntity (departmentId );
68-
69- // 카테고리 존재 여부 확인
70- if (!categoryEntities .isEmpty ()) {
71- return mappingCarouselItems (categoryEntities , departmentEng );
40+ return noticeServiceV2 .existUserReturnNotice (departmentEng , departmentId );
7241 } else {
73- return thereIsNoCategory ();
74- }
75- }
76-
77- // 공지가 존재하는 경우
78- public String mappingCarouselItems (List <NoticeCategoryEntity > categoryEntities , String departmentEng ) {
79- // 카테고리 리스트 생성 (캐로셀 아이템 리스트)
80- List <CarouselItemDto > categoryList = new ArrayList <>();
81- for (NoticeCategoryEntity entity : categoryEntities ) {
82- // 해당 카테고리의 공지 ListCard 생성
83- List <ListItemDto > noticeItemList = noticeServiceV2 .getNoticeList (
84- entity .getId (), valueOf (entity .getMi ()), valueOf (entity .getBbsId ()), departmentEng );
85- // ListCard 버튼 생성
86- List <ButtonDto > buttonList = noticeServiceV2 .makeButton (
87- departmentEng , valueOf (entity .getMi ()), valueOf (entity .getBbsId ()));
88- // 카테고리 제목 header 객체 생성
89- HeaderDto title = new HeaderDto (entity .getCategory ());
90- // 하나의 카테고리 아이템 생성
91- CarouselItemDto carouselItem = new CarouselItemDto (title , noticeItemList , buttonList );
92- categoryList .add (carouselItem );
42+ return noticeServiceV2 .doesNotExistUserReturnBlock ();
9343 }
94- CarouselDto carousel = new CarouselDto ("listCard" , categoryList );
95- List <ComponentDto > componentList = new ArrayList <>();
96- componentList .add (new ComponentDto (carousel ));
97- TemplateDto templateDto = new TemplateDto (componentList );
98- ResponseDto responseDto = new ResponseDto ("2.0" , templateDto );
99- return JsonUtils .toJsonResponse (responseDto );
100- }
101-
102- // 공지가 존재하지 않는 경우 예외처리
103- public String thereIsNoCategory () {
104- List <ButtonDto > buttonList = new ArrayList <>();
105- ButtonDto buttonDto = new ButtonDto ("게시판 등록 요청" , "webLink" , "https://forms.gle/cSMheFmmGDe7P3RD6" );
106- buttonList .add (buttonDto );
107- return TextCardResponse .textCardResponse ("최근에 등록된 공지사항이 없어!" , buttonList );
108- }
109-
110- // 사용자 학과 정보가 없는 경우 학과인증 블록 리턴 예외처리
111- public String doesNotExistUserReturnBlock () {
112- List <ButtonDto > buttonList = new ArrayList <>();
113- // 블록 버튼 생성
114- ButtonDto buttonDto = new ButtonDto ("학과 등록" , "block" , null ,"66cf0c8ae5715f75b254dfea" );
115- buttonList .add (buttonDto );
116- return TextCardResponse .textCardResponse ("학과 등록이 필요한 서비스야! 학과 등록을 진행해줘." , buttonList );
11744 }
11845}
0 commit comments