-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from team-Ollie/develop
[develop] Tag 관련 enum 정의 및 프로그램 목록 조회 구현
- Loading branch information
Showing
7 changed files
with
136 additions
and
24 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ollie.wecare.common.enums; | ||
|
||
import lombok.Getter; | ||
import ollie.wecare.common.base.BaseException; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static ollie.wecare.common.base.BaseResponseStatus.WRONG_TAG_DETAIL; | ||
import static ollie.wecare.common.base.BaseResponseStatus.WRONG_TAG_NAME; | ||
|
||
@Getter | ||
public enum TagEnum { | ||
LOCATION("위치", null), | ||
SEOUL("서울", LOCATION), | ||
GYEONGGI("경기", LOCATION), | ||
OTHER("그 외", LOCATION), | ||
CATEGORY("카테고리", null), | ||
SPORTS("운동", CATEGORY), | ||
ART("예술", CATEGORY), | ||
ACADEMIC("학술", CATEGORY), | ||
ETC("기타", CATEGORY); | ||
|
||
private final String tagName; | ||
private final TagEnum parent; | ||
private final List<TagEnum> child; | ||
|
||
TagEnum(String name, TagEnum parent) { | ||
this.child = new ArrayList<>(); | ||
this.tagName = name; | ||
this.parent = parent; | ||
if(Objects.nonNull(parent)) { | ||
parent.child.add(this); | ||
} | ||
} | ||
|
||
public static TagEnum getEnumByName(String name) throws BaseException { | ||
return Arrays.stream(TagEnum.values()) | ||
.filter(tagEnum -> tagEnum.getTagName().equalsIgnoreCase(name)) | ||
.findFirst() | ||
.orElseThrow(() -> new BaseException(WRONG_TAG_NAME)); | ||
} | ||
|
||
public static TagEnum getTag(TagEnum tagEnum, String tagDetail) throws BaseException { | ||
return Arrays.stream(TagEnum.values()) | ||
.filter(t -> t.parent == tagEnum && t.getTagName().equalsIgnoreCase(tagDetail)) | ||
.findFirst() | ||
.orElseThrow(() -> new BaseException(WRONG_TAG_DETAIL)); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/main/java/ollie/wecare/program/dto/ProgramListResponse.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,40 @@ | ||
package ollie.wecare.program.dto; | ||
|
||
import ollie.wecare.common.enums.TagEnum; | ||
import ollie.wecare.program.entity.Program; | ||
import ollie.wecare.program.entity.Tag; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record ProgramListResponse(Long programIdx, | ||
String name, | ||
DateDto openDate, | ||
DateDto dueDate, | ||
String location, | ||
String category) { | ||
private static DateDto convertToDateDto(LocalDateTime dueDate) { | ||
if (dueDate == null) return null; | ||
return new DateDto( | ||
dueDate.getYear(), | ||
dueDate.getMonthValue(), | ||
dueDate.getDayOfMonth()); | ||
} | ||
|
||
public static ProgramListResponse fromProgram(Program program) { | ||
return new ProgramListResponse( | ||
program.getProgramIdx(), | ||
program.getName(), | ||
convertToDateDto(program.getOpenDate()), | ||
convertToDateDto(program.getDueDate()), | ||
program.getLocation(), | ||
getCategoryTag(program) != null ? getCategoryTag(program).getTagName() : null); | ||
} | ||
|
||
private static TagEnum getCategoryTag(Program program) { | ||
return program.getTags().stream() | ||
.map(Tag::getName) | ||
.filter(tagEnum -> tagEnum.getParent() == TagEnum.CATEGORY) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
package ollie.wecare.program.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.*; | ||
import ollie.wecare.common.base.BaseEntity; | ||
import ollie.wecare.common.enums.TagEnum; | ||
import org.hibernate.annotations.DynamicInsert; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@DynamicInsert | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Tag extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "tag_idx") | ||
private Long tagIdx; | ||
|
||
private String name; | ||
@Enumerated(EnumType.STRING) | ||
private TagEnum name; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "program_idx") | ||
private Program program; | ||
|
||
public void setProgram(Program program) { | ||
this.program = program; | ||
if (program != null) { program.getTags().add(this); } | ||
} | ||
} |
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