Skip to content

Commit

Permalink
Merge pull request #50 from pyro-yolog/feat/#49-color-cover-image
Browse files Browse the repository at this point in the history
Feat/#49 컬러 커버 이미지 설정 기능 추가
  • Loading branch information
yeonjy authored Jul 10, 2024
2 parents 2cd3861 + fe279c5 commit 2c25f34
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.pyro.yolog.domain.diary.dto.response.PreviewDiaryResponse;
import com.pyro.yolog.domain.diary.dto.request.WeatherRequest;
import com.pyro.yolog.domain.diary.service.DiaryService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -57,14 +58,14 @@ public void deleteDiary(@PathVariable final Long id) {
@ResponseStatus(HttpStatus.NO_CONTENT)
@PutMapping("/{id}/weather")
@Override
public void updateWeather(@PathVariable final Long id, @RequestBody final WeatherRequest request) {
public void updateWeather(@PathVariable final Long id, @Valid @RequestBody final WeatherRequest request) {
diaryService.updateWeather(id, request);
}

@ResponseStatus(HttpStatus.NO_CONTENT)
@PutMapping("/{id}/mood")
@Override
public void updateMood(@PathVariable final Long id, @RequestBody final MoodRequest request) {
public void updateMood(@PathVariable final Long id, @Valid @RequestBody final MoodRequest request) {
diaryService.updateMood(id, request);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pyro.yolog.domain.diary.dto.request;

import com.pyro.yolog.domain.diary.entity.Mood;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -11,5 +12,6 @@
@NoArgsConstructor
@Builder
public class MoodRequest {
@Schema(defaultValue = "행복한")
private Mood mood;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pyro.yolog.domain.diary.dto.request;

import com.pyro.yolog.domain.diary.entity.Weather;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -11,5 +12,6 @@
@NoArgsConstructor
@Builder
public class WeatherRequest {
@Schema(defaultValue = "맑음")
private Weather weather;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pyro.yolog.domain.diary.dto.response;

import com.pyro.yolog.domain.diary.entity.Diary;
import com.pyro.yolog.domain.diary.entity.Mood;
import com.pyro.yolog.domain.diary.entity.Weather;
import lombok.AllArgsConstructor;
Expand All @@ -16,7 +17,31 @@ public class DetailDiaryResponse {
private String dayName;
private String title;
private String content;
private Mood mood;
private Weather weather;
private String mood;
private String weather;
private LocalDate travelDate;

public DetailDiaryResponse(Diary diary) {
this.id = diary.getId();
this.dayName = diary.getDayName();
this.title = diary.getTitle();
this.content = diary.getContent();
this.mood = getMood(diary.getMood());
this.weather = getWeather(diary.getWeather());
this.travelDate = diary.getTravelDate();
}

private String getMood(Mood mood) {
if (mood == null) {
return null;
}
return mood.getName();
}

private String getWeather(Weather weather) {
if (weather == null) {
return null;
}
return weather.getName();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pyro.yolog.domain.diary.dto.response;

import com.pyro.yolog.domain.diary.entity.Diary;
import com.pyro.yolog.domain.diary.entity.Mood;
import com.pyro.yolog.domain.diary.entity.Weather;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -16,7 +17,30 @@ public class PreviewDiaryResponse {
private Long id;
private String dayName;
private String content;
private Mood mood;
private Weather weather;
private String mood;
private String weather;
private LocalDate travelDate;

public PreviewDiaryResponse(Diary diary) {
this.id = diary.getId();
this.dayName = diary.getDayName();
this.content = diary.getContent();
this.mood = getMood(diary.getMood());
this.weather = getWeather(diary.getWeather());
this.travelDate = diary.getTravelDate();
}

private String getMood(Mood mood) {
if (mood == null) {
return null;
}
return mood.getName();
}

private String getWeather(Weather weather) {
if (weather == null) {
return null;
}
return weather.getName();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.pyro.yolog.domain.diary.mapper;

import com.pyro.yolog.domain.diary.dto.response.DefaultDiaryResponse;
import com.pyro.yolog.domain.diary.dto.response.DetailDiaryResponse;
import com.pyro.yolog.domain.diary.dto.response.PreviewDiaryResponse;
import com.pyro.yolog.domain.diary.entity.Diary;
import com.pyro.yolog.domain.trip.entity.Trip;
import org.mapstruct.Mapper;
Expand All @@ -12,11 +10,6 @@

@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface DiaryMapper {

PreviewDiaryResponse toPreviewResponse(Diary diary);

DetailDiaryResponse toDetailResponse(Diary diary);

DefaultDiaryResponse toDefaultFormatResponse(Diary diary);

Diary toEntity(Trip trip, String dayName, LocalDate travelDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public class DiaryService {
private final DiaryMapper diaryMapper;

public DetailDiaryResponse getDiary(Long id) {
return diaryMapper.toDetailResponse(diaryRepository.findById(id)
.orElseThrow(EntityNotFoundException::new));
return new DetailDiaryResponse((diaryRepository.findById(id)
.orElseThrow(EntityNotFoundException::new)));
}


public List<PreviewDiaryResponse> getDiaries(Long tripId, String dayName) {
List<Diary> diaries = diaryRepository.findAllByTripIdAndDayName(tripId, dayName);
return diaries.stream().map(diaryMapper::toPreviewResponse).collect(Collectors.toList());
return diaries.stream().map(PreviewDiaryResponse::new).collect(Collectors.toList());
}

@Transactional
Expand Down
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
@@ -0,0 +1,10 @@
package com.pyro.yolog.domain.trip.exception;

import com.pyro.yolog.global.error.ErrorCode;
import com.pyro.yolog.global.error.exception.BusinessException;

public class RequestColorCoverInvalidException extends BusinessException {
public RequestColorCoverInvalidException() {
super(ErrorCode.REQUEST_COLOR_COVER_INVALID_ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

import com.pyro.yolog.domain.member.entity.Member;
import com.pyro.yolog.domain.trip.dto.TripRequest;
import com.pyro.yolog.domain.trip.dto.TripResponse;
import com.pyro.yolog.domain.trip.entity.Trip;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;

@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface TripMapper {
Trip toEntity(TripRequest request, Member member);

TripResponse toResponse(Trip trip);
}
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());
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/pyro/yolog/global/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public enum ErrorCode {
INQUIRY_NOT_FOUND_ERROR(HttpStatus.NOT_FOUND, "해당 문의를 찾지 못했습니다."),
INQUIRY_NOT_ADMIN_MEMBER(HttpStatus.BAD_REQUEST, "문의하기 답변은 관리자만 가능합니다."),

// TRIP
REQUEST_COLOR_COVER_INVALID_ERROR(HttpStatus.BAD_REQUEST, "올바른 색상 코드를 입력해야 합니다."),

//DIARY
REQUEST_WEATHER_NAME_INVALID_ERROR(HttpStatus.BAD_REQUEST, "올바른 날씨를 입력해야 합니다."),
REQUEST_MOOD_NAME_INVALID_ERROR(HttpStatus.BAD_REQUEST, "올바른 기분을 입력해야 합니다."),
Expand Down

0 comments on commit 2c25f34

Please sign in to comment.