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

[feature/4-getChallenge2] 챌린지 조회 API 태그 수정 #93

Merged
merged 1 commit into from
Jul 1, 2024
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
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
Loading