4 Backend chanul#25
Conversation
| import java.util.List; | ||
|
|
||
| @Service | ||
| @AllArgsConstructor |
There was a problem hiding this comment.
@AllArgsConstructor는 모든 필드 값을 파라미터로 받는 생성자를 생성 어노테이션이라 서비스 로직에서 사용하기에 적합하지 않아보여요
| } | ||
|
|
||
| @PutMapping("/{id}") | ||
| public Long updateBoard(@PathVariable Long id, @RequestBody BoardRequestDto requestDto) { |
There was a problem hiding this comment.
board를 수정하는 메서드 인데 반환하는 값이 Long인 이유가 있나요?
| public class BoardController { | ||
| private final BoardService boardService; | ||
|
|
||
| public BoardController(BoardService boardService) { |
There was a problem hiding this comment.
생성자를 만들어서 BoardService를 사용하는 것이 아닌 @RequiredArgsConstructor를 통한 의존성 주입을 통해 boardService를 사용하는게 더 좋을거 같아요
| @Entity(name = "boards") // DB 테이블 이름을 "boards"로 설정 | ||
| public class Board { | ||
| // 글 고유 아이디 | ||
| @GeneratedValue(strategy = GenerationType.AUTO) |
There was a problem hiding this comment.
현재 기본키 생성 전략을 GenerationType.AUTO로 해두어 하이버네이트가 자동으로 전략을 선택하게끔 됬는데 DB 버전에 따라 선택되는 전략이 달라질 수 있으므로 사용하는 DBMS에 맞는 전략을 사용하시면 좋을거 같아요
| @Transactional | ||
| public Long deleteBoard(Long id) { | ||
| boardRepository.deleteById(id); | ||
| return id; |
There was a problem hiding this comment.
삭제하는 메서드에서 삭제한 board의 id를 다시 반환하는 이유가 있나요?
|
|
||
| @Transactional | ||
| public Long deleteBoard(Long id) { | ||
| boardRepository.deleteById(id); |
There was a problem hiding this comment.
받아온 id를 바로 삭제하는게 아니라 이 board의 id가 있는지 확인하는 로직이 있으면 좋을 것 같아요
| @@ -0,0 +1,5 @@ | |||
| spring.datasource.url=jdbc:mysql://localhost:3306/boardmysql?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true | |||
There was a problem hiding this comment.
많은 프로젝트에서 application.properties 파일보다 application.yml파일을 더 많이 사용해요
그래서 yml 파일 사용해보는것도 좋을거 같아요
| @@ -0,0 +1,5 @@ | |||
| spring.datasource.url=jdbc:mysql://localhost:3306/boardmysql?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true | |||
| spring.datasource.username=root | |||
There was a problem hiding this comment.
username이나 password 같은 민감한 정보는 외부에 노출되면 안되기 때문에 커밋을 할때 환경변수 처리해서 올려주세요
| } | ||
|
|
||
| @PostMapping("/") | ||
| public BoardResponseDto createBoard(@RequestBody BoardRequestDto requestDto) { |
There was a problem hiding this comment.
컨트롤러에서 반환할때 ResponseEntity 사용해서 반환값과 상태 코드를 함께 반환하면 좋을거 같아요
ResponseEntity는 적절한 상태 코드와 응답 헤더 및 응답 본문을 생성하여 클라이언트에 전달하기 위해 사용합니다
| return boardService.findOneBoard(id); | ||
| } | ||
|
|
||
| @PutMapping("/{id}") |
There was a problem hiding this comment.
@PutMapping보다 @PatchMapping이 나아보입니다.
기본적인 http 메서드에 대해 알아보시는걸 추천드려요
|
|
||
| @Repository | ||
| public interface BoardRepository extends JpaRepository<Board, Long> { | ||
| List<BoardListResponseDto> findAllByOrderByModifiedAtDesc(); |
There was a problem hiding this comment.
이 메서드 사용하지 않고 있는데 넣으신 이유가 있나요?
There was a problem hiding this comment.
로컬에서 실행했을 때 ModifiedAt이라는 필드가 없지만 여기서 ModifiedAt이라는 필드를 기준으로 정렬하려해서 오류가 터져 실행이 되지 않습니다
💡 개요
📃 작업내용
🔀 변경사항
🙋♂️ 질문사항
💀 어려웠던 점