-
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
[FEAT] 타임라인 선수 교체 정보 관련 기능 추가 #116
Merged
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ca586fb
[FEAT] api 응답에 따라 dto 구현 #107
ldk980130 23435e7
[FEAT] n + 1을 방지하고자 페치 조인 쿼리 작성 #107
ldk980130 f86bf9d
[FEAT] 교체 타임라인 dto 매핑 코드 구현 #107
ldk980130 e5cb1e1
[FEAT] 타임라인 조회 기능 구현 #107
ldk980130 6a58db9
[TEST] 타임라인 조회 인수 테스트 작성 #107
ldk980130 300c44b
[DOCS] 타임라인 api 문서화 #107
ldk980130 dd9e9ca
[REFACTOR] 필요 없는 조인 제거 #107
ldk980130 c8e955e
[REFACTOR] RecordQueryService 인터페이스로 구체 타입 추상화 #107
ldk980130 ff3711b
[REFACTOR] ScoreRecordQueryService 메서드 분리 #107
ldk980130 ec41328
[REFACTOR] ReplacementRecord -> RecordResponse 매핑 로직 분리 메서드 분리 #107
ldk980130 2c50dd0
[REFACTOR] ScoreHistory와 ScoreSnapshot으로 리팩터링 #107
ldk980130 f062d34
[DOCS] 수정된 사항 api 문서에 반영 #107
ldk980130 f34bae3
[REFACTOR] application.timeline 패키지에 타임라인 조회 기능 이동 #107
ldk980130 385eb79
[REFACTOR] for 문 foreach로 변경 #107
ldk980130 61f28db
Merge branch 'main' into feat/#107-timeline
ldk980130 7a53daf
[DCOS] 충돌 해결 후 api 문서 업데이트 #107
ldk980130 d849c15
[FIX] 응답 본문 필드 네이밍 수정 #107
ldk980130 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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/sports/server/query/application/ScoreHistory.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,57 @@ | ||
package com.sports.server.query.application; | ||
|
||
import com.sports.server.command.game.domain.GameTeam; | ||
import com.sports.server.command.record.domain.ScoreRecord; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static java.util.stream.Collectors.toMap; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class ScoreHistory { | ||
|
||
private final Map<ScoreRecord, ScoreSnapshot> snapshots; | ||
|
||
public static ScoreHistory of(List<ScoreRecord> scoreRecords, List<GameTeam> gameTeams) { | ||
Map<ScoreRecord, ScoreSnapshot> values = new HashMap<>(); | ||
Map<GameTeam, Integer> scores = initializeScores(gameTeams); | ||
for (ScoreRecord record : scoreRecords) { | ||
applyScore(scores, record); | ||
ScoreSnapshot snapshot = generateSnapshot(scores, gameTeams); | ||
values.put(record, snapshot); | ||
} | ||
return new ScoreHistory(values); | ||
} | ||
|
||
private static Map<GameTeam, Integer> initializeScores(List<GameTeam> gameTeams) { | ||
return gameTeams.stream() | ||
.collect(toMap(gameTeam -> gameTeam, gameTeam -> 0)); | ||
} | ||
|
||
private static void applyScore(Map<GameTeam, Integer> scores, ScoreRecord record) { | ||
GameTeam gameTeam = record.getRecord().getGameTeam(); | ||
int score = record.getScore(); | ||
scores.put(gameTeam, scores.get(gameTeam) + score); | ||
} | ||
|
||
private static ScoreSnapshot generateSnapshot(Map<GameTeam, Integer> scores, | ||
List<GameTeam> gameTeams) { | ||
Map<GameTeam, Integer> snapshot = new HashMap<>(); | ||
gameTeams.forEach(team -> snapshot.put(team, scores.get(team))); | ||
return new ScoreSnapshot(snapshot); | ||
} | ||
|
||
public List<ScoreRecord> getScoreRecordsOrderByTimeDesc() { | ||
return snapshots.keySet().stream() | ||
.sorted((r1, r2) -> Integer.compare(r2.getRecord().getRecordedAt(), r1.getRecord().getRecordedAt())) | ||
.toList(); | ||
} | ||
|
||
public ScoreSnapshot getSnapshot(ScoreRecord scoreRecord) { | ||
return snapshots.get(scoreRecord); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/sports/server/query/application/ScoreSnapshot.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.sports.server.query.application; | ||
|
||
import com.sports.server.command.game.domain.GameTeam; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
|
||
public class ScoreSnapshot { | ||
|
||
private final Map<GameTeam, Integer> values; | ||
|
||
public ScoreSnapshot(Map<GameTeam, Integer> values) { | ||
this.values = values; | ||
} | ||
|
||
public Integer getScore(GameTeam team) { | ||
return values.get(team); | ||
} | ||
|
||
public List<GameTeam> getTeamsOrderById() { | ||
return values.keySet() | ||
.stream() | ||
.sorted(Comparator.comparingLong(GameTeam::getId)) | ||
.toList(); | ||
} | ||
} |
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
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.
저는 개인적으로 point 가 조금 어색하다고 느껴지는 것 같아요. 왜냐하면 이전까지 이러한 득점의 경우 score 를 썼었고 현재 score_records 테이블에서도 득점 정보에 관해서 score 라는 컬럼을 쓰고 있어서인 것 같아요!
작성해주신 코드에서의 score 의 역할은 Snapshot 에 종속돼서 과거의 점수를 서술하는 용어라면, 테이블에서의 score 은 득점하는 점수 자체를 서술하는 용어라고 다가와요. 이에 대해서 어떻게 생각하시는지 궁금해요! 👀
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.
위 스펙에서 각 타입에 따라
null
인 객체를 하나로 묶기 위해score
와replacement
라는 이름으로 각 타입에 맞는 특수한 값들을 묶어줬어요. 이 구조에서 득점을score
라고 하자니records.score.score
가 되기에 어색하다고 느껴졌어요.score
하위의 몇점을 득점했는지에 의미를 담아point
라고 이름을 명명했는데 더 나은 네이밍이 있을까요? 아니면 최상위 객체의 이름 (score
,replacment
)를 다르게 표기해야 할까요?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.
현재 테이블명을 따라서 scoreRecords, ReplacementRecord 로 하는건 어떨까요?
사실상 타입이 score 이고 replacement 인거고, 그 각자는 각각 scoreRecord, replacementRecord 이기는 하니까요!
point 는 snapshot 내부에서는 같은 맥락임에도 score 로 표기되고 있기도 하고, 저희가 사전에 정의되었거나 논의된 용어가 아니라서 나중에도, api 스펙 상에서도 혼돈을 줄 것 같다는 생각이 들어요!
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.
@Jin409
리뷰 반영햇습니다~
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.
수고하셨습니당~ 머지해도 좋을 것 같아요!