Skip to content
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

#44 [feat] 홈 response에 디데이 필드 추가 #45

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -6,14 +6,15 @@

import lombok.Builder;

@JsonPropertyOrder({"userId", "roundGameId", "myScore", "partnerScore", "drawCount", "couple", "shortGame"})
@JsonPropertyOrder({"userId", "roundGameId", "myScore", "partnerScore", "drawCount", "dDay", "couple", "shortGame"})
@Builder
public record HomeResponseDto(
Long userId,
Long roundGameId,
int myScore,
int partnerScore,
int drawCount,
int dDay,
CoupleDto couple,
ShortGameDto shortGame
) {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/universe/uni/service/HomeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static com.universe.uni.exception.dto.ErrorType.NOT_FOUND_USER;

import java.time.LocalDate;
import java.time.Period;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -35,12 +37,6 @@ public class HomeService {
private final RoundGameRepository roundGameRepository;

public HomeResponseDto getHome() {
/**
* jwt userId
* game에서 coupleId 조회해서 GameResult.WIN, GameResult.LOSE, GameResult.DRAW 각각 개수 변수에 저장
* userId로 shortGame 가져옴
* shortGame은 nullable합니다.
*/

/** TODO 영주 : 추후 1L 내 userId로 바꾸기*/
Long userId = 1L;
Expand All @@ -61,6 +57,10 @@ public HomeResponseDto getHome() {

int drawCount = (int)gameHistoryList.stream().filter(history -> history.getResult() == GameResult.DRAW).count();

LocalDate today = LocalDate.now();
Period period = Period.between(user.getCouple().getStartDate(), today);
int dDay = period.getDays() + 1;

Optional<ShortGameDto> shortGameDto = Optional.empty();
if (game instanceof ShortGame) {
shortGameDto = Optional.of(new ShortGameDto((ShortGame)game));
Expand All @@ -78,6 +78,7 @@ public HomeResponseDto getHome() {
.myScore(myScore)
.partnerScore(partnerScore)
.drawCount(drawCount)
.dDay(dDay)
.couple(coupleDto)
.shortGame(shortGameDto.orElse(null))
.build();
Expand Down
Loading