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

Feat/#45 일기 관련 기획 수정된 내용 반영 #48

Merged
merged 7 commits into from
Jul 9, 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
38 changes: 29 additions & 9 deletions src/main/java/com/pyro/yolog/domain/diary/api/DiaryApi.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.pyro.yolog.domain.diary.api;

import com.pyro.yolog.domain.diary.dto.request.DiaryContentRequest;
import com.pyro.yolog.domain.diary.dto.request.DiaryDateRequest;
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.response.DiaryResponse;
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;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
Expand All @@ -14,13 +16,13 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.time.LocalDateTime;
import java.util.List;

@Tag(name = "Diary")
public interface DiaryApi {
@Operation(
summary = "일기 조회",
description = "일기장의 일기를 조회합니다.",
description = "일기를 조회합니다.",
security = {@SecurityRequirement(name = "access_token")}
)
@ApiResponses(
Expand All @@ -31,14 +33,33 @@ public interface DiaryApi {
)
}
)
DiaryResponse getDiary(
DetailDiaryResponse getDiary(
@Parameter(in = ParameterIn.PATH, description = "일기 ID", required = true)
Long id
);

@Operation(
summary = "특정 날짜의 일기 전체 조회",
description = "특정 날짜의 일기장의 일기를 전체 조회합니다.",
security = {@SecurityRequirement(name = "access_token")}
)
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "OK"
)
}
)
List<PreviewDiaryResponse> getDiaries(
@Parameter(in = ParameterIn.PATH, description = "일기장 ID", required = true)
Long tripId,

@Parameter(in = ParameterIn.PATH, description = "여행 날짜", required = true)
LocalDateTime date
@Parameter(in = ParameterIn.PATH, description = "일기 DayName", required = true)
String dayName
);


@Operation(
summary = "디폴트 일기 생성",
description = "제목과 여행 날짜를 가진 일기를 생성합니다.",
Expand All @@ -56,8 +77,7 @@ DefaultDiaryResponse createDefaultDiary(
@Parameter(in = ParameterIn.PATH, description = "일기장 ID", required = true)
Long tripId,

@Parameter(in = ParameterIn.PATH, description = "일기 작성 날짜", required = true)
LocalDateTime date
DiaryDateRequest request
);

@Operation(
Expand All @@ -73,7 +93,7 @@ DefaultDiaryResponse createDefaultDiary(
)
}
)
void updateDiaryContent(
void updateDiaryTitleAndContent(
@Parameter(in = ParameterIn.PATH, description = "일기 ID", required = true)
Long id,

Expand Down
26 changes: 17 additions & 9 deletions src/main/java/com/pyro/yolog/domain/diary/api/DiaryController.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.pyro.yolog.domain.diary.api;

import com.pyro.yolog.domain.diary.dto.request.DiaryContentRequest;
import com.pyro.yolog.domain.diary.dto.request.DiaryDateRequest;
import com.pyro.yolog.domain.diary.dto.request.MoodRequest;
import com.pyro.yolog.domain.diary.dto.response.DefaultDiaryResponse;
import com.pyro.yolog.domain.diary.dto.response.DiaryResponse;
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 lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequiredArgsConstructor
Expand All @@ -19,24 +21,30 @@ public class DiaryController implements DiaryApi {
private final DiaryService diaryService;

@ResponseStatus(HttpStatus.OK)
@GetMapping("/{tripId}/{date}")
@GetMapping("/{id}")
@Override
public DiaryResponse getDiary(@PathVariable final Long tripId, @PathVariable final LocalDateTime date) {
return diaryService.getDiary(tripId, date);
public DetailDiaryResponse getDiary(@PathVariable final Long id) {
return diaryService.getDiary(id);
}

@ResponseStatus(HttpStatus.OK)
@GetMapping("/{tripId}/days/{dayName}")
@Override
public List<PreviewDiaryResponse> getDiaries(@PathVariable final Long tripId, @PathVariable final String dayName) {
return diaryService.getDiaries(tripId, dayName);
}
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/{tripId}")
@Override
public DefaultDiaryResponse createDefaultDiary(@PathVariable final Long tripId, @PathVariable final LocalDateTime date) {
return diaryService.createDefaultDiary(tripId, date);
public DefaultDiaryResponse createDefaultDiary(@PathVariable final Long tripId, @RequestBody DiaryDateRequest request) {
return diaryService.createDefaultDiary(tripId, request);
}

@ResponseStatus(HttpStatus.NO_CONTENT)
@PutMapping("/{id}/content")
@Override
public void updateDiaryContent(@PathVariable final Long id, @RequestBody final DiaryContentRequest request) {
diaryService.updateDiaryContent(id, request);
public void updateDiaryTitleAndContent(@PathVariable final Long id, @RequestBody final DiaryContentRequest request) {
diaryService.updateDiaryTitleAndContent(id, request);
}

@ResponseStatus(HttpStatus.NO_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
@NoArgsConstructor
@Builder
public class DiaryContentRequest {
private String title;
private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.pyro.yolog.domain.diary.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class DiaryDateRequest {
@Schema(defaultValue = "2024-07-05",
description = "해당 날짜를 기반으로 DAY가 정해집니다.")
private LocalDate date;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.pyro.yolog.domain.diary.dto.request;

import com.pyro.yolog.domain.diary.entity.Mood;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class MoodRequest {
private String mood;
private Mood mood;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.pyro.yolog.domain.diary.dto.request;

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 WeatherRequest {
private String weather;
private Weather weather;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import lombok.Builder;
import lombok.Getter;

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

@Getter
@AllArgsConstructor
@Builder
public class DefaultDiaryResponse {
private Long id;
private String title;
private LocalDateTime travelDate;
private String dayName;
private LocalDate travelDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
import lombok.Builder;
import lombok.Getter;

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

@Getter
@AllArgsConstructor
@Builder
public class DiaryResponse {
public class DetailDiaryResponse {
private Long id;
private String dayName;
private String title;
private String content;
private Mood mood;
private Weather weather;
private LocalDateTime travelDate;
private LocalDate travelDate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.pyro.yolog.domain.diary.dto.response;

import com.pyro.yolog.domain.diary.entity.Mood;
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;

import java.time.LocalDate;

@Getter
@AllArgsConstructor
@Builder
public class PreviewDiaryResponse {
private Long id;
private String dayName;
private String content;
private Mood mood;
private Weather weather;
private LocalDate travelDate;
}
16 changes: 9 additions & 7 deletions src/main/java/com/pyro/yolog/domain/diary/entity/Diary.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.sql.Blob;
import java.time.LocalDateTime;
import java.time.LocalDate;

@Getter
@Entity
Expand All @@ -22,30 +21,33 @@ public class Diary {
private Long id;

@Column(nullable = false)
private String dayName;

private String title;

@Column(nullable = false)
private String content;

@Enumerated(EnumType.STRING)
private Mood mood;
@Enumerated(EnumType.STRING)
private Weather weather;

private LocalDateTime travelDate;
private LocalDate travelDate;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "trip_id")
private Trip trip;

@Builder
public Diary(String title, LocalDateTime travelDate) {
this.title = title;
public Diary(Trip trip, String dayName, LocalDate travelDate) {
this.trip = trip;
this.dayName = dayName;
this.travelDate = travelDate;
}

public void updateContent(DiaryContentRequest request) {
public void updateTitleAndContent(DiaryContentRequest request) {
this.content = request.getContent();
this.title = request.getTitle();
}

public void updateWeather(Weather weather) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/pyro/yolog/domain/diary/entity/Mood.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.pyro.yolog.domain.diary.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.pyro.yolog.domain.diary.exception.RequestMoodNameInvalidException;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.stream.Stream;

@Getter
@RequiredArgsConstructor
public enum Mood {
Expand All @@ -13,4 +17,12 @@ public enum Mood {
ANGRY("화나는");

private final String name;

@JsonCreator
public static Mood parsing(String inputValue) {
return Stream.of(Mood.values())
.filter(mood -> mood.getName().equals(inputValue))
.findFirst()
.orElseThrow(RequestMoodNameInvalidException::new);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/pyro/yolog/domain/diary/entity/Weather.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.pyro.yolog.domain.diary.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.pyro.yolog.domain.diary.exception.RequestWeatherNameInvalidException;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.stream.Stream;

@Getter
@RequiredArgsConstructor
public enum Weather {
Expand All @@ -13,4 +17,12 @@ public enum Weather {
WINDS("바람");

private final String name;

@JsonCreator
public static Weather parsing(String inputValue) {
return Stream.of(Weather.values())
.filter(weather -> weather.getName().equals(inputValue))
.findFirst()
.orElseThrow(RequestWeatherNameInvalidException::new);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.pyro.yolog.domain.diary.exception;

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

public class RequestMoodNameInvalidException extends BusinessException {
public RequestMoodNameInvalidException() {
super(ErrorCode.REQUEST_MOOD_NAME_INVALID_ERROR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.pyro.yolog.domain.diary.exception;

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

public class RequestWeatherNameInvalidException extends BusinessException {
public RequestWeatherNameInvalidException() {
super(ErrorCode.REQUEST_WEATHER_NAME_INVALID_ERROR);
}
}
Loading
Loading