-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
d82ec28
commit 428d069
Showing
10 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package umc.spring.converter; | ||
|
||
import org.springframework.data.domain.Page; | ||
import umc.spring.domain.Review; | ||
import umc.spring.web.dto.StoreResponseDTO; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class StoreConverter { | ||
|
||
public static StoreResponseDTO.ReviewPreViewDTO reviewPreViewDTO(Review review){ | ||
return StoreResponseDTO.ReviewPreViewDTO.builder() | ||
.ownerNickname(review.getMember().getName()) | ||
.score(review.getScore()) | ||
.body(review.getBody()) | ||
.createdAt(review.getCreatedAt().toLocalDate()) | ||
.build(); | ||
} | ||
|
||
|
||
public static StoreResponseDTO.ReviewPreViewListDTO reviewPreViewListDTO(Page<Review> reviewList){ | ||
List<StoreResponseDTO.ReviewPreViewDTO> reviewPreViewDTOList = reviewList.stream() | ||
.map(StoreConverter::reviewPreViewDTO).collect(Collectors.toList()); | ||
|
||
return StoreResponseDTO.ReviewPreViewListDTO.builder() | ||
.isLast(reviewList.isLast()) | ||
.isFirst(reviewList.isFirst()) | ||
.totalPage(reviewList.getTotalPages()) | ||
.totalElements(reviewList.getTotalElements()) | ||
.listSize(reviewPreViewDTOList.size()) | ||
.reviewList(reviewPreViewDTOList) | ||
.build(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/umc/spring/repository/ReviewRepository/ReviewRepository.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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package umc.spring.repository.ReviewRepository; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import umc.spring.domain.Review; | ||
import umc.spring.domain.Store; | ||
|
||
public interface ReviewRepository extends JpaRepository<Review, Long>, ReviewRepositoryCustom { | ||
|
||
Page<Review> findAllByStore(Store store, PageRequest pageRequest); | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/umc/spring/validation/annotation/ExistStore.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,17 @@ | ||
package umc.spring.validation.annotation; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
import umc.spring.validation.validator.StoreExistValidator; | ||
|
||
import java.lang.annotation.*; | ||
|
||
@Documented | ||
@Constraint(validatedBy = StoreExistValidator.class) | ||
@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ExistStore { | ||
String message() default "해당하는 가게가 존재하지 않습니다."; | ||
Class<?>[] groups() default {}; | ||
Class<? extends Payload>[] payload() default {}; | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/umc/spring/validation/validator/StoreExistValidator.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,36 @@ | ||
package umc.spring.validation.validator; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import umc.spring.apiPayload.code.status.ErrorStatus; | ||
import umc.spring.domain.Store; | ||
import umc.spring.service.StoreService.StoreQueryService; | ||
import umc.spring.validation.annotation.ExistStore; | ||
|
||
import java.util.Optional; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class StoreExistValidator implements ConstraintValidator<ExistStore, Long> { | ||
|
||
private final StoreQueryService storeQueryService; | ||
|
||
@Override | ||
public void initialize(ExistStore constraintAnnotation) { | ||
ConstraintValidator.super.initialize(constraintAnnotation); | ||
} | ||
|
||
@Override | ||
public boolean isValid(Long value, ConstraintValidatorContext context) { | ||
Optional<Store> target = storeQueryService.findStore(value); | ||
|
||
if (target.isEmpty()){ | ||
context.disableDefaultConstraintViolation(); | ||
context.buildConstraintViolationWithTemplate(ErrorStatus.STORE_NOT_FOUND.toString()).addConstraintViolation(); | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/umc/spring/web/controller/StoreRestController.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,43 @@ | ||
package umc.spring.web.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.Parameters; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
import umc.spring.apiPayload.ApiResponse; | ||
import umc.spring.converter.StoreConverter; | ||
import umc.spring.domain.Review; | ||
import umc.spring.service.StoreService.StoreQueryService; | ||
import umc.spring.validation.annotation.ExistStore; | ||
import umc.spring.web.dto.StoreResponseDTO; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Validated | ||
@RequestMapping("/stores") | ||
public class StoreRestController { | ||
|
||
private final StoreQueryService storeQueryService; | ||
|
||
@GetMapping("/{storeId}/reviews") | ||
@Operation(summary = "특정 가게의 리뷰 목록 조회 API",description = "특정 가게의 리뷰들의 목록을 조회하는 API이며, 페이징을 포함합니다. query String 으로 page 번호를 주세요") | ||
@ApiResponses({ | ||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), | ||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))), | ||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))), | ||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class))), | ||
}) | ||
@Parameters({ | ||
@Parameter(name = "storeId", description = "가게의 아이디, path variable 입니다!") | ||
}) | ||
public ApiResponse<StoreResponseDTO.ReviewPreViewListDTO> getReviewList(@ExistStore @PathVariable(name = "storeId") Long storeId, @RequestParam(name = "page") Integer page){ | ||
Page<Review> reviewList = storeQueryService.getReviewList(storeId, page); | ||
return ApiResponse.onSuccess(StoreConverter.reviewPreViewListDTO(reviewList)); | ||
} | ||
} |
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,4 @@ | ||
package umc.spring.web.dto; | ||
|
||
public class StoreRequestDTO { | ||
} |
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,36 @@ | ||
package umc.spring.web.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public class StoreResponseDTO { | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class ReviewPreViewListDTO { | ||
List<ReviewPreViewDTO> reviewList; | ||
Integer listSize; | ||
Integer totalPage; | ||
Long totalElements; | ||
Boolean isFirst; | ||
Boolean isLast; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class ReviewPreViewDTO { | ||
String ownerNickname; | ||
Float score; | ||
String body; | ||
LocalDate createdAt; | ||
} | ||
} |