Skip to content

Commit

Permalink
Merge pull request #94 from team-Ollie/feature/4-getChallenge2
Browse files Browse the repository at this point in the history
[feature/4-getChallenge2] 챌린지 조회 API 태그 수정
  • Loading branch information
Haeun-Y authored Jul 1, 2024
2 parents d5a07ea + 477889c commit c96996e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
13 changes: 12 additions & 1 deletion src/main/java/ollie/wecare/challenge/dto/GetChallengesRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import ollie.wecare.challenge.entity.Challenge;
import ollie.wecare.common.enums.TagEnum;
import ollie.wecare.program.entity.Program;
import ollie.wecare.program.entity.Tag;

@Data
@AllArgsConstructor
Expand Down Expand Up @@ -32,10 +35,18 @@ public static GetChallengesRes fromChallenge(Challenge challenge, Integer myAtte
.challengeIdx(challenge.getChallengeIdx())
.name(challenge.getName())
.participantsCount(challenge.getParticipants().size())
.location(challenge.getProgram().getLocation())
.location(getLocationTag(challenge.getProgram()) != null ? getLocationTag(challenge.getProgram()).getTagName() : null)
.schedule(challenge.getProgram().getSchedule())
.myAttendanceRate(myAttendanceRate)
.totalAttendanceRate(challenge.getAttendanceRate()).build();
}

private static TagEnum getLocationTag(Program program) {
return program.getTags().stream()
.map(Tag::getName)
.filter(tagEnum -> tagEnum.getParent() == TagEnum.LOCATION)
.findFirst()
.orElse(null);
}

}
22 changes: 21 additions & 1 deletion src/main/java/ollie/wecare/program/dto/GetProgramDetailRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import ollie.wecare.common.enums.TagEnum;
import ollie.wecare.program.entity.Program;
import ollie.wecare.program.entity.Tag;

import java.time.LocalDateTime;

Expand All @@ -25,6 +27,8 @@ public class GetProgramDetailRes {

private String location;

private String category;

private String host;

private String schedule;
Expand All @@ -38,7 +42,8 @@ public static GetProgramDetailRes fromProgram(Program program) {
.name(program.getName())
.openDate(convertToDateDto(program.getOpenDate()))
.dueDate(convertToDateDto(program.getDueDate()))
.location(program.getLocation())
.location(getLocationTag(program) != null ? getLocationTag(program).getTagName() : null)
.category(getCategoryTag(program) != null ? getCategoryTag(program).getTagName() : null)
.host(program.getHost())
.schedule(program.getSchedule())
.description(program.getDescription()).build();
Expand All @@ -51,4 +56,19 @@ private static DateDto convertToDateDto(LocalDateTime dueDate) {
dueDate.getMonthValue(),
dueDate.getDayOfMonth());
}
private static TagEnum getCategoryTag(Program program) {
return program.getTags().stream()
.map(Tag::getName)
.filter(tagEnum -> tagEnum.getParent() == TagEnum.CATEGORY)
.findFirst()
.orElse(null);
}

private static TagEnum getLocationTag(Program program) {
return program.getTags().stream()
.map(Tag::getName)
.filter(tagEnum -> tagEnum.getParent() == TagEnum.LOCATION)
.findFirst()
.orElse(null);
}
}
1 change: 0 additions & 1 deletion src/main/java/ollie/wecare/program/dto/PostProgramReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public static Program toProgram(PostProgramReq postProgramReq) {
return Program.builder().name(postProgramReq.getName())
.dueDate(convertToLocalDateTime(postProgramReq.getDueDate()))
.openDate(convertToLocalDateTime(postProgramReq.getOpenDate()))
.location((postProgramReq.getLocation()))
.host(postProgramReq.getHost())
.schedule(postProgramReq.getSchedule())
.description(postProgramReq.getDescription())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static ProgramListResponse fromProgram(Program program) {
program.getName(),
convertToDateDto(program.getOpenDate()),
convertToDateDto(program.getDueDate()),
getLocationTag(program) != null ? getCategoryTag(program).getTagName() : null,
getLocationTag(program) != null ? getLocationTag(program).getTagName() : null,
getCategoryTag(program) != null ? getCategoryTag(program).getTagName() : null);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ollie/wecare/program/entity/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Program extends BaseEntity {

private LocalDateTime openDate;

private String location;
//private String location;

private String host;

Expand Down

0 comments on commit c96996e

Please sign in to comment.