File tree Expand file tree Collapse file tree 10 files changed +85
-2
lines changed
src/main/java/com/neighbors/tohero
infrastructure/query/impl Expand file tree Collapse file tree 10 files changed +85
-2
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,9 @@ public enum BaseResponseMessage {
1212 토큰_재발급이_성공했습니다 ("토큰 재발급이 성공했습니다" ),
1313
1414 //notice success
15+ 공지_무한페이징_조회_성공했습니댜 ("공지 무한페이징 조회 성공했습니댜" ),
1516 공지_조회_성공했습니댜 ("공지 조회 성공했습니댜" ),
17+ 일치하는_공지가_없습니다 ("일치하는 공지가 없습니다" ),
1618
1719 //user
1820 이미_존재하는_유저입니다 ("이미 존재하는 유저입니다" ),
Original file line number Diff line number Diff line change 77public record GetNoticeResponse (List <NoticeDTO > noticeList ) {
88
99 public record NoticeDTO (
10+ long noticeId ,
1011 String title ,
1112 String content ,
1213 String createdAT
1314 ) {
1415 public static NoticeDTO from (Notice notice ) {
1516 return new GetNoticeResponse .NoticeDTO (
17+ notice .getNoticeId (),
1618 notice .getNoticeTitle (),
1719 notice .getNoticeContent (),
1820 notice .getCreatedAt ().toLocalDate ().toString ()
Original file line number Diff line number Diff line change @@ -24,9 +24,19 @@ public BaseResponse<GetNoticeResponse> getNotice(Pageable pageable){
2424
2525 return new BaseResponse <>(
2626 BaseResponseStatus .OK ,
27- BaseResponseMessage .공지_조회_성공했습니댜 .getMessage (),
27+ BaseResponseMessage .공지_무한페이징_조회_성공했습니댜 .getMessage (),
2828 GetNoticeResponse .createSuccessObjFrom (notices )
2929 );
3030 }
3131
32+ public BaseResponse <GetNoticeResponse .NoticeDTO > getNoticeDetail (long noticeId ){
33+ Notice notice = getNotice .getNotice (noticeId );
34+
35+ return new BaseResponse <>(
36+ BaseResponseStatus .OK ,
37+ BaseResponseMessage .공지_조회_성공했습니댜 .getMessage (),
38+ GetNoticeResponse .NoticeDTO .from (notice )
39+ );
40+ }
41+
3242}
Original file line number Diff line number Diff line change 1+ package com .neighbors .tohero .common .exception .notice ;
2+
3+ import com .neighbors .tohero .application .baseResponse .BaseResponseStatus ;
4+
5+ public class NoticeException extends RuntimeException {
6+
7+ private final BaseResponseStatus status ;
8+ private final String message ;
9+
10+ public NoticeException (BaseResponseStatus status , String message ) {
11+ super (message );
12+ this .status = status ;
13+ this .message = message ;
14+ }
15+ }
Original file line number Diff line number Diff line change @@ -21,4 +21,8 @@ public List<Notice> getPagedNotice(Pageable pageable) {
2121 public List <Notice > getTopNotices (int exposeNoticeNumber ){
2222 return noticeRepository .getTopNotices (exposeNoticeNumber );
2323 }
24+
25+ public Notice getNotice (long noticeId ) {
26+ return noticeRepository .getNoticeById (noticeId );
27+ }
2428}
Original file line number Diff line number Diff line change 88public interface NoticeRepository {
99 List <Notice > getPagedNotice (Pageable pageable );
1010 List <Notice > getTopNotices (int exposeNoticeNumber );
11+ Notice getNoticeById (long noticeId );
1112}
Original file line number Diff line number Diff line change 11package com .neighbors .tohero .infrastructure .query .impl ;
22
3+ import com .neighbors .tohero .application .baseResponse .BaseResponseMessage ;
4+ import com .neighbors .tohero .application .baseResponse .BaseResponseStatus ;
5+ import com .neighbors .tohero .common .exception .notice .NoticeException ;
36import com .neighbors .tohero .domain .domain .notice .model .Notice ;
47import com .neighbors .tohero .domain .query .NoticeRepository ;
58import com .neighbors .tohero .infrastructure .entity .NoticeEntity ;
1013import org .springframework .stereotype .Repository ;
1114
1215import java .util .List ;
16+ import java .util .Optional ;
1317
1418@ Repository
1519@ RequiredArgsConstructor
@@ -35,4 +39,15 @@ public List<Notice> getTopNotices(int exposeNoticeNumber) {
3539 .map (noticeMapper ::toDomain )
3640 .toList ();
3741 }
42+
43+ @ Override
44+ public Notice getNoticeById (long noticeId ) {
45+ NoticeEntity noticeEntity = noticeEntityRepository .findById (noticeId )
46+ .orElseThrow (() -> new NoticeException (
47+ BaseResponseStatus .NO_RESULT ,
48+ BaseResponseMessage .일치하는_공지가_없습니다 .getMessage ()
49+ ));
50+
51+ return noticeMapper .toDomain (noticeEntity );
52+ }
3853}
Original file line number Diff line number Diff line change 99import org .springframework .http .ResponseEntity ;
1010import org .springframework .web .bind .annotation .GetMapping ;
1111import org .springframework .web .bind .annotation .RequestMapping ;
12+ import org .springframework .web .bind .annotation .RequestParam ;
1213import org .springframework .web .bind .annotation .RestController ;
1314
1415@ RestController
@@ -24,4 +25,11 @@ public ResponseEntity<BaseResponse> getNotice(@ParameterObject Pageable pageable
2425 return ResponseEntity .ok ()
2526 .body (noticeService .getNotice (pageable ));
2627 }
28+
29+ @ Operation (summary = "공지 API" , description = "공지사항 상세보기 API입니다." )
30+ @ GetMapping ("/notice/detail" )
31+ public ResponseEntity <BaseResponse > getNoticeDetail (@ RequestParam long noticeId ){
32+ return ResponseEntity .ok ()
33+ .body (noticeService .getNoticeDetail (noticeId ));
34+ }
2735}
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public DTOFieldExceptionControllerAdvice() {
3232
3333 @ ResponseStatus (HttpStatus .BAD_REQUEST )
3434 @ ExceptionHandler (MethodArgumentNotValidException .class )
35- public ResponseEntity <BaseResponse > handle_UserValidationException (MethodArgumentNotValidException e ) {
35+ public ResponseEntity <BaseResponse > handle_fieldValidationException (MethodArgumentNotValidException e ) {
3636 BaseResponse response = new BaseResponse (
3737 BaseResponseStatus .BAD_REQUEST ,
3838 fieldErrorMapper .get (e .getBindingResult ().getFieldError ().getField ()).getMessage ()
Original file line number Diff line number Diff line change 1+ package com .neighbors .tohero .presentation .exception_handler ;
2+
3+ import com .neighbors .tohero .application .baseResponse .BaseResponse ;
4+ import com .neighbors .tohero .application .baseResponse .BaseResponseStatus ;
5+ import com .neighbors .tohero .common .exception .notice .NoticeException ;
6+ import org .springframework .http .HttpStatus ;
7+ import org .springframework .http .ResponseEntity ;
8+ import org .springframework .web .bind .annotation .ExceptionHandler ;
9+ import org .springframework .web .bind .annotation .ResponseStatus ;
10+ import org .springframework .web .bind .annotation .RestControllerAdvice ;
11+
12+ @ RestControllerAdvice
13+ public class NoticeExceptionControllerAdvice {
14+
15+ @ ResponseStatus (HttpStatus .BAD_REQUEST )
16+ @ ExceptionHandler (NoticeException .class )
17+ public ResponseEntity <BaseResponse > handle_NoticeException (NoticeException e ) {
18+ BaseResponse response = new BaseResponse (
19+ BaseResponseStatus .NO_RESULT ,
20+ e .getMessage ()
21+ );
22+
23+ return ResponseEntity .badRequest ()
24+ .body (response );
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments