Skip to content

Commit

Permalink
Merge pull request #110 from CHZZK-Study/release/1.0.1
Browse files Browse the repository at this point in the history
release: 1.0.1
  • Loading branch information
junest66 authored Oct 26, 2024
2 parents d8ff9cd + 38359fe commit 42d0321
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import static org.chzz.market.common.error.GlobalErrorCode.EXTERNAL_API_ERROR;

import java.io.IOException;
import java.util.List;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.chzz.market.common.error.ErrorCode;
import org.chzz.market.common.error.ErrorResponse;
import org.chzz.market.common.error.GlobalErrorCode;
import org.chzz.market.common.error.GlobalException;
import org.chzz.market.common.error.exception.BusinessException;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
Expand All @@ -20,6 +22,7 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.method.annotation.HandlerMethodValidationException;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.multipart.support.MissingServletRequestPartException;
import org.springframework.web.reactive.function.client.WebClientResponseException;
Expand All @@ -32,6 +35,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
private static final String LOG_FORMAT = "\nException Class = {}\nResponse Code = {}\nMessage = {}";

// 1. 커스텀 예외 핸들러

/**
* 비즈니스 로직에서 정의한 예외가 발생할 때 처리
*/
Expand Down Expand Up @@ -83,6 +87,7 @@ public ResponseEntity<Object> handleIOException(IOException e) {
}

// 2. ResponseEntityExceptionHandler에서 오버라이드된 핸들러

/**
* 필수 요청 매개변수가 누락된 경우 발생
*/
Expand Down Expand Up @@ -145,6 +150,39 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(@NonNull MethodArg
.body(errorResponse);
}

/**
* @ReuqestParam, @PathVariable 에서 발생하는 유효성 검사 에러 핸들러
*/
@Override
protected ResponseEntity<Object> handleHandlerMethodValidationException(
@NonNull HandlerMethodValidationException ex,
@NonNull HttpHeaders headers, @NonNull HttpStatusCode status,
@NonNull WebRequest request) {
GlobalErrorCode errorCode = GlobalErrorCode.VALIDATION_FAILED;

// 모든 오류를 추출
List<? extends MessageSourceResolvable> allErrors = ex.getAllErrors();
log.info("allErrors = {}", allErrors);

// 필드명과 기본 메시지를 조합하여 "필드명: 메시지" 형식으로 변환
String[] errorMessages = allErrors.stream()
.map(error -> {
String[] codes = error.getCodes();
String fieldName = (codes != null && codes.length > 0)
? codes[0].substring(codes[0].lastIndexOf('.') + 1) // 필드명 추출
: "Unknown field";
return fieldName + ": " + error.getDefaultMessage(); // 필드명과 기본 메시지 결합
})
.toArray(String[]::new);

logException(ex, errorCode, errorMessages);

ErrorResponse errorResponse = ErrorResponse.of(errorCode, errorMessages);
return ResponseEntity
.status(errorCode.getHttpStatus())
.body(errorResponse);
}

/**
* 읽을 수 없는 HTTP 메시지가 수신된 경우 발생
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.chzz.market.domain.address.dto.DeliveryRequest;
import org.chzz.market.domain.address.dto.DeliveryResponse;
import org.springframework.data.domain.Page;
Expand All @@ -16,10 +17,10 @@ public interface AddressApi {
public ResponseEntity<Page<DeliveryResponse>> getAddresses(Long userId, Pageable pageable);

@Operation(summary = "배송지 추가")
public ResponseEntity<Void> addDelivery(Long userId, DeliveryRequest deliveryRequest);
public ResponseEntity<Void> addDelivery(Long userId, @Valid DeliveryRequest deliveryRequest);

@Operation(summary = "배송지 수정")
public ResponseEntity<Void> updateDelivery(Long userId, Long addressId, DeliveryRequest deliveryRequest);
public ResponseEntity<Void> updateDelivery(Long userId, Long addressId, @Valid DeliveryRequest deliveryRequest);

@Operation(summary = "배송시 삭제", description = "기본 배송지는 삭제할 수 없습니다")
public ResponseEntity<Void> deleteDelivery(Long userId, Long addressId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public record DeliveryRequest(
String recipientName,

@NotBlank(message = "전화번호는 필수 입력 사항입니다.")
@Pattern(regexp = "^(01[016789]-?\\d{3,4}-?\\d{4})$", message = "전화번호 형식이 올바르지 않습니다.")
@Pattern(regexp = "^010-\\d{3,4}-\\d{4}$", message = "전화번호 형식이 올바르지 않습니다.")
String phoneNumber,

Boolean isDefault
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import org.chzz.market.common.config.LoginUser;
import org.chzz.market.common.springdoc.ApiExceptionExplanation;
Expand Down Expand Up @@ -72,7 +73,7 @@ public interface AuctionApi {
ResponseEntity<Page<UserEndedAuctionResponse>> getEndedAuctions(Long userId, Pageable pageable);

@Operation(summary = "경매 등록")
ResponseEntity<RegisterResponse> registerAuction(Long userId, BaseRegisterRequest request,
ResponseEntity<RegisterResponse> registerAuction(Long userId, @Valid BaseRegisterRequest request,
List<MultipartFile> images);

@ApiResponseExplanations(
Expand All @@ -86,7 +87,7 @@ ResponseEntity<RegisterResponse> registerAuction(Long userId, BaseRegisterReques
}
)
@Operation(summary = "정식 경매 전환")
ResponseEntity<StartAuctionResponse> startAuction(Long userId, StartAuctionRequest request);
ResponseEntity<StartAuctionResponse> startAuction(Long userId, @Valid StartAuctionRequest request);

@Operation(summary = "테스트 경매 등록")
ResponseEntity<Void> testEndAuction(Long userId, int seconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -30,8 +30,7 @@ public abstract class BaseRegisterRequest {
@Size(min = 2, max = 30, message = "제목은 최소 2글자 이상 30자 이하여야 합니다")
protected String productName;

@NotNull
@Size(max = 1000, message = "상품 설명은 최대 1000자까지 가능합니다")
@Pattern(regexp = "^$|.{5,1000}$", message = "상품 설명은 최소 5자에서 최대 1000자까지 가능합니다")
protected String description;

@NotNull(message = "카테고리를 선택해주세요")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.chzz.market.common.util.QuerydslUtil.nullSafeBuilder;
import static org.chzz.market.domain.auction.entity.QAuction.auction;
import static org.chzz.market.domain.auction.repository.AuctionRepositoryCustomImpl.AuctionOrder.NEWEST;
import static org.chzz.market.domain.auction.repository.AuctionRepositoryCustomImpl.AuctionOrder.POPULARITY;
import static org.chzz.market.domain.auction.type.AuctionStatus.ENDED;
import static org.chzz.market.domain.auction.type.AuctionStatus.PROCEEDING;
Expand Down Expand Up @@ -246,7 +247,7 @@ public List<AuctionResponse> findBestAuctions() {
JPAQuery<?> baseQuery = jpaQueryFactory.from(auction)
.join(auction.product, product)
.where(auction.status.eq(PROCEEDING))
.orderBy(POPULARITY.getOrderSpecifier());
.orderBy(POPULARITY.getOrderSpecifier(), NEWEST.getOrderSpecifier());

return baseQuery.select(new QAuctionResponse(
auction.id,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.chzz.market.common.springdoc.ApiExceptionExplanation;
import org.chzz.market.common.springdoc.ApiResponseExplanations;
import org.chzz.market.domain.auction.error.AuctionErrorCode;
Expand Down Expand Up @@ -41,7 +42,7 @@ ResponseEntity<Page<BiddingRecord>> findUsersBidHistory(Long userId, @ParameterO
@ApiExceptionExplanation(value = BidErrorCode.class, constant = BID_ALREADY_CANCELLED, name = "취소한 입찰 일때"),
}
)
ResponseEntity<Void> createBid(BidCreateRequest bidCreateRequest, Long userId);
ResponseEntity<Void> createBid(@Valid BidCreateRequest bidCreateRequest, Long userId);

@Operation(summary = "입찰 취소")
ResponseEntity<Void> cancelBid(Long bidId, Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import org.chzz.market.domain.payment.entity.Payment;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionalEventListener;

@Service
@RequiredArgsConstructor
@Transactional
public class OrderService {
private final OrderRepository orderRepository;
private final AddressRepository addressRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.Map;
import org.chzz.market.domain.payment.dto.request.ApprovalRequest;
import org.chzz.market.domain.payment.dto.response.ApprovalResponse;
Expand All @@ -12,7 +13,7 @@
public interface PaymentApi {

@Operation(summary = "결제 승인")
public ResponseEntity<ApprovalResponse> approvePayment(Long userId, ApprovalRequest request);
public ResponseEntity<ApprovalResponse> approvePayment(Long userId, @Valid ApprovalRequest request);

@Operation(summary = "주문 ID 생성")
public ResponseEntity<Map<String, String>> createOrderId();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.chzz.market.domain.payment.controller;

import jakarta.validation.Valid;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.chzz.market.common.config.LoginUser;
Expand All @@ -21,7 +22,7 @@ public class PaymentController implements PaymentApi {

@Override
@PostMapping("/approval")
public ResponseEntity<ApprovalResponse> approvePayment(@LoginUser Long userId, @RequestBody ApprovalRequest request) {
public ResponseEntity<ApprovalResponse> approvePayment(@LoginUser Long userId, @Valid @RequestBody ApprovalRequest request) {
ApprovalResponse approval = paymentService.approval(userId, request);
return ResponseEntity.status(HttpStatus.OK).body(approval); // TODO: redirect to payment page
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import java.util.Map;
import org.chzz.market.domain.like.dto.LikeResponse;
Expand Down Expand Up @@ -48,7 +49,7 @@ ResponseEntity<Page<ProductResponse>> getProductList(Category category, Long use
description = "key: 이미지 순서(1~5), value: 업로드할 이미지 파일",
schema = @Schema(type = "string", format = "binary")
)
ResponseEntity<UpdateProductResponse> updateProduct(Long userId, Long productId, UpdateProductRequest request,
ResponseEntity<UpdateProductResponse> updateProduct(Long userId, Long productId, @Valid UpdateProductRequest request,
Map<String, MultipartFile> images);

@Operation(summary = "사전 경매 삭제")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.chzz.market.domain.product.entity.Product.Category;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -20,7 +21,7 @@ public class UpdateProductRequest {
@Size(min = 2, max = 30, message = "제목은 최소 2글자 이상 30자 이하여야 합니다")
private String productName;

@Size(max = 1000, message = "상품 설명은 최대 1000자까지 가능합니다")
@Pattern(regexp = "^$|.{5,1000}$", message = "상품 설명은 최소 5자에서 최대 1000자까지 가능합니다")
private String description;

private Category category;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import java.util.Map;
import org.chzz.market.domain.user.dto.request.UpdateUserProfileRequest;
import org.chzz.market.domain.user.dto.request.UserCreateRequest;
import org.chzz.market.domain.user.dto.response.NicknameAvailabilityResponse;
import org.chzz.market.domain.user.dto.response.UserProfileResponse;
import org.hibernate.validator.constraints.Length;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -25,14 +27,14 @@ public interface UserApi {
ResponseEntity<UserProfileResponse> getUserProfileByNickname(String nickname);

@Operation(summary = "닉네임 중복 확인")
ResponseEntity<NicknameAvailabilityResponse> checkNickname(String nickname);
ResponseEntity<NicknameAvailabilityResponse> checkNickname(@Length(min = 1, max = 15) String nickname);

@Operation(summary = "회원가입 완료")
ResponseEntity<Void> completeRegistration(Long userId, UserCreateRequest userCreateRequest,
ResponseEntity<Void> completeRegistration(Long userId, @Valid UserCreateRequest userCreateRequest,
HttpServletResponse response);

@Operation(summary = "프로필 수정")
ResponseEntity<Void> updateUserProfile(Long userId, MultipartFile file, UpdateUserProfileRequest request);
ResponseEntity<Void> updateUserProfile(Long userId, MultipartFile file, @Valid UpdateUserProfileRequest request);

@Operation(summary = "JWT 토큰 재발급")
ResponseEntity<Void> reissue(HttpServletRequest request, HttpServletResponse response);
Expand Down
Loading

0 comments on commit 42d0321

Please sign in to comment.