-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: (#88) 게시글 작성 시, 클라이언트로부터 받는 데이터를 매핑하는 Dto 이름 개선 * refactor: (#88) 컨트롤러 통합 테스트 삭제 * refactor: (#88) 수월한 디버깅을 위해 member toString 추가 * feat: (#88) 조건에 따라 전체 게시글을 정렬해서 조회하는 기능 구현 * feat: (#88) 클라이언트에게 데이터 전달하기 위한 response 생성 * test: (#88) 테스트 없는 메서드 테스트 코드 추가 * refactor: (#88) 서비스 메서드 트랜잭션 어노테이션 붙이기 * refactor: (#88) 이미지 삭제 * refactor: (#88) 이미지 저장 경로 변경 * refactor: (#88) 게시글 작성 시, 필요없는 파라미터 개선 * refactor: (#88) PostOptions 생성하는 코드 개선 * refactor: (#88) dto에 데이터 정제 로직들을 도메인으로 옮김 * refactor: (#88) sql문을 더 보기 쉽게 하기 위해 개행 추가 * refactor: (#88) 원시 타입을 래퍼 클래스 타입으로 변경 * refactor: (#88) 개행 없어야 하는 부분 개행 지우기 * refactor: (#88) 전체 게시글 목록 조회 기능 테스트 메서드 명 더 명확하게 개선 * refactor: (#88) enum 상수들 개행 * refactor: (#88) EqualsAndHashCode의 supercall 속성 삭제 * refactor: (#88) PostOption의 EqualsAndHashCode 삭제 * refactor: (#88) 테스트용 yml 파일 필요없는 설정 삭제 * refactor: (#88) Member 파라미터에 final 붙이기 * refactor: (#88) swagger 관련 어노테이션 중 500 에러 관련 어노테이션 생략 * refactor: (#88) 페이지 넘버 파라미터 타입을 원시 타입으로 변경 * refactor: (#88) response 변수명 더 간결하게 개선 * refactor: (#88) 투표 결과를 볼 수 있는지 판단하는 메서드를 작성자인 경우에도 볼 수 있도록 수정 * refactor: (#88) Repository의 메서드 파라미터에 final 붙이기 * refactor: (#88) isWriter의 테스트 코드 수정 * refactor: (#88) 테스트 코드에서 final 키워드 삭제 * refactor: (#88) 클래스, 필드명을 더 명확하게 개선 * refactor: (#88) Dto클래스의 이름에서 불용어인 Info 삭제 * refactor: (#88) selectedOption 의 역할이 sequence가 아닌 id가 되도록 변경 * refactor: (#88) 파라미터인 Member의 위치를 맨 밑으로 수정 * refactor: (#88) 게시글 조회 반환 값인 response dto의 생성을 정적 팩토리 메서드가 하도록 개선 * refactor: (#88) 래퍼 클래스 타입을 원시 타입으로 변경 * refactor: (#88) 연관관계 편의 메서드에 양방향에 추가하는 로직을 몰아 넣기 * refactor: (#88) 스트림에서 하나만 빼낼 시, findFirst 대신 findAny로 찾는 것으로 변경
- Loading branch information
Showing
27 changed files
with
755 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/com/votogether/domain/post/dto/response/CategoryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.votogether.domain.post.dto.response; | ||
|
||
import com.votogether.domain.category.entity.Category; | ||
|
||
public record CategoryResponse( | ||
long id, | ||
String name | ||
) { | ||
|
||
public static CategoryResponse of(Category category) { | ||
return new CategoryResponse(category.getId(), category.getName()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CategoryResponse{" + | ||
"id=" + id + | ||
", name='" + name + '\'' + | ||
'}'; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
backend/src/main/java/com/votogether/domain/post/dto/response/PostOptionResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.votogether.domain.post.dto.response; | ||
|
||
import com.votogether.domain.post.entity.PostOption; | ||
|
||
public record PostOptionResponse( | ||
long optionId, | ||
String content, | ||
int voteCount, | ||
double votePercent | ||
) { | ||
|
||
public static PostOptionResponse of( | ||
final PostOption postOption, | ||
final boolean isVisibleVoteResult, | ||
final Long totalVoteCount | ||
) { | ||
return new PostOptionResponse( | ||
postOption.getId(), | ||
postOption.getContent(), | ||
postOption.getVoteCount(isVisibleVoteResult), | ||
postOption.getVotePercent(totalVoteCount) | ||
); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "OptionResponse{" + | ||
"optionId=" + optionId + | ||
", content='" + content + '\'' + | ||
", voteCount=" + voteCount + | ||
", votePercent=" + votePercent + | ||
'}'; | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
backend/src/main/java/com/votogether/domain/post/dto/response/PostResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.votogether.domain.post.dto.response; | ||
|
||
import com.votogether.domain.member.entity.Member; | ||
import com.votogether.domain.post.entity.Post; | ||
import com.votogether.domain.post.entity.PostBody; | ||
import com.votogether.domain.post.entity.PostCategory; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public record PostResponse( | ||
Long postId, | ||
WriterResponse writer, | ||
String title, | ||
String content, | ||
List<CategoryResponse> categories, | ||
LocalDateTime createdAt, | ||
LocalDateTime deadline, | ||
VoteResponse voteInfo | ||
) { | ||
|
||
public static PostResponse of(final Post post, final Member loginMember) { | ||
final Member writer = post.getWriter(); | ||
final PostBody postBody = post.getPostBody(); | ||
|
||
return new PostResponse( | ||
post.getId(), | ||
WriterResponse.of(writer.getId(), writer.getNickname().getValue()), | ||
postBody.getTitle(), | ||
postBody.getContent(), | ||
getCategories(post), | ||
post.getCreatedAt(), | ||
post.getDeadline(), | ||
VoteResponse.of( | ||
post.getPostOptions().getSelectedOptionId(loginMember), | ||
post.getFinalTotalVoteCount(loginMember), | ||
getOptions(post, loginMember) | ||
) | ||
); | ||
} | ||
|
||
private static List<CategoryResponse> getCategories(final Post post) { | ||
return post.getPostCategories().getPostCategories().stream() | ||
.map(PostCategory::getCategory) | ||
.map(CategoryResponse::of) | ||
.toList(); | ||
} | ||
|
||
private static List<PostOptionResponse> getOptions( | ||
final Post post, | ||
final Member loginMember | ||
) { | ||
return post.getPostOptions().getPostOptions().stream() | ||
.map(postOption -> | ||
PostOptionResponse.of( | ||
postOption, | ||
post.isVisibleVoteResult(loginMember), | ||
post.getFinalTotalVoteCount(loginMember) | ||
) | ||
) | ||
.toList(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PostResponse{" + | ||
"postId=" + postId + | ||
", writer=" + writer + | ||
", title='" + title + '\'' + | ||
", content='" + content + '\'' + | ||
", categories=" + categories + | ||
", createdAt=" + createdAt + | ||
", deadline=" + deadline + | ||
", voteInfo=" + voteInfo + | ||
'}' + "\n\n"; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/com/votogether/domain/post/dto/response/VoteResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.votogether.domain.post.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record VoteResponse( | ||
long selectedOptionId, | ||
long totalVoteCount, | ||
List<PostOptionResponse> options | ||
) { | ||
|
||
public static VoteResponse of( | ||
final long selectedOptionId, | ||
final long finalTotalVoteCount, | ||
final List<PostOptionResponse> options | ||
) { | ||
return new VoteResponse(selectedOptionId, finalTotalVoteCount, options); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "VoteInfoResponse{" + | ||
"selectedOptionId=" + selectedOptionId + | ||
", totalVoteCount=" + totalVoteCount + | ||
", options=" + options + | ||
'}'; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/com/votogether/domain/post/dto/response/WriterResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.votogether.domain.post.dto.response; | ||
|
||
public record WriterResponse( | ||
Long id, | ||
String nickname | ||
) { | ||
|
||
public static WriterResponse of(final Long id, final String nickname) { | ||
return new WriterResponse(id, nickname); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "WriterResponse{" + | ||
"id=" + id + | ||
", nickname='" + nickname + '\'' + | ||
'}'; | ||
} | ||
|
||
} |
Oops, something went wrong.