diff --git a/src/main/java/com/example/api/common/type/ErrorCodeEnum.java b/src/main/java/com/example/api/common/type/ErrorCodeEnum.java index 1e48013..fb6bd00 100644 --- a/src/main/java/com/example/api/common/type/ErrorCodeEnum.java +++ b/src/main/java/com/example/api/common/type/ErrorCodeEnum.java @@ -15,6 +15,7 @@ public enum ErrorCodeEnum { USER_NOT_FOUND(HttpStatus.BAD_REQUEST, "유저 정보가 없습니다"), CODE_IS_EXPIRED(HttpStatus.BAD_REQUEST, "휴대전화를 인증해주세요"), CODE_IS_NOT_VALID(HttpStatus.BAD_REQUEST, "잘못된 인증번호입니다"), + INVALID_DURATION(HttpStatus.BAD_REQUEST, "시작 시간이 종료 시간 이후입니다"), MATCHING_NOT_FOUND(HttpStatus.BAD_REQUEST, "매칭 정보가 없습니다"), PREFERENCE_NOT_FOUND(HttpStatus.BAD_REQUEST, "선호도 정보가 없습니다"), APPLICATION_NOT_FOUND(HttpStatus.BAD_REQUEST, "신청 정보가 없습니다"), diff --git a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java index 01a0d0d..273b64c 100644 --- a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java +++ b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java @@ -17,6 +17,7 @@ import com.example.api.user.type.UserRoleEnum; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; @@ -46,7 +47,7 @@ public class MatchingController { */ @Operation(summary = "Create matching", description = "새로운 매칭을 생성한다.") @PostMapping("/matching") - public FindMatchingDto createMatching(@RequestBody SaveMatchingDto saveMatchingDto) { + public FindMatchingDto createMatching(@Valid @RequestBody SaveMatchingDto saveMatchingDto) { SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); if (securityUser == null) { log.error("MatchingController::createMatching: Login is needed"); @@ -71,7 +72,7 @@ public FindMatchingDto createMatching(@RequestBody SaveMatchingDto saveMatchingD */ @Operation(summary = "Create matching application", description = "새로운 매칭 신청을 생성한다.") @PostMapping("/matching/application") - public ChatRoom createMatchingApplication(@RequestBody SaveMatchingApplicationDto matchingApplicationDto) { + public ChatRoom createMatchingApplication(@Valid @RequestBody SaveMatchingApplicationDto matchingApplicationDto) { FindMatchingDto matchingDto = findMatchingUsecase.getMatchingById(matchingApplicationDto.getMatchingId()); if (matchingDto == null) { log.error("MatchingController::createMatchingApplication: No such matching"); diff --git a/src/main/java/com/example/api/matching/dto/SaveMatchingApplicationDto.java b/src/main/java/com/example/api/matching/dto/SaveMatchingApplicationDto.java index 0dfec86..3b5d3be 100644 --- a/src/main/java/com/example/api/matching/dto/SaveMatchingApplicationDto.java +++ b/src/main/java/com/example/api/matching/dto/SaveMatchingApplicationDto.java @@ -14,6 +14,7 @@ @NoArgsConstructor @AllArgsConstructor public class SaveMatchingApplicationDto { + @org.hibernate.validator.constraints.UUID private UUID userId; @NotNull diff --git a/src/main/java/com/example/api/matching/dto/SaveMatchingDto.java b/src/main/java/com/example/api/matching/dto/SaveMatchingDto.java index 51788ec..ac66d47 100644 --- a/src/main/java/com/example/api/matching/dto/SaveMatchingDto.java +++ b/src/main/java/com/example/api/matching/dto/SaveMatchingDto.java @@ -18,13 +18,13 @@ public class SaveMatchingDto { @NotNull private MatchingTypeEnum type; - @NotBlank + @NotBlank(message = "Title is empty") private String title; - @NotBlank + @NotBlank(message = "Place is empty") private String place; - @NotBlank + @NotBlank(message = "Content is empty") private String content; @NotNull @@ -34,7 +34,7 @@ public class SaveMatchingDto { private LocalDateTime endDate; @NotNull - @Min(1) + @Min(value = 1, message = "MaxMember must be at least 1") private Integer maxMember; @NotNull diff --git a/src/main/java/com/example/api/matching/service/MatchingService.java b/src/main/java/com/example/api/matching/service/MatchingService.java index b78eba0..9bd29ec 100644 --- a/src/main/java/com/example/api/matching/service/MatchingService.java +++ b/src/main/java/com/example/api/matching/service/MatchingService.java @@ -1,6 +1,8 @@ package com.example.api.matching.service; +import com.example.api.common.exception.CustomException; import com.example.api.common.type.ApplicationStateEnum; +import com.example.api.common.type.ErrorCodeEnum; import com.example.api.common.type.Pair; import com.example.api.matching.adapter.out.persistence.MatchingEntity; import com.example.api.matching.adapter.out.persistence.MatchingMapperInterface; @@ -39,6 +41,10 @@ public class MatchingService implements SaveMatchingUsecase, FindMatchingUsecase public FindMatchingDto createMatching(UUID writerId, SaveMatchingDto matchingDto) { Matching matching = matchingMapper.toDomain(matchingDto); matching.setWriterId(writerId); + if (matching.getStartDate().isAfter(matching.getEndDate())) { + log.error("MatchingService::createMatching: Invalid duration"); + throw new CustomException(ErrorCodeEnum.INVALID_DURATION); + } return matchingMapper.toDto(saveMatchingPort.createMatching(matching)); }