Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5기 김남규, 박유진] Spring Boot JPA 게시판 구현 미션 제출합니다. #269

Open
wants to merge 41 commits into
base: eugene_namgyu
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5d1b20c
init commit
eugene225 Nov 20, 2023
e67814f
Chore : 프로젝트 환경설정
eugene225 Nov 20, 2023
71f3790
Feat : entity 생성 - User, Post
eugene225 Nov 20, 2023
3bc557b
Fix : 연관관계 매핑 오류 해결
GiHoo Nov 20, 2023
b0c5ecb
Feat : Post 관련 Dto 구현
GiHoo Nov 21, 2023
426d642
Feat : PostRepository 구현
GiHoo Nov 21, 2023
7fbe52e
Refactor : 사용하지 않는 애노테이션 제거
GiHoo Nov 21, 2023
91b8736
Feat : UserRepository 구현
GiHoo Nov 21, 2023
ec97bec
Feat : UserDto 구현
GiHoo Nov 21, 2023
5f485c8
Feat : PostService 구현
GiHoo Nov 21, 2023
462b862
Feat : PostController 구현
GiHoo Nov 21, 2023
1c49847
Refactor : PostDto에 UserDto 추가
GiHoo Nov 21, 2023
bc065c9
Feat : setUser, update 메서드 추가
GiHoo Nov 21, 2023
f4d7a9b
Feat : Converter 구현
GiHoo Nov 21, 2023
afa8a7d
Refactor : update Api 수정
GiHoo Nov 21, 2023
8bfc7d2
Test : PostService 테스트
GiHoo Nov 21, 2023
ff17326
Feat : ApiReponse 생성 및 postController 적용
eugene225 Nov 22, 2023
95e91f8
Chore : restdocs 플러그인 추가
eugene225 Nov 22, 2023
d15af2a
Test : PostController 테스트 및 문서화 작업
eugene225 Nov 22, 2023
33b67e2
Feat : GlobalExceptionHandler 구현
eugene225 Nov 22, 2023
c008314
Docs : api 문서화
eugene225 Nov 22, 2023
268882d
Feat : postController ApiResponse 적용
eugene225 Nov 22, 2023
cc0e870
Test : findById 실패 테스트 추가
GiHoo Nov 23, 2023
63ed5a5
1차 피드백 수정
GiHoo Dec 3, 2023
35628e6
1차 피드백 수정
GiHoo Dec 3, 2023
b01f6ed
Refactor: HTTP 메서드 변경 (POST -> PUT)
GiHoo Dec 4, 2023
57127d9
Refactor: create를 위한 로직 수정(dto 생성 및 converter 추가)
GiHoo Dec 4, 2023
4cafb55
Refactor: update를 위한 로직 수정(null 체크)
GiHoo Dec 4, 2023
f6a301b
Refactor: update를 위한 로직 수정
GiHoo Dec 4, 2023
0b112f1
Remove: ApiResponse 제거
GiHoo Dec 5, 2023
0f91afa
Refactor : ApiResponse -> ResponseEntity 변경
GiHoo Dec 5, 2023
6599c3c
Refactor : @RequiredArgsConstructor 로 변경
GiHoo Dec 5, 2023
bdda4e9
Test: 변경한 Dto 반영
GiHoo Dec 5, 2023
055fdd0
Test: 변경한 Dto 반영
GiHoo Dec 5, 2023
71d2f67
Docs: Test를 위한 환경 설정 추가
GiHoo Dec 5, 2023
226bcac
Refactor: BaseEntity abstract class 변경
GiHoo Dec 5, 2023
2068b99
Feat: CustomException 생성
eugene225 Dec 6, 2023
100260e
Refactor: CustomException 적용
eugene225 Dec 6, 2023
e4bc9c1
Refactor: CustomException 적용
eugene225 Dec 6, 2023
bd2b1ca
Refactor: update 로직 변경
eugene225 Dec 6, 2023
858c1ac
Comment: 1차 코드리뷰 주석 삭제
eugene225 Dec 7, 2023
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
@@ -1,48 +1,49 @@
package com.prgrms.dev.springbootboardjpa.controller;

import com.prgrms.dev.springbootboardjpa.ApiResponse;
import com.prgrms.dev.springbootboardjpa.dto.PostCreateRequestDto;
import com.prgrms.dev.springbootboardjpa.dto.PostDto;
import com.prgrms.dev.springbootboardjpa.dto.PostUpdateRequestDto;
import com.prgrms.dev.springbootboardjpa.service.PostService;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@AllArgsConstructor // 생성자 lombok ...
@RequestMapping("/api/v1/posts") // 새로운 요구사항 -> native에서는 하위 버전을 고려하기 위해, 에러 발생 시 mapping되는 범위
@RequiredArgsConstructor
@RequestMapping("/api/v1/posts")
public class PostController {

private final PostService postService;

//단건 조회 -> find
@GetMapping("/{id}")
public ApiResponse<PostDto> findById(@PathVariable Long id) {
public ResponseEntity<PostDto> findById(@PathVariable Long id) {
PostDto postDto = postService.findById(id);
return ApiResponse.ok(postDto);
return ResponseEntity.status(HttpStatus.OK).body(postDto);
}

//페이지 조회 -> get
@GetMapping
public ApiResponse<Page<PostDto>> getAll(Pageable pageable) {
public ResponseEntity<Page<PostDto>> getAll(Pageable pageable) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pageable로 받는 부분을 수정해보면 좋을 것 같네요 👍

Page<PostDto> postDto = postService.getAll(pageable);
return ApiResponse.ok(postDto);
return ResponseEntity.status(HttpStatus.OK).body(postDto);
}

//생성
@PostMapping
public ApiResponse<PostDto> create(@RequestBody PostCreateRequestDto postCreateRequestDto) {
public ResponseEntity<PostDto> create(@RequestBody PostCreateRequestDto postCreateRequestDto) {
PostDto postDto = postService.create(postCreateRequestDto);
return ApiResponse.ok(postDto);
return ResponseEntity.status(HttpStatus.OK).body(postDto);
}

//수정
@PutMapping("/{id}")
public ApiResponse<PostDto> update(@RequestBody PostUpdateRequestDto postUpdateRequestDto, @PathVariable Long id) {
@PatchMapping("/{id}")
public ResponseEntity<PostDto> update(@RequestBody PostUpdateRequestDto postUpdateRequestDto, @PathVariable Long id) {
PostDto update = postService.update(postUpdateRequestDto, id);
return ApiResponse.ok(update);
return ResponseEntity.status(HttpStatus.OK).body(update);
}

// 서로 다른 리턴 값을 줄 때 컴파일 시점에서 잡아줄 수 있는 에러 ...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package com.prgrms.dev.springbootboardjpa.exception;

import com.prgrms.dev.springbootboardjpa.ApiResponse;
import com.prgrms.dev.springbootboardjpa.controller.PostController;
import org.springframework.data.crossstore.ChangeSetPersister;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

@RestControllerAdvice
@RestControllerAdvice(basePackageClasses = PostController.class)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

패키지는 공통 exception이지만 포스트 컨트롤러에 대해서만 적용하신 이유가 있나요?

public class GlobalExceptionHandler {

private static final int NOT_FOUND = 404;
private static final int INTERNAL_SERVER_ERROR = 500;

@ExceptionHandler(ChangeSetPersister.NotFoundException.class)
public ApiResponse<String> notFoundHandler(ChangeSetPersister.NotFoundException e) {
return ApiResponse.fail(NOT_FOUND, e.getMessage());
public ResponseEntity<String> notFoundHandler(ChangeSetPersister.NotFoundException e) {
return ResponseEntity.status(NOT_FOUND).body(e.getMessage());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttpStatusCode를 활용하는걸 고려해보세요.

}

@ExceptionHandler(Exception.class)
public ApiResponse<String> internalServerErrorHandler(Exception e) {
return ApiResponse.fail(INTERNAL_SERVER_ERROR, e.getMessage());
} // 다음 타자 .................
public ResponseEntity<String> internalServerErrorHandler(Exception e) {
return ResponseEntity.status(INTERNAL_SERVER_ERROR).body(e.getMessage());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttpStatusCode를 활용하는걸 고려해보세요.

}
}