Skip to content

Commit

Permalink
Merge pull request #149 from Team-Motivoo/chore/#148-mission_history_…
Browse files Browse the repository at this point in the history
…response

[CHORE] 미션 히스토리 응답 추가
  • Loading branch information
jun02160 authored Mar 24, 2024
2 parents 32fcaf6 + fe2eff7 commit 8c7bb0d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@Builder
public record MissionHistoryResponse(
@JsonProperty("user_type") String userType,
@JsonProperty("opponent_user_type") String opponentUserType,
@JsonProperty("today_mission") TodayUserMissionResponse todayMission,
@JsonProperty("mission_history") List<ParentchildMissionResponse> missionHistory
) {
Expand All @@ -20,6 +21,7 @@ public static MissionHistoryResponse of(MissionHistoryResult result) {

return MissionHistoryResponse.builder()
.userType(result.userType())
.opponentUserType(result.opponentUserType())
.todayMission(TodayUserMissionResponse.of(result.todayMission()))
.missionHistory(result.missionHistory() != null ? result.missionHistory().stream().map(ParentchildMissionResponse::of)
.collect(Collectors.toList()) : null).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ void getMissionHistory() throws Exception {
fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"),
fieldWithPath("data").description("응답 데이터"),
fieldWithPath("data.user_type").type(STRING).description("유저의 타입(PARENT|CHILD)"),
fieldWithPath("data.opponent_user_type").type(STRING).description("상대 유저의 타입(PARENT|CHILD)"),
fieldWithPath("data.today_mission").type(OBJECT).description("오늘의 미션"),
fieldWithPath("data.today_mission.mission_content").type(STRING).description("오늘의 미션 내용"),
fieldWithPath("data.today_mission.date").type(STRING).description("오늘 날짜"),
Expand Down
2 changes: 1 addition & 1 deletion motivoo-api/src/test/java/fixture/UserMissionFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static MissionHistoryResponse createMissionHistoryResponse() {
User childUser = createUser();
User parentUser = createUserV2();

return MissionHistoryResponse.of(MissionHistoryResult.of(childUser, createUserMission(), createUserMissions(), createUserMissions()));
return MissionHistoryResponse.of(MissionHistoryResult.of(childUser, parentUser, createUserMission(), createUserMissions(), createUserMissions()));
}

public static TodayMissionResponse createTodayMissionResponse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,38 @@
@Builder
public record MissionHistoryResult(
String userType,
String opponentUserType,
Boolean isTodayMissionChoiceCompleted,
TodayUserMissionDto todayMission,
List<ParentchildMissionDto> missionHistory
) {


public static MissionHistoryResult of(User user, UserMission todayMission, Map<LocalDate, List<UserMission>> missionGroupsByDate) {
public static MissionHistoryResult of(User user, User opponentUser, UserMission todayMission, Map<LocalDate, List<UserMission>> missionGroupsByDate) {

List<ParentchildMissionDto> parentchildMissions = getParentchildMissionDtos(user, missionGroupsByDate);

return MissionHistoryResult.builder()
.userType(user.getType().getValue())
.opponentUserType(opponentUser.getType().getValue())
.todayMission(TodayUserMissionDto.ofHistory(todayMission))
.missionHistory(parentchildMissions).build();
}

public static MissionHistoryResult of(User user, Map<LocalDate, List<UserMission>> missionGroupsByDate) {
public static MissionHistoryResult of(User user, User opponentUser, Map<LocalDate, List<UserMission>> missionGroupsByDate) {

List<ParentchildMissionDto> parentchildMissions = getParentchildMissionDtos(user, missionGroupsByDate);

return MissionHistoryResult.builder()
.userType(user.getType().getValue())
.opponentUserType(opponentUser.getType().getValue())
.missionHistory(parentchildMissions).build();
}

public static MissionHistoryResult of(User user) {
public static MissionHistoryResult of(User myUser, User opponentUser) {
return MissionHistoryResult.builder()
.userType(user.getType().getValue()).build();
.userType(myUser.getType().getValue())
.opponentUserType(opponentUser.getType().getValue()).build();
}

@NotNull
Expand All @@ -63,10 +67,11 @@ private static List<ParentchildMissionDto> getParentchildMissionDtos(User user,


// Test용
public static MissionHistoryResult of(User user, UserMission todayMission, List<UserMission> myMissions, List<UserMission> opponentMissions) {
public static MissionHistoryResult of(User user, User opponentUser, UserMission todayMission, List<UserMission> myMissions, List<UserMission> opponentMissions) {

return MissionHistoryResult.builder()
.userType(user.getType().getValue())
.opponentUserType(opponentUser.getType().getValue())
.todayMission(TodayUserMissionDto.ofHistory(todayMission))
.missionHistory(IntStream.range(0, myMissions.size())
.mapToObj(i -> ParentchildMissionDto.of(myMissions.get(i), opponentMissions.get(i)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public MissionHistoryResult getUserMissionHistory(final Long userId) {

// 유저의 미션 목록이 없는 경우
if (myUser.getUserMissions().isEmpty()) {
return MissionHistoryResult.of(myUser);
return MissionHistoryResult.of(myUser, opponentUser);
}

Map<LocalDate, List<UserMission>> missionsByDate = groupUserMissionsByDate(userId, opponentUser.getId());
Expand All @@ -83,10 +83,10 @@ public MissionHistoryResult getUserMissionHistory(final Long userId) {

// 오늘의 미션을 아직 선택하지 않은 경우
if (!validateTodayDateMission(todayMission)) {
return MissionHistoryResult.of(myUser, missionsByDate);
return MissionHistoryResult.of(myUser, opponentUser, missionsByDate);
}

return MissionHistoryResult.of(myUser, todayMission, missionsByDate);
return MissionHistoryResult.of(myUser, opponentUser, todayMission, missionsByDate);
}

private Map<LocalDate, List<UserMission>> groupUserMissionsByDate(Long myUserId, Long opponentUserId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void init() {
FirebaseApp.initializeApp(options);
log.info("파이어베이스 연결에 성공했습니다.");
ref = FirebaseDatabase.getInstance().getReference(COLLECTION_NAME);
log.info("ref = {}", ref.getDatabase()+" "+COLLECTION_NAME);

} catch (IOException e) {
log.error("파이어베이스 서버와의 연결에 실패했습니다.");
throw new BusinessException(FIREBASE_CONNECTION_ERROR);
Expand Down

0 comments on commit 8c7bb0d

Please sign in to comment.