-
Notifications
You must be signed in to change notification settings - Fork 0
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
feature : vote, room 의존성 분리 및 vote repository 추가 #85
Conversation
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.
고생했어요 달리!
저는 EventListner를 지금처럼 두는 것이 맞다고 생각해요. 다만, 달리가 물어본 것이 애그리거트 패키지 내의 위치에 대해서 여쭤보신거라면, application내에 listener 패키지를 두어서 조금 보기 명확하게 하면 더 좋을 것 같다는 생각이 있습니다. application 하위에 있는 것은 맞는 것 같다고 생각이 들어요.
@@ -22,6 +22,9 @@ repositories { | |||
} | |||
|
|||
dependencies { | |||
implementation 'org.springframework.boot:spring-boot-starter-data-redis' | |||
testImplementation 'org.testcontainers:testcontainers' |
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.
TestContainer.. 이제 내 컴퓨터에서 테스트를 돌릴 때 마다 1분씩 걸리겠군요 ㅠ
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.
testcontainers는 springboot 자체에서 기본적으로 h2는 지원하는데 redis는 없어서 redis로 테스트 돌리기위해서 필요한건가?
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.
예스 Redis를 돌리기위해 testContainers로 Redis 도커 띄워서 사용하고 있음
@EventListener | ||
public void listenAllVotedEvent(final AllVotedEvent allVotedEvent){ | ||
// todo : 이후 status 변경 이벤트 발행 | ||
} |
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.
의존성 끊어내기 너어무우~ 좋아요
// public void clearVote() { | ||
// this.voteLegacy.clear(); | ||
// } |
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.
지금?? 일단 패키지 의존성 분리하고 생각하자는거 아니었슴까?
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.
흑흑..
if (maxCount == voteCount.getValue()) { | ||
count++; | ||
} | ||
if (maxCount < voteCount.getValue()) { | ||
maxCount = voteCount.getValue(); | ||
count = 1; | ||
maxVotedPlayer = voteCount.getKey(); | ||
} |
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.
depth 2는 나는 못참아!
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.
메서드로 빼도 괜찮을 것 같고, 두 번 나눠서 처리하는 것이 더 가독성이 좋을 것 같기도하고...
근데, 솔직히 지금도 괜찮기도 하고.. ㅋㅋㅋㅋ
count>1은 동점표 잖아요. 이런 것도 메서드로 분리할 수 있으면 좋을 것 같은데 이거는 일단, 임시로 해놓으신거죠?!
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.
이렇게 하는게 최고 좋은 것 같은데, 의미만 명확히 하면 좋을 것 같아요.
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.
나도 이부분 메서드로 분리하면 보기편할거같음 🧐
RedisTemplate<String, Vote> template = new RedisTemplate<>(); | ||
template.setConnectionFactory(redisConnectionFactory); | ||
|
||
// Use String serializer for keys | ||
template.setKeySerializer(new StringRedisSerializer()); | ||
template.setHashKeySerializer(new StringRedisSerializer()); | ||
|
||
// Use JSON serializer for values | ||
template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); | ||
template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); | ||
|
||
template.setEnableDefaultSerializer(true); | ||
template.setDefaultSerializer(new GenericJackson2JsonRedisSerializer()); |
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.
달리의 고민의 흔적들이 보이는 설정들이네요 ㅋㅋㅋ
int maxCount = 0; | ||
int count = 0; | ||
Player maxVotedPlayer = Player.NONE; | ||
for (Entry<Player, Integer> voteCount : voteCounts.entrySet()) { | ||
if (voteCount.getKey() == Player.NONE) { | ||
continue; | ||
} | ||
if (maxCount == voteCount.getValue()) { | ||
count++; | ||
} | ||
if (maxCount < voteCount.getValue()) { | ||
maxCount = voteCount.getValue(); | ||
count = 1; | ||
maxVotedPlayer = voteCount.getKey(); | ||
} | ||
} | ||
if (count > 1) { | ||
return Player.NONE; | ||
} | ||
return maxVotedPlayer; | ||
} |
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.
고생했어
private Status status; | ||
private final RoomInfo roomInfo; | ||
private final Chat chat; | ||
private final JobTarget jobTarget; | ||
private Player master; | ||
|
||
public static Room create(final String code, final RoomInfo roomInfo, final Long now) { |
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.
아 이거 room Repository 생성할려고 적어둔거긴 한데 아직 Room 작업을 안해서 사용이 안됬네 나중에 RoomRepository 생성하면서 사용될듯
if (maxCount == voteCount.getValue()) { | ||
count++; | ||
} | ||
if (maxCount < voteCount.getValue()) { | ||
maxCount = voteCount.getValue(); | ||
count = 1; | ||
maxVotedPlayer = voteCount.getKey(); | ||
} |
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.
나도 이부분 메서드로 분리하면 보기편할거같음 🧐
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class VoteRepositoryImpl implements VoteRepository { |
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.
ㄴㄴ CrudRepository 사용하면 할수 있긴한데 그럴 경우
조회의 경우 findByID, findAll 밖에 안되고 조건 조회 같은게 불가능함
그래서 RedisTemplate으로 Secondary index 조회를 위해서 직접 구현해줘야함
@@ -0,0 +1,22 @@ | |||
package mafia.mafiatogether.redis; |
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.
따로 패키지 분리안하고 코드단처럼 global에 있으면 보기편할거같아
@@ -22,6 +22,9 @@ repositories { | |||
} | |||
|
|||
dependencies { | |||
implementation 'org.springframework.boot:spring-boot-starter-data-redis' | |||
testImplementation 'org.testcontainers:testcontainers' |
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.
testcontainers는 springboot 자체에서 기본적으로 h2는 지원하는데 redis는 없어서 redis로 테스트 돌리기위해서 필요한건가?
c2af594
to
01c5e91
Compare
충돌 폼 미쳐따이;; |
f2bb243
to
aa66178
Compare
기존 vote의 구조를 말씀드렸던 것처럼 각각이 code, player, target을 가지고 있게 바꿨습니다.
이 후 Redis에 저장을 하도록하였습니다.
redis key의 경우는 redis의 다중키를 이용하여 vote:code:name 형식으로 저장하였습니다.
이는 Redis의 경우 쿼리처럼 value로 필터링하는 방법이 없어 키를 복합적으로 구현하고 search할때 "vote:code:*"이런식으로 검색해야한다고 하네요. 그래서 저렇게 구현하였습니다.
아직 Game 패키지를 구현하지 않았기 때문에 전원 투표시 status가 넘어가는 event는 구현하지 않았습니다.
이보다 더 진행하면 뭔가 복잡해질것 같아서 일단 여기까지 구현하고 pr 올려봅니다.
before : 대각선을 기준으로 vote와 room 사이 양방향 의존성 존재
after: room과 vote는 의존성이 끊김
ps. EventListener는 어디서 관리하면 좋을지 궁금합니다 .아이디어 부탁