[3주차] 남유정/[feat] 게시글 도메인 API 구현#100
Hidden character warning
[3주차] 남유정/[feat] 게시글 도메인 API 구현#100N-yujeong wants to merge 3 commits intoLeets-Official:남유정/mainfrom
Conversation
gusanans218
left a comment
There was a problem hiding this comment.
전체적으로 구조가 잘 잡혀 있고 DTO 분리와 예외 처리, Swagger 적용까지 깔끔하게 구현되어 있어서 보기 좋았습니다!!
코드 가독성과 완성도 모두 좋은 것 같습니다 👍
Hanharam
left a comment
There was a problem hiding this comment.
👍 DTO 중첩으로 사용하신 점과 전체적인 흐름이 좋았습니다! 최상위 커스텀 예외를 하나 만들고 다른 예외들은 상속받으면서 핸들러에는 부모 예외 하나만 두는 것도 좋을 것 같습니다!
jihoonkim501
left a comment
There was a problem hiding this comment.
유정님 고생많으셨습니다~! 제 리뷰 한번 확인 부탁드려요~~!
| @RequestMapping("/api/posts") | ||
| @RequiredArgsConstructor | ||
| @Validated | ||
| public class PostController { |
There was a problem hiding this comment.
Swagger 문서관리해주셨네요~! 지금도 충분히 세세하게 잘 작성해주셨는데 Docs 파일로 따로 관리해서 ( PostControllerDocs, PostController )
controller 코드는 설명을 제외하고 기능적인 코드만 남겨서 가독성을 높일 수 있는 방법도 있습니다. 수정은 아니고 참고만 해주시면 감사하겠습니다~!
| public PostDetailResponse getPost(Long postId) { | ||
| Post post = postRepository.findById(postId) | ||
| .orElseThrow(() -> new PostNotFoundException(postId)); | ||
| return PostDetailResponse.from(post); | ||
| } | ||
|
|
||
| @Transactional | ||
| public Long createPost(PostCreateRequest request, Long userId) { | ||
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> new IllegalArgumentException("사용자를 찾을 수 없습니다.")); |
There was a problem hiding this comment.
커스텀 예외처리와 표준(내장) 런타임 예외가 공존합니다! 커스텀 예외처리로 통일하는것을 추천드립니다! 추후 API 연동시에 프론트분들이 (아시겠지만) 어려워할수 있습니다..!
|
|
||
| @Transactional | ||
| public void deletePost(Long postId, Long userId) { | ||
| Post post = postRepository.findById(postId) |
There was a problem hiding this comment.
검증하는 부분이 반복되어서 따로 함수를 빼서 이용하면 SRP을 지키며 코드 가독성도 좋아진답니다!
| @Bean | ||
| public OpenAPI openAPI() { | ||
| return new OpenAPI() | ||
| .info(new Info() | ||
| .title("Leets-7th BE Blog API") | ||
| .description("[남유정] 미션 API 명세서") | ||
| .version("3주차")); | ||
| } | ||
| } |
1. 과제 요구사항 중 구현한 내용
GET /api/posts)GET /api/posts/{postId})POST /api/posts)PATCH /api/posts/{postId})DELETE /api/posts/{postId})GET /health)POST /string/repeat)2. 핵심 변경 사항
PostControllerPostServicePostcategory,thumbnailImageUrl필드 추가,create()/update()팩토리·수정 메서드 추가CategoryCategoryRepository신규 추가ApiResponsesuccess,error,errors포함)GlobalExceptionHandlerPostNotFoundException,ForbiddenException,@Valid검증 오류, 타입 불일치 등 전역 처리SwaggerConfigDataInitializerdomain/string패키지 이동domain/string으로 이동 (도메인 패키지 구조 정리)3. 실행 및 검증 결과
4. 완료 사항
ApiResponse) 및 전역 예외 처리(GlobalExceptionHandler) 추가domain/string으로 이동)5. 추가 사항
제출 체크리스트
{이름}/main브랜치다{이름}/{숫자}주차브랜치다Reviewer 참고