-
Notifications
You must be signed in to change notification settings - Fork 2
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
Featur/ISM-92 #5
base: develop
Are you sure you want to change the base?
Conversation
private final PostService postService; | ||
|
||
// 게시글 생성 | ||
@PostMapping("/post") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
restapi 방식으로 하기때문에 http요청 또는 응답을 하기위해서는 ResponseEntity를 사용하는게 나을것 같습니다.
관련글 드릴께요
ResponseEntity
private String title; // 제목 | ||
private String description; // 내용 | ||
private User user; // 사용자 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
게시글 작성에는 제목 내용만 필요할 것 같습니다. 본인이 작성했기 때문에 굳이 사용자를 받지 않아도 될 것 같습니다. (클래스중에 Tokenmanager라고 제가 만들어 놓은걸로 현재 요청보내는 사용자가 누군지 판별할 수 있습니다.) 그리고 내용에는 사진도 여러장 들어갈 수 있습니다
} | ||
|
||
// 게시글 조회 | ||
@GetMapping("/post") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵!!
//게시글 수정 | ||
@Transactional | ||
public Long update(final Long id, final PostRequestDTO params){ | ||
Post entity = postRepository.findById(id).orElseThrow(() -> new CustomException("게시글 수정 완료")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orElseThrow를 사용했을시 예외가 터지면 exception이 나오는데 예외가 터졌을대 "게시글 수정 완료"는 적절하지 않는 것 같습니다. 예외 만들어 놓은 것중에 GLOBALEXCEPTION.NOT_FOUND가 있는데 이거 사용하시면 될 것 같습니다.
// 게시글 조회 | ||
public List<PostResponseDTO> findAll(){ | ||
Sort sort = Sort.by(Sort.Direction.DESC, "id", "createDate"); | ||
List<Post> list = postRepository.findAll(sort); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findAll을 사용하는건 적합하지 않다고 생각합니다.
@@ -12,13 +12,11 @@ public class PostRequestDto { | |||
|
|||
private String title; // 제목 | |||
private String description; // 내용 | |||
private User user; // 사용자 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
======= | ||
Post entity = postRepository.findById(id).orElseThrow(() -> new CustomException(ErrorCodes.POST_NOT_FOUND)); | ||
>>>>>>> 62b7de874240edd7fd34ebafca564f8c8783618f | ||
Post entity = postRepository.findById(id).orElseThrow(() -> new CustomException(GlobalException.NOT_FOUND)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Post entity = postRepository.findById(id).orElseThrow(() -> new CustomException(ErrorCodes.POST_NOT_FOUND)); | ||
>>>>>>> 62b7de874240edd7fd34ebafca564f8c8783618f | ||
Post entity = postRepository.findById(id).orElseThrow(() -> new CustomException(GlobalException.NOT_FOUND)); | ||
//Post entity = postRepository.findById(id).orElseThrow(() -> new CustomException(ErrorCodes.POST_NOT_FOUND)3); | ||
entity.update(params.getTitle(), params.getDescription(), params.getUser(), params.getUser().getCreateAt()); | ||
return id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PostRequestDto params
에서 params에 필드값이 2개여서
entity.update(params.getTitle(), params.getDescription(), params.getUser(), params.getUser().getCreateAt());이 부분 오류 발생합니다.
Type
Implements issue ISM-0
What & Why
게시판 등록, 수정, 조회, 삭제 api
Checklist