Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public enum BaseResponseMessage {
토큰_재발급이_성공했습니다("토큰 재발급이 성공했습니다"),

//notice success
공지_무한페이징_조회_성공했습니댜("공지 무한페이징 조회 성공했습니댜"),
공지_조회_성공했습니댜("공지 조회 성공했습니댜"),
일치하는_공지가_없습니다("일치하는 공지가 없습니다"),

//user
이미_존재하는_유저입니다("이미 존재하는 유저입니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
public record GetNoticeResponse(List<NoticeDTO> noticeList) {

public record NoticeDTO(
long noticeId,
String title,
String content,
String createdAT
) {
public static NoticeDTO from(Notice notice) {
return new GetNoticeResponse.NoticeDTO(
notice.getNoticeId(),
notice.getNoticeTitle(),
notice.getNoticeContent(),
notice.getCreatedAt().toLocalDate().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,19 @@ public BaseResponse<GetNoticeResponse> getNotice(Pageable pageable){

return new BaseResponse<>(
BaseResponseStatus.OK,
BaseResponseMessage.공지_조회_성공했습니댜.getMessage(),
BaseResponseMessage.공지_무한페이징_조회_성공했습니댜.getMessage(),
GetNoticeResponse.createSuccessObjFrom(notices)
);
}

public BaseResponse<GetNoticeResponse.NoticeDTO> getNoticeDetail(long noticeId){
Notice notice = getNotice.getNotice(noticeId);

return new BaseResponse<>(
BaseResponseStatus.OK,
BaseResponseMessage.공지_조회_성공했습니댜.getMessage(),
GetNoticeResponse.NoticeDTO.from(notice)
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.neighbors.tohero.common.exception.notice;

import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;

public class NoticeException extends RuntimeException {

private final BaseResponseStatus status;
private final String message;

public NoticeException(BaseResponseStatus status, String message) {
super(message);
this.status = status;
this.message = message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public List<Notice> getPagedNotice(Pageable pageable) {
public List<Notice> getTopNotices(int exposeNoticeNumber){
return noticeRepository.getTopNotices(exposeNoticeNumber);
}

public Notice getNotice(long noticeId) {
return noticeRepository.getNoticeById(noticeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
public interface NoticeRepository {
List<Notice> getPagedNotice(Pageable pageable);
List<Notice> getTopNotices(int exposeNoticeNumber);
Notice getNoticeById(long noticeId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.neighbors.tohero.infrastructure.query.impl;

import com.neighbors.tohero.application.baseResponse.BaseResponseMessage;
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
import com.neighbors.tohero.common.exception.notice.NoticeException;
import com.neighbors.tohero.domain.domain.notice.model.Notice;
import com.neighbors.tohero.domain.query.NoticeRepository;
import com.neighbors.tohero.infrastructure.entity.NoticeEntity;
Expand All @@ -10,6 +13,7 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
@RequiredArgsConstructor
Expand All @@ -35,4 +39,15 @@ public List<Notice> getTopNotices(int exposeNoticeNumber) {
.map(noticeMapper::toDomain)
.toList();
}

@Override
public Notice getNoticeById(long noticeId) {
NoticeEntity noticeEntity = noticeEntityRepository.findById(noticeId)
.orElseThrow(() -> new NoticeException(
BaseResponseStatus.NO_RESULT,
BaseResponseMessage.일치하는_공지가_없습니다.getMessage()
));

return noticeMapper.toDomain(noticeEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -24,4 +25,11 @@ public ResponseEntity<BaseResponse> getNotice(@ParameterObject Pageable pageable
return ResponseEntity.ok()
.body(noticeService.getNotice(pageable));
}

@Operation(summary = "공지 API", description = "공지사항 상세보기 API입니다.")
@GetMapping("/notice/detail")
public ResponseEntity<BaseResponse> getNoticeDetail(@RequestParam long noticeId){
return ResponseEntity.ok()
.body(noticeService.getNoticeDetail(noticeId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public DTOFieldExceptionControllerAdvice() {

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<BaseResponse> handle_UserValidationException(MethodArgumentNotValidException e) {
public ResponseEntity<BaseResponse> handle_fieldValidationException(MethodArgumentNotValidException e) {
BaseResponse response = new BaseResponse(
BaseResponseStatus.BAD_REQUEST,
fieldErrorMapper.get(e.getBindingResult().getFieldError().getField()).getMessage()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.neighbors.tohero.presentation.exception_handler;

import com.neighbors.tohero.application.baseResponse.BaseResponse;
import com.neighbors.tohero.application.baseResponse.BaseResponseStatus;
import com.neighbors.tohero.common.exception.notice.NoticeException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class NoticeExceptionControllerAdvice {

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(NoticeException.class)
public ResponseEntity<BaseResponse> handle_NoticeException(NoticeException e) {
BaseResponse response = new BaseResponse(
BaseResponseStatus.NO_RESULT,
e.getMessage()
);

return ResponseEntity.badRequest()
.body(response);
}
}
Loading