-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
419 additions
and
14 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
application/src/main/java/org/depromeet/spot/application/review/CreateReviewController.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,41 @@ | ||
package org.depromeet.spot.application.review; | ||
|
||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
import org.depromeet.spot.application.review.dto.request.CreateReviewRequest; | ||
import org.depromeet.spot.application.review.dto.response.ReviewResponse; | ||
import org.depromeet.spot.domain.review.Review; | ||
import org.depromeet.spot.usecase.port.in.review.CreateReviewUsecase; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@Tag(name = "리뷰") | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
public class CreateReviewController { | ||
|
||
private final CreateReviewUsecase createReviewUsecase; | ||
|
||
@ResponseStatus(HttpStatus.CREATED) | ||
@Operation(summary = "특정 좌석에 신규 리뷰를 추가한다.") | ||
@PostMapping("/seats/{seatId}/members/{memberId}/reviews") | ||
public ReviewResponse create( | ||
@PathVariable @Positive @NotNull final Long seatId, | ||
@PathVariable @Positive @NotNull final Long memberId, | ||
@RequestBody @Valid @NotNull CreateReviewRequest request) { | ||
Review review = createReviewUsecase.create(seatId, memberId, request.toCommand()); | ||
return ReviewResponse.from(review); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
.../src/main/java/org/depromeet/spot/application/review/dto/request/CreateReviewRequest.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,32 @@ | ||
package org.depromeet.spot.application.review.dto.request; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import java.util.List; | ||
|
||
import org.depromeet.spot.common.exception.review.ReviewException.InvalidReviewDateTimeFormatException; | ||
import org.depromeet.spot.usecase.port.in.review.CreateReviewUsecase.CreateReviewCommand; | ||
|
||
public record CreateReviewRequest( | ||
List<String> images, List<String> good, List<String> bad, String content, String dateTime) { | ||
|
||
public CreateReviewCommand toCommand() { | ||
return CreateReviewCommand.builder() | ||
.images(images) | ||
.good(good) | ||
.bad(bad) | ||
.content(content) | ||
.dateTime(toLocalDateTime(dateTime)) | ||
.build(); | ||
} | ||
|
||
private LocalDateTime toLocalDateTime(String dateTimeStr) { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | ||
try { | ||
return LocalDateTime.parse(dateTimeStr, formatter); | ||
} catch (DateTimeParseException e) { | ||
throw new InvalidReviewDateTimeFormatException(); | ||
} | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
common/src/main/java/org/depromeet/spot/common/exception/seat/SeatErrorCode.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,27 @@ | ||
package org.depromeet.spot.common.exception.seat; | ||
|
||
import org.depromeet.spot.common.exception.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum SeatErrorCode implements ErrorCode { | ||
SEAT_NOT_FOUND(HttpStatus.NOT_FOUND, "SEAT001", "요청 좌석이 존재하지 않습니다."), | ||
; | ||
|
||
private final HttpStatus status; | ||
private final String code; | ||
private String message; | ||
|
||
SeatErrorCode(HttpStatus status, String code, String message) { | ||
this.status = status; | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
public SeatErrorCode appended(Object o) { | ||
message = message + " {" + o.toString() + "}"; | ||
return this; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
common/src/main/java/org/depromeet/spot/common/exception/seat/SeatException.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,20 @@ | ||
package org.depromeet.spot.common.exception.seat; | ||
|
||
import org.depromeet.spot.common.exception.BusinessException; | ||
|
||
public abstract class SeatException extends BusinessException { | ||
|
||
protected SeatException(SeatErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
|
||
public static class SeatNotFoundException extends SeatException { | ||
public SeatNotFoundException() { | ||
super(SeatErrorCode.SEAT_NOT_FOUND); | ||
} | ||
|
||
public SeatNotFoundException(Object obj) { | ||
super(SeatErrorCode.SEAT_NOT_FOUND.appended(obj)); | ||
} | ||
} | ||
} |
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
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
6 changes: 6 additions & 0 deletions
6
...cture/jpa/src/main/java/org/depromeet/spot/jpa/review/repository/ReviewJpaRepository.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,6 @@ | ||
package org.depromeet.spot.jpa.review.repository; | ||
|
||
import org.depromeet.spot.jpa.review.entity.ReviewEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReviewJpaRepository extends JpaRepository<ReviewEntity, Long> {} |
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
6 changes: 6 additions & 0 deletions
6
...rc/main/java/org/depromeet/spot/jpa/review/repository/image/ReviewImageJpaRepository.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,6 @@ | ||
package org.depromeet.spot.jpa.review.repository.image; | ||
|
||
import org.depromeet.spot.jpa.review.entity.ReviewImageEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReviewImageJpaRepository extends JpaRepository<ReviewImageEntity, Long> {} |
25 changes: 25 additions & 0 deletions
25
...c/main/java/org/depromeet/spot/jpa/review/repository/image/ReviewImageRepositoryImpl.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,25 @@ | ||
package org.depromeet.spot.jpa.review.repository.image; | ||
|
||
import java.util.List; | ||
|
||
import org.depromeet.spot.domain.review.ReviewImage; | ||
import org.depromeet.spot.jpa.review.entity.ReviewImageEntity; | ||
import org.depromeet.spot.usecase.port.out.review.ReviewImageRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class ReviewImageRepositoryImpl implements ReviewImageRepository { | ||
|
||
private final ReviewImageJpaRepository reviewImageJpaRepository; | ||
|
||
@Override | ||
public List<ReviewImage> saveAll(List<ReviewImage> images) { | ||
List<ReviewImageEntity> entities = | ||
reviewImageJpaRepository.saveAll( | ||
images.stream().map(ReviewImageEntity::from).toList()); | ||
return entities.stream().map(ReviewImageEntity::toDomain).toList(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...structure/jpa/src/main/java/org/depromeet/spot/jpa/seat/repository/SeatJpaRepository.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,6 @@ | ||
package org.depromeet.spot.jpa.seat.repository; | ||
|
||
import org.depromeet.spot.jpa.seat.entity.SeatEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface SeatJpaRepository extends JpaRepository<SeatEntity, Long> {} |
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
21 changes: 21 additions & 0 deletions
21
usecase/src/main/java/org/depromeet/spot/usecase/port/in/review/CreateReviewUsecase.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,21 @@ | ||
package org.depromeet.spot.usecase.port.in.review; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import org.depromeet.spot.domain.review.Review; | ||
|
||
import lombok.Builder; | ||
|
||
public interface CreateReviewUsecase { | ||
|
||
Review create(Long seatId, Long memberId, CreateReviewCommand command); | ||
|
||
@Builder | ||
record CreateReviewCommand( | ||
List<String> images, | ||
List<String> good, | ||
List<String> bad, | ||
LocalDateTime dateTime, | ||
String content) {} | ||
} |
8 changes: 8 additions & 0 deletions
8
usecase/src/main/java/org/depromeet/spot/usecase/port/in/seat/ReadSeatUsecase.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,8 @@ | ||
package org.depromeet.spot.usecase.port.in.seat; | ||
|
||
import org.depromeet.spot.domain.seat.Seat; | ||
|
||
public interface ReadSeatUsecase { | ||
|
||
Seat findById(Long seatId); | ||
} |
10 changes: 10 additions & 0 deletions
10
usecase/src/main/java/org/depromeet/spot/usecase/port/out/review/ReviewImageRepository.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,10 @@ | ||
package org.depromeet.spot.usecase.port.out.review; | ||
|
||
import java.util.List; | ||
|
||
import org.depromeet.spot.domain.review.ReviewImage; | ||
|
||
public interface ReviewImageRepository { | ||
|
||
List<ReviewImage> saveAll(List<ReviewImage> images); | ||
} |
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
Oops, something went wrong.