Skip to content
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,6 +1,7 @@
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.PostRequestDto;
import com.prgrms.dev.springbootboardjpa.service.PostService;
Expand Down Expand Up @@ -32,8 +33,8 @@ public ApiResponse<Page<PostDto>> getAll(Pageable pageable) {

//생성
@PostMapping
public ApiResponse<PostDto> create(@RequestBody PostRequestDto postRequestDto, @RequestParam Long userId) {
PostDto postDto = postService.create(postRequestDto, userId);
public ApiResponse<PostDto> create(@RequestBody PostCreateRequestDto postCreateRequestDto) {
PostDto postDto = postService.create(postCreateRequestDto);
return ApiResponse.ok(postDto);
} // body에서 전부 받는 방식으로

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.prgrms.dev.springbootboardjpa.domain.post.Post;
import com.prgrms.dev.springbootboardjpa.domain.user.User;
import com.prgrms.dev.springbootboardjpa.dto.PostCreateRequestDto;
import com.prgrms.dev.springbootboardjpa.dto.PostDto;
import com.prgrms.dev.springbootboardjpa.dto.PostRequestDto;
import com.prgrms.dev.springbootboardjpa.dto.UserDto;
Expand All @@ -28,6 +29,14 @@ public Post convertPost(PostRequestDto postDto) {
.build();
}

// dto -> entity
public Post convertPost(PostCreateRequestDto postCreateRequestDto) {
return Post.builder()
.title(postCreateRequestDto.title())
.content(postCreateRequestDto.content())
.build();
}

// entity -> dto
public UserDto convertUserDto(User user) {
return UserDto.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.prgrms.dev.springbootboardjpa.dto;

import lombok.Builder;

@Builder
public record PostCreateRequestDto(Long userId, String title, String content) {

public PostCreateRequestDto {
validateNull(title);
validateNull(content);
}

private void validateNull(String input) {
if(input.isEmpty() || input.isBlank()) throw new NullPointerException("NPE");

Choose a reason for hiding this comment

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

검증좋네요 👍
나중에 title / content에서 길이와 같은 개별 검증이 들어갈 수 있을 것 같기도 해서 각각 분리해보는걸 고려해봐도 좋을 것 같아요 👍

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

@Builder
public record PostRequestDto(String title, String content) {
// 검증
// 생성, 업데이트 를 분리?
// 요구사항이 늘었을 때를 생각해보자
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.prgrms.dev.springbootboardjpa.domain.post.PostRepository;
import com.prgrms.dev.springbootboardjpa.domain.user.User;
import com.prgrms.dev.springbootboardjpa.domain.user.UserRepository;
import com.prgrms.dev.springbootboardjpa.dto.PostCreateRequestDto;
import com.prgrms.dev.springbootboardjpa.dto.PostDto;
import com.prgrms.dev.springbootboardjpa.dto.PostRequestDto;
import jakarta.persistence.EntityNotFoundException;
Expand Down Expand Up @@ -37,9 +38,9 @@ public Page<PostDto> getAll(Pageable pageable) {
}

@Transactional
public PostDto create(PostRequestDto requestDto, Long userId) {
Post post = converter.convertPost(requestDto);
User user = userRepository.findById(userId)
public PostDto create(PostCreateRequestDto postCreateRequestDto) {
Post post = converter.convertPost(postCreateRequestDto);
User user = userRepository.findById(postCreateRequestDto.userId())
.orElseThrow(() -> new EntityNotFoundException("회원을 찾을 수 없습니다"));
post.setUser(user);
return converter.convertPostDto(postRepository.save(post));
Expand Down