-
Notifications
You must be signed in to change notification settings - Fork 1
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
YEL-193 [feat] 친구 쪽지 전체 조회하기 #421
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3ab68da
YEL-193 [feat] 친구 투표 전체, 내가 보낸 쪽지 조회
hyeonjeongs 78f3e8d
YEL-193 [feat] adoc 수정
hyeonjeongs 717b91c
YEL-193 [feat] type 유형 수정
hyeonjeongs 1985350
YEL-193 [feat] 코드리뷰 반영
hyeonjeongs ee78833
YEL-193 [feat] 명세서 반영
hyeonjeongs 829b4f7
YEL-193 [feat] notice 날짜 변경되는거 수정
hyeonjeongs ce06a65
YEL-193 [feat] 명세서 수정
hyeonjeongs 5503e57
Merge branch 'develop' into feat/YEL-193
hyeonjeongs 3217c6c
YEL-193 [feat] notice testcode
hyeonjeongs c592b43
YEL-193 [feat] merge
hyeonjeongs bc6b303
YEL-193 [feat] vote type fix
hyeonjeongs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/yello/server/domain/vote/entity/VoteType.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,27 @@ | ||
package com.yello.server.domain.vote.entity; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Arrays; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum VoteType { | ||
send("send"); | ||
|
||
private final String intial; | ||
|
||
public static VoteType fromCode(String dbData) { | ||
return Arrays.stream(VoteType.values()) | ||
.filter(v -> v.getIntial().equals(dbData)) | ||
.findAny() | ||
.orElseThrow(() -> new IllegalArgumentException( | ||
MessageFormat.format("존재하지 않는 투표 타입입니다. {0}", dbData))); | ||
} | ||
|
||
public String intial() { | ||
return intial; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/yello/server/domain/vote/entity/VoteTypeConverter.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,32 @@ | ||
package com.yello.server.domain.vote.entity; | ||
|
||
import com.yello.server.domain.user.entity.Social; | ||
import javax.persistence.AttributeConverter; | ||
import javax.persistence.Converter; | ||
import lombok.extern.log4j.Log4j2; | ||
|
||
@Converter | ||
@Log4j2 | ||
public class VoteTypeConverter implements AttributeConverter<VoteType, String> { | ||
|
||
@Override | ||
public String convertToDatabaseColumn(VoteType voteType) { | ||
if (voteType == null) { | ||
return null; | ||
} | ||
return voteType.getIntial(); | ||
} | ||
|
||
@Override | ||
public VoteType convertToEntityAttribute(String dbData) { | ||
if (dbData == null) { | ||
return null; | ||
} | ||
try { | ||
return VoteType.fromCode(dbData); | ||
} catch (IllegalArgumentException exception) { | ||
log.error("failure to convert cause unexpected code" + dbData + exception); | ||
throw exception; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
import com.yello.server.domain.vote.dto.response.VoteResponse; | ||
import com.yello.server.domain.vote.dto.response.VoteUnreadCountResponse; | ||
import com.yello.server.domain.vote.entity.Vote; | ||
import com.yello.server.domain.vote.entity.VoteType; | ||
import com.yello.server.domain.vote.exception.VoteForbiddenException; | ||
import com.yello.server.domain.vote.exception.VoteNotFoundException; | ||
import com.yello.server.domain.vote.repository.VoteRepository; | ||
|
@@ -57,6 +58,7 @@ | |
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.util.StringUtils; | ||
|
||
@Service | ||
@Builder | ||
|
@@ -121,18 +123,7 @@ public VoteFriendResponse findAllFriendVotes(Long userId, Pageable pageable) { | |
|
||
public VoteFriendAndUserResponse findAllFriendVotesWithType(Long userId, Pageable pageable, String type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ENUM을 통해 type을 narrowing해주고, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
if(type.equals(USER_VOTE_TYPE)) { | ||
final Long totalCount = voteRepository.countUserSendReceivedByFriends(userId); | ||
|
||
List<VoteFriendAndUserVO> list = | ||
voteRepository.findUserSendReceivedByFriends(userId, pageable) | ||
.stream() | ||
.filter(vote -> vote.getNameHint()!=-3) | ||
.map(vote -> VoteFriendAndUserVO.of(vote, vote.getSender().getId().equals(userId))) | ||
.toList(); | ||
return VoteFriendAndUserResponse.of(totalCount,list); | ||
} | ||
if(type.equals(ALL_VOTE_TYPE)) { | ||
if(!StringUtils.hasText(type)) { | ||
final Long totalCount = Long.valueOf(voteRepository.countAllReceivedByFriends(userId)); | ||
final List<VoteFriendAndUserVO> list = voteRepository.findAllReceivedByFriends(userId, pageable) | ||
.stream() | ||
|
@@ -142,6 +133,19 @@ public VoteFriendAndUserResponse findAllFriendVotesWithType(Long userId, Pageabl | |
return VoteFriendAndUserResponse.of(totalCount, list); | ||
} | ||
|
||
switch(VoteType.valueOf(type)) { | ||
case send -> { | ||
final Long totalCount = voteRepository.countUserSendReceivedByFriends(userId); | ||
List<VoteFriendAndUserVO> list = | ||
voteRepository.findUserSendReceivedByFriends(userId, pageable) | ||
.stream() | ||
.filter(vote -> vote.getNameHint()!=-3) | ||
.map(vote -> VoteFriendAndUserVO.of(vote, vote.getSender().getId().equals(userId))) | ||
.toList(); | ||
return VoteFriendAndUserResponse.of(totalCount,list); | ||
} | ||
} | ||
|
||
throw new VoteForbiddenException(WRONG_VOTE_TYPE_FORBIDDEN); | ||
} | ||
|
||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
enum 이름은 대문자 SEND로 바꿔주세요