Skip to content

Commit

Permalink
FEAT: (NONE) 판매점 리뷰 조회 시 토큰 검증 로직을 추가한다
Browse files Browse the repository at this point in the history
  • Loading branch information
anxi01 committed Aug 10, 2024
1 parent dd51bea commit 3c3a6cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import com.zerozero.core.domain.infra.repository.ReviewJPARepository;
import com.zerozero.core.domain.infra.repository.ReviewLikeJPARepository;
import com.zerozero.core.domain.infra.repository.UserJPARepository;
import com.zerozero.core.domain.vo.AccessToken;
import com.zerozero.core.domain.vo.User;
import com.zerozero.core.exception.DomainException;
import com.zerozero.core.exception.error.BaseErrorCode;
import com.zerozero.core.util.JwtUtil;
import com.zerozero.review.application.ReadStoreReviewUseCase.ReadStoreReviewRequest;
import com.zerozero.review.application.ReadStoreReviewUseCase.ReadStoreReviewResponse;
import java.util.Arrays;
Expand Down Expand Up @@ -43,14 +45,25 @@ public class ReadStoreReviewUseCase implements BaseUseCase<ReadStoreReviewReques

private final UserJPARepository userJPARepository;

private final JwtUtil jwtUtil;

@Override
public ReadStoreReviewResponse execute(ReadStoreReviewRequest request) {
if (request == null || !request.isValid()) {
log.error("[ReadStoreReviewUseCase] Invalid request");
return ReadStoreReviewResponse.builder()
.success(false)
.errorCode(ReadStoreReviewErrorCode.NOT_EXIST_REQUEST_CONDITION)
.build();
}
AccessToken accessToken = request.getAccessToken();
if (jwtUtil.isTokenExpired(accessToken.getToken())) {
log.error("[ReadStoreReviewUseCase] Expired access token");
return ReadStoreReviewResponse.builder()
.success(false)
.errorCode(ReadStoreReviewErrorCode.EXPIRED_TOKEN)
.build();
}
List<Review> reviews = reviewJPARepository.findAllByStoreIdAndDeleted(request.getStoreId(), false);
List<Integer> reviewsCount = reviews.stream()
.map(review -> reviewLikeJPARepository.countByReviewId(review.getId()))
Expand All @@ -74,7 +87,8 @@ private ReadStoreReviewResponse.Review[] convertReviewResponse(com.zerozero.core
@Getter
@RequiredArgsConstructor
public enum ReadStoreReviewErrorCode implements BaseErrorCode<DomainException> {
NOT_EXIST_REQUEST_CONDITION(HttpStatus.BAD_REQUEST, "요청 조건이 올바르지 않습니다.");
NOT_EXIST_REQUEST_CONDITION(HttpStatus.BAD_REQUEST, "요청 조건이 올바르지 않습니다."),
EXPIRED_TOKEN(HttpStatus.UNAUTHORIZED, "만료된 토큰입니다.");

private final HttpStatus httpStatus;

Expand Down Expand Up @@ -122,9 +136,11 @@ public static class ReadStoreReviewRequest implements BaseRequest {

private Filter filter;

private AccessToken accessToken;

@Override
public boolean isValid() {
return storeId != null;
return storeId != null && accessToken != null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public ResponseEntity<ReadStoreInfoResponse> readStoreInfo(@ParameterObject Read
ReadStoreReviewResponse readStoreReviewResponse = readStoreReviewUseCase.execute(ReadStoreReviewRequest.builder()
.storeId(request.getStoreId())
.filter(request.getFilter())
.accessToken(accessToken)
.build());
if (readStoreReviewResponse == null || !readStoreReviewResponse.isSuccess()) {
Optional.ofNullable(readStoreReviewResponse)
Expand Down

0 comments on commit 3c3a6cb

Please sign in to comment.