Skip to content

Commit

Permalink
feat: Trip에 색상 커버 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjy committed Jul 10, 2024
1 parent 589bf8f commit fe279c5
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/pyro/yolog/domain/trip/dto/TripRequest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pyro.yolog.domain.trip.dto;

import com.pyro.yolog.domain.trip.entity.ColorCover;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -18,9 +19,13 @@ public class TripRequest {
private String name;
private String destination;

@Schema(description = "이미지 커버입니다. URL 형식으로 입력되어야 합니다.")
@URL
private String coverImageUrl;

@Schema(defaultValue = "ECD5E3", description = "색상 커버입니다. 지정된 색상 코드만 입력되어야 합니다.")
private ColorCover colorCover;

@Schema(defaultValue = "2024-07-05")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/com/pyro/yolog/domain/trip/dto/TripResponse.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.pyro.yolog.domain.trip.dto;

import com.pyro.yolog.domain.trip.entity.ColorCover;
import com.pyro.yolog.domain.trip.entity.Trip;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Getter
@AllArgsConstructor
Expand All @@ -15,7 +16,25 @@ public class TripResponse {
private String name;
private String destination;
private String coverImageUrl;
private String colorCover;

private LocalDate startDate;
private LocalDate finishDate;

public TripResponse(Trip trip) {
this.id = trip.getId();
this.name = trip.getName();
this.destination = trip.getDestination();
this.coverImageUrl = trip.getCoverImageUrl();
this.colorCover = getColorCode(trip.getColorCover());
this.startDate = trip.getStartDate();
this.finishDate = trip.getFinishDate();
}

private String getColorCode(ColorCover colorCover) {
if (colorCover == null) {
return null;
}
return colorCover.getCode();
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/pyro/yolog/domain/trip/entity/ColorCover.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.pyro.yolog.domain.trip.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.pyro.yolog.domain.trip.exception.RequestColorCoverInvalidException;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.stream.Stream;

@Getter
@RequiredArgsConstructor
public enum ColorCover {
PALE_YELLOW("FFFFB5"),
AQUA_BLUE("D2F5F5"),
PASTEL_BLUE("C6DCE9"),
GRAY_GREEN("9DAAA2"),
PALE_MINT("C6EFDC"),
PALE_PEACH("FED5CF"),
BABY_PINK("FFD1DB"),
BEIGE_BROWN("BBA498"),
IVORY("F2E3C7"),
PALE_OLIVE_GREEN("C4D4B1"),
PALE_GREEN("B2BDA8"),
LIGHT_BROWN("A49D92"),
PALE_AQUA("C6DBDA"),
PALE_CORAL("F1B598"),
LAVENDER("D3C7E6"),
PALE_LILAC("ECD5E3")
;

private final String code;

@JsonCreator
public static ColorCover parsing(String inputValue) {
return Stream.of(ColorCover.values())
.filter(color -> color.getCode().equals(inputValue))
.findFirst()
.orElseThrow(RequestColorCoverInvalidException::new);
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/pyro/yolog/domain/trip/entity/Trip.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public class Trip extends BaseTimeEntity {
@Column(nullable = false)
private String name;
private String destination;

private String coverImageUrl;

@Enumerated(EnumType.STRING)
private ColorCover colorCover;

@NotNull
private LocalDate startDate;

Expand All @@ -36,10 +40,11 @@ public class Trip extends BaseTimeEntity {
private Member member;

@Builder
public Trip(String name, String destination, String coverImageUrl, LocalDate startDate, LocalDate finishDate, Member member) {
public Trip(String name, String destination, String coverImageUrl, ColorCover colorCover, LocalDate startDate, LocalDate finishDate, Member member) {
this.name = name;
this.destination = destination;
this.coverImageUrl = coverImageUrl;
this.colorCover = colorCover;
this.startDate = startDate;
this.finishDate = finishDate;
this.member = member;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public Trip getTrip(final Long id) {
public List<TripResponse> getTrips() {
Member login = authService.getLoginUser();
return tripRepository.findAllByMember(login).stream()
.map(tripMapper::toResponse).collect(Collectors.toList());
.map(TripResponse::new).collect(Collectors.toList());
}
}

0 comments on commit fe279c5

Please sign in to comment.