diff --git a/src/main/java/com/pyro/yolog/domain/diary/api/DiaryApi.java b/src/main/java/com/pyro/yolog/domain/diary/api/DiaryApi.java index d28221c..df6a438 100644 --- a/src/main/java/com/pyro/yolog/domain/diary/api/DiaryApi.java +++ b/src/main/java/com/pyro/yolog/domain/diary/api/DiaryApi.java @@ -1,10 +1,6 @@ package com.pyro.yolog.domain.diary.api; -import com.pyro.yolog.domain.diary.dto.request.PutDiaryContentRequest; -import com.pyro.yolog.domain.diary.dto.request.CreateDiaryRequest; -import com.pyro.yolog.domain.diary.dto.request.MoodRequest; -import com.pyro.yolog.domain.diary.dto.request.WeatherRequest; -import com.pyro.yolog.domain.diary.dto.response.DefaultDiaryResponse; +import com.pyro.yolog.domain.diary.dto.request.*; import com.pyro.yolog.domain.diary.dto.response.DetailDiaryResponse; import com.pyro.yolog.domain.diary.dto.response.PreviewDiaryResponse; import io.swagger.v3.oas.annotations.Operation; @@ -81,26 +77,6 @@ void createDiary( CreateDiaryRequest request ); - @Operation( - summary = "일기 수정", - description = "일기를 수정합니다.", - security = {@SecurityRequirement(name = "access_token")} - ) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "204", - description = "No Content" - ) - } - ) - void updateDiaryTitleAndContent( - @Parameter(in = ParameterIn.PATH, description = "일기 ID", required = true) - Long id, - - @RequestBody(required = true) PutDiaryContentRequest request - ); - @Operation( summary = "일기 삭제", description = "일기를 삭제합니다.", @@ -119,28 +95,8 @@ void deleteDiary(@Parameter(in = ParameterIn.PATH, description = "일기 ID", re ); @Operation( - summary = "일기 날씨 수정", - description = "일기의 날씨 정보를 수정합니다.", - security = {@SecurityRequirement(name = "access_token")} - ) - @ApiResponses( - value = { - @ApiResponse( - responseCode = "204", - description = "No Content" - ) - } - ) - void updateWeather( - @Parameter(in = ParameterIn.PATH, description = "일기 ID", required = true) - Long id, - - @RequestBody(required = true) WeatherRequest request - ); - - @Operation( - summary = "일기 기분 수정", - description = "일기의 기분 정보를 수정합니다.", + summary = "일기 수정", + description = "일기를 수정합니다.", security = {@SecurityRequirement(name = "access_token")} ) @ApiResponses( @@ -151,9 +107,9 @@ void updateWeather( ) } ) - void updateMood(@Parameter(in = ParameterIn.PATH, description = "일기 ID", required = true) - Long id, + void updateDiary(@Parameter(in = ParameterIn.PATH, description = "일기 ID", required = true) + Long id, - @RequestBody(required = true) MoodRequest request + @RequestBody(required = true) UpdateDiaryRequest request ); } diff --git a/src/main/java/com/pyro/yolog/domain/diary/api/DiaryController.java b/src/main/java/com/pyro/yolog/domain/diary/api/DiaryController.java index 88cf8d0..50809e5 100644 --- a/src/main/java/com/pyro/yolog/domain/diary/api/DiaryController.java +++ b/src/main/java/com/pyro/yolog/domain/diary/api/DiaryController.java @@ -1,11 +1,8 @@ package com.pyro.yolog.domain.diary.api; -import com.pyro.yolog.domain.diary.dto.request.PutDiaryContentRequest; -import com.pyro.yolog.domain.diary.dto.request.CreateDiaryRequest; -import com.pyro.yolog.domain.diary.dto.request.MoodRequest; +import com.pyro.yolog.domain.diary.dto.request.*; import com.pyro.yolog.domain.diary.dto.response.DetailDiaryResponse; 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; @@ -37,15 +34,15 @@ public List getDiaries(@PathVariable final Long tripId, @P @ResponseStatus(HttpStatus.CREATED) @PostMapping("/{tripId}") @Override - public void createDiary(@PathVariable final Long tripId, @RequestBody CreateDiaryRequest request) { + public void createDiary(@PathVariable final Long tripId, @Valid @RequestBody CreateDiaryRequest request) { diaryService.createDiary(tripId, request); } @ResponseStatus(HttpStatus.NO_CONTENT) - @PutMapping("/{id}/content") + @PutMapping("/{id}") @Override - public void updateDiaryTitleAndContent(@PathVariable final Long id, @RequestBody final PutDiaryContentRequest request) { - diaryService.updateDiaryTitleAndContent(id, request); + public void updateDiary(@PathVariable final Long id, @Valid @RequestBody final UpdateDiaryRequest request) { + diaryService.updateDiary(id, request); } @ResponseStatus(HttpStatus.NO_CONTENT) @@ -54,18 +51,4 @@ public void updateDiaryTitleAndContent(@PathVariable final Long id, @RequestBody public void deleteDiary(@PathVariable final Long id) { diaryService.deleteDiary(id); } - - @ResponseStatus(HttpStatus.NO_CONTENT) - @PutMapping("/{id}/weather") - @Override - 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, @Valid @RequestBody final MoodRequest request) { - diaryService.updateMood(id, request); - } } diff --git a/src/main/java/com/pyro/yolog/domain/diary/dto/request/PutDiaryContentRequest.java b/src/main/java/com/pyro/yolog/domain/diary/dto/request/UpdateDiaryContentRequest.java similarity index 87% rename from src/main/java/com/pyro/yolog/domain/diary/dto/request/PutDiaryContentRequest.java rename to src/main/java/com/pyro/yolog/domain/diary/dto/request/UpdateDiaryContentRequest.java index 8710782..efeb2fa 100644 --- a/src/main/java/com/pyro/yolog/domain/diary/dto/request/PutDiaryContentRequest.java +++ b/src/main/java/com/pyro/yolog/domain/diary/dto/request/UpdateDiaryContentRequest.java @@ -9,7 +9,7 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class PutDiaryContentRequest { +public class UpdateDiaryContentRequest { private String title; private String content; } diff --git a/src/main/java/com/pyro/yolog/domain/diary/dto/request/UpdateDiaryRequest.java b/src/main/java/com/pyro/yolog/domain/diary/dto/request/UpdateDiaryRequest.java new file mode 100644 index 0000000..6a5fbb7 --- /dev/null +++ b/src/main/java/com/pyro/yolog/domain/diary/dto/request/UpdateDiaryRequest.java @@ -0,0 +1,19 @@ +package com.pyro.yolog.domain.diary.dto.request; + +import com.pyro.yolog.domain.diary.entity.Mood; +import com.pyro.yolog.domain.diary.entity.Weather; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class UpdateDiaryRequest { + private String title; + private String content; + private Mood mood; + private Weather weather; +} diff --git a/src/main/java/com/pyro/yolog/domain/diary/dto/response/DetailDiaryResponse.java b/src/main/java/com/pyro/yolog/domain/diary/dto/response/DetailDiaryResponse.java index 069d84d..cdbb89e 100644 --- a/src/main/java/com/pyro/yolog/domain/diary/dto/response/DetailDiaryResponse.java +++ b/src/main/java/com/pyro/yolog/domain/diary/dto/response/DetailDiaryResponse.java @@ -14,7 +14,6 @@ @Builder public class DetailDiaryResponse { private Long id; - private String dayName; private String title; private String content; private Mood mood; diff --git a/src/main/java/com/pyro/yolog/domain/diary/entity/Diary.java b/src/main/java/com/pyro/yolog/domain/diary/entity/Diary.java index 3164961..9b9cef8 100644 --- a/src/main/java/com/pyro/yolog/domain/diary/entity/Diary.java +++ b/src/main/java/com/pyro/yolog/domain/diary/entity/Diary.java @@ -1,6 +1,6 @@ package com.pyro.yolog.domain.diary.entity; -import com.pyro.yolog.domain.diary.dto.request.PutDiaryContentRequest; +import com.pyro.yolog.domain.diary.dto.request.UpdateDiaryContentRequest; import com.pyro.yolog.domain.trip.entity.Trip; import jakarta.persistence.*; import lombok.AccessLevel; @@ -20,6 +20,7 @@ public class Diary { private String title; + @Column(columnDefinition = "TEXT") private String content; @Enumerated(EnumType.STRING) @@ -43,9 +44,12 @@ public Diary(Trip trip, String title, String content, Mood mood, Weather weather this.travelDate = travelDate; } - public void updateTitleAndContent(PutDiaryContentRequest request) { - this.content = request.getContent(); - this.title = request.getTitle(); + public void updateTitle(String title) { + this.title = title; + } + + public void updateContent(String content) { + this.content = content; } public void updateWeather(Weather weather) { diff --git a/src/main/java/com/pyro/yolog/domain/diary/service/DiaryService.java b/src/main/java/com/pyro/yolog/domain/diary/service/DiaryService.java index 860792b..0e2da6d 100644 --- a/src/main/java/com/pyro/yolog/domain/diary/service/DiaryService.java +++ b/src/main/java/com/pyro/yolog/domain/diary/service/DiaryService.java @@ -1,10 +1,7 @@ package com.pyro.yolog.domain.diary.service; import com.pyro.yolog.domain.auth.service.AuthService; -import com.pyro.yolog.domain.diary.dto.request.PutDiaryContentRequest; -import com.pyro.yolog.domain.diary.dto.request.CreateDiaryRequest; -import com.pyro.yolog.domain.diary.dto.request.MoodRequest; -import com.pyro.yolog.domain.diary.dto.request.WeatherRequest; +import com.pyro.yolog.domain.diary.dto.request.*; 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; @@ -22,25 +19,29 @@ import java.time.LocalDate; import java.util.List; +import java.util.function.Consumer; import java.util.stream.Collectors; @Slf4j @Service @RequiredArgsConstructor public class DiaryService { - private static final String DAY = "Day"; - private final AuthService authService; private final DiaryRepository diaryRepository; private final TripRepository tripRepository; private final DiaryMapper diaryMapper; public DetailDiaryResponse getDiary(Long id) { - Diary diary = diaryRepository.findById(id).orElseThrow(DiaryNotFoundException::new); - checkDiaryOwner(diary); + final Diary diary = getDiaryById(id); return new DetailDiaryResponse(diary); } + private Diary getDiaryById(Long id) { + final Diary diary = diaryRepository.findById(id) + .orElseThrow(DiaryNotFoundException::new); + checkDiaryOwner(diary); + return diary; + } public List getDiaries(Long tripId, LocalDate dayName) { checkTripOwner(tripRepository.findById(tripId) @@ -52,35 +53,35 @@ public List getDiaries(Long tripId, LocalDate dayName) { @Transactional public void createDiary(final Long tripId, final CreateDiaryRequest request) { - Trip trip = tripRepository.findById(tripId).orElseThrow(TripNotFoundException::new); + final Trip trip = tripRepository.findById(tripId) + .orElseThrow(TripNotFoundException::new); diaryRepository.save(diaryMapper.toEntity(request, trip)); } - @Transactional - public void updateDiaryTitleAndContent(Long id, PutDiaryContentRequest request) { - final Diary diary = diaryRepository.findById(id).orElseThrow(DiaryNotFoundException::new); - checkDiaryOwner(diary); - diary.updateTitleAndContent(request); - } - @Transactional public void deleteDiary(Long id) { - checkDiaryOwner(diaryRepository.findById(id).orElseThrow(DiaryNotFoundException::new)); + checkDiaryOwner(diaryRepository.findById(id) + .orElseThrow(DiaryNotFoundException::new)); diaryRepository.deleteById(id); } @Transactional - public void updateWeather(Long id, WeatherRequest request) { - Diary diary = diaryRepository.findById(id).orElseThrow(DiaryNotFoundException::new); - checkDiaryOwner(diary); - diary.updateWeather(request.getWeather()); + public void updateDiary(Long id, UpdateDiaryRequest request) { + Diary diary = getDiaryById(id); + updateDiaryDetails(diary, request); } - @Transactional - public void updateMood(Long id, MoodRequest request) { - Diary diary = diaryRepository.findById(id).orElseThrow(DiaryNotFoundException::new); - checkTripOwner(diary.getTrip()); - diary.updateMood(request.getMood()); + private void updateDiaryDetails(Diary diary, UpdateDiaryRequest request) { + updateFieldIfPresent(request.getTitle(), diary::updateTitle); + updateFieldIfPresent(request.getContent(), diary::updateContent); + updateFieldIfPresent(request.getMood(), diary::updateMood); + updateFieldIfPresent(request.getWeather(), diary::updateWeather); + } + + private void updateFieldIfPresent(T value, Consumer updateMethod) { + if (value != null) { + updateMethod.accept(value); + } } @@ -88,7 +89,8 @@ public void updateMood(Long id, MoodRequest request) { public void deleteOutOfDuration(Trip trip) { checkTripOwner(trip); diaryRepository.findById(trip.getId()).ifPresent(diary -> { - if (diary.getTravelDate().isBefore(trip.getStartDate()) || diary.getTravelDate().isAfter(trip.getFinishDate())) { + if (diary.getTravelDate().isBefore(trip.getStartDate()) + || diary.getTravelDate().isAfter(trip.getFinishDate())) { diaryRepository.deleteById(diary.getId()); } }); diff --git a/src/main/java/com/pyro/yolog/domain/inquiry/entity/InquiryImage.java b/src/main/java/com/pyro/yolog/domain/inquiry/entity/InquiryImage.java index 45a1a31..487ee30 100644 --- a/src/main/java/com/pyro/yolog/domain/inquiry/entity/InquiryImage.java +++ b/src/main/java/com/pyro/yolog/domain/inquiry/entity/InquiryImage.java @@ -14,6 +14,7 @@ public class InquiryImage { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(columnDefinition = "TEXT") private String imageUrl; @ManyToOne(fetch = FetchType.LAZY) diff --git a/src/main/java/com/pyro/yolog/domain/trip/entity/Trip.java b/src/main/java/com/pyro/yolog/domain/trip/entity/Trip.java index 718e786..b2d3c7e 100644 --- a/src/main/java/com/pyro/yolog/domain/trip/entity/Trip.java +++ b/src/main/java/com/pyro/yolog/domain/trip/entity/Trip.java @@ -24,6 +24,7 @@ public class Trip extends BaseTimeEntity { private String name; private String destination; + @Column(columnDefinition = "TEXT") private String coverImageUrl; @Enumerated(EnumType.STRING)