Skip to content

Commit

Permalink
#149 [fix] gill pull conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
hellozo0 committed Jan 17, 2024
2 parents bf48d8b + 670a448 commit 0ba7b4f
Show file tree
Hide file tree
Showing 25 changed files with 327 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static com.moddy.server.common.exception.enums.ErrorCode.NOT_FOUND_RESOURCE_EXCEPTION;
import static com.moddy.server.common.exception.enums.ErrorCode.VALIDATION_REQUEST_MISSING_EXCEPTION;


@Slf4j
@RestControllerAdvice
public class GlobalControllerExceptionAdvice {
Expand Down Expand Up @@ -115,7 +116,7 @@ protected ErrorResponse handleNoResourceFoundException(final NoResourceFoundExce
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
protected ErrorResponse handleHttpRequestMethodNotSupportedException(
HttpRequestMethodNotSupportedException exception) {
HttpRequestMethodNotSupportedException e) {
return ErrorResponse.error(METHOD_NOT_ALLOWED_EXCEPTION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum ErrorCode {
INVALID_HAIR_SERVICE_RECORD_TERM_EXCEPTION(HttpStatus.BAD_REQUEST, "유효하지 않은 헤어시술 이력기간을 입력했습니다."),
INVALID_HAIR_STYLE_EXCEPTION(HttpStatus.BAD_REQUEST, "유효하지 않은 헤어스타일을 입력했습니다."),
INVALID_VALUE_TYPE_EXCEPTION(HttpStatus.BAD_REQUEST, "유효하지 않은 타입 값을 입력했습니다."),
VALIDATION_REQUEST_MISSING_EXCEPTION(HttpStatus.BAD_REQUEST, "요청값이 유효하지 않습니다."),
INVALID_PHONE_NUMBER_EXCEPTION(HttpStatus.BAD_REQUEST, "유효하지 않은 전화번호를 입력했습니다."),

// 401
Expand All @@ -39,11 +40,14 @@ public enum ErrorCode {
NOT_FOUND_RESOURCE_EXCEPTION(HttpStatus.NOT_FOUND, "해당 자원을 찾을 수 없습니다."),
NOT_FOUND_REGION_EXCEPTION(HttpStatus.NOT_FOUND, "해당 지역을 찾을 수 없습니다."),
NOT_FOUND_VERIFICATION_CODE_EXCEPTION(HttpStatus.NOT_FOUND, "인증 코드가 존재하지 않습니다."),
VALIDATION_REQUEST_MISSING_EXCEPTION(HttpStatus.BAD_REQUEST, "요청값이 유효하지 않습니다."),

// 405 METHOD_NOT_ALLOWED
METHOD_NOT_ALLOWED_EXCEPTION(HttpStatus.METHOD_NOT_ALLOWED, "지원하지 않는 메소드 입니다."),

// 409 Conflict
ALREADY_EXIST_USER_EXCEPTION(HttpStatus.CONFLICT, "이미 존재하는 유저입니다."),
ALREADY_EXIST_OFFER_EXCEPTION(HttpStatus.CONFLICT, "이미 존재하는 제안서입니다"),

// 500
INTERNAL_SERVER_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류입니다.");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.moddy.server.common.validation.prefer_regions;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.HashSet;
import java.util.List;

public class PreferRegionsValidator implements ConstraintValidator<ValidPreferRegions, List<Long>> {

@Override
public void initialize(ValidPreferRegions constraintAnnotation) {
}

@Override
public boolean isValid(List<Long> preferRegions, ConstraintValidatorContext context) {

if (preferRegions == null || preferRegions.isEmpty()) return false;
if (preferRegions.size() > 3 ) return false;
if (preferRegions.size() != new HashSet<>(preferRegions).size()) return false;
if (preferRegions.stream().filter(p -> p == 0).count() == 1 && preferRegions.stream().anyMatch(p -> p != 0)) return false;
if (!preferRegions.stream().allMatch(p -> p >= 0 && p <= 25)) return false;

return true;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.moddy.server.common.validation.prefer_regions;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Constraint(validatedBy = PreferRegionsValidator.class)
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface ValidPreferRegions {

String message() default "preferRegions는 0은 1개만, 1~25사이의 값은 3개까지 올 수 있습니다.";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.moddy.server.common.validation.unique_dayofweek;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.*;


@Documented
@Constraint(validatedBy = UniqueDayOfWeekValidator.class)
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface UniqueDayOfWeek {
String message() default "List elements must be unique";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.moddy.server.common.validation.unique_dayofweek;

import com.moddy.server.domain.day_off.DayOfWeek;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class UniqueDayOfWeekValidator implements ConstraintValidator<UniqueDayOfWeek, List<DayOfWeek>> {

@Override
public void initialize(UniqueDayOfWeek constraintAnnotation) {
}

@Override
public boolean isValid(List<DayOfWeek> dayOfWeeks, ConstraintValidatorContext context) {
Set<DayOfWeek> uniqueDays = new HashSet<>(dayOfWeeks);
return uniqueDays.size() == dayOfWeeks.size();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.moddy.server.common.validation.unique_prefer_offer_condition;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.*;

@Documented
@Constraint(validatedBy = UniqueOfferConditionValidator.class)
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface UniqueOfferCondition {
String message() default "List elements must be unique";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.moddy.server.common.validation.unique_prefer_offer_condition;

import com.moddy.server.domain.day_off.DayOfWeek;
import com.moddy.server.domain.prefer_offer_condition.OfferCondition;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class UniqueOfferConditionValidator implements ConstraintValidator<UniqueOfferCondition, List<OfferCondition>> {
@Override
public void initialize(UniqueOfferCondition constraintAnnotation) {
}

@Override
public boolean isValid(List<OfferCondition> offerConditions, ConstraintValidatorContext context) {
Set<OfferCondition> uniqueConditions = new HashSet<>(offerConditions);
return uniqueConditions.size() == offerConditions.size();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.moddy.server.common.validation.year;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Constraint(validatedBy = YearValidator.class)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface ValidYear {

String message() default "Year는 오늘의 년도보다 큰 년도일 수 없어요.";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.moddy.server.common.validation.year;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class YearValidator implements ConstraintValidator<ValidYear, String> {

@Override
public void initialize(ValidYear constraintAnnotation) {
}

@Override
public boolean isValid(String year, ConstraintValidatorContext context) {
try {
int parsedYear = Integer.parseInt(year);
int currentYear = Calendar.getInstance().get(Calendar.YEAR);

return parsedYear >= 1900 && parsedYear <= currentYear;

} catch (NumberFormatException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -92,7 +93,7 @@ public SuccessResponse<List<RegionResponse>> getRegionList() {
SuccessResponse<UserCreateResponse> createDesigner(
@Parameter(hidden = true) @UserId Long userId,
@RequestPart(value = "profileImg", required = false) MultipartFile profileImg,
@RequestPart("designerInfo") DesignerCreateRequest designerInfo) {
@Valid @RequestPart("designerInfo") DesignerCreateRequest designerInfo) {
return SuccessResponse.success(SuccessCode.DESIGNER_CREATE_SUCCESS, designerService.createDesigner(userId, designerInfo, profileImg));
}

Expand All @@ -107,7 +108,7 @@ SuccessResponse<UserCreateResponse> createDesigner(
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<UserCreateResponse> createModel(
@Parameter(hidden = true) @UserId Long userId,
@RequestBody ModelCreateRequest modelCreateRequest) {
@Valid @RequestBody ModelCreateRequest modelCreateRequest) {
return SuccessResponse.success(SuccessCode.MODEL_CREATE_SUCCESS, modelService.createModel(userId, modelCreateRequest));
}

Expand All @@ -118,7 +119,7 @@ public SuccessResponse<UserCreateResponse> createModel(
@ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PostMapping("/phoneNumber")
public SuccessNonDataResponse sendVerificationCodeMessageToUser(@RequestBody PhoneNumberRequestDto phoneNumberRequestDto) throws IOException {
public SuccessNonDataResponse sendVerificationCodeMessageToUser(@Valid @RequestBody PhoneNumberRequestDto phoneNumberRequestDto) throws IOException {
authService.sendVerificationCodeMessageToUser(phoneNumberRequestDto.phoneNumber());
return SuccessNonDataResponse.success(SEND_VERIFICATION_CODE_SUCCESS);
}
Expand All @@ -135,7 +136,7 @@ public SuccessNonDataResponse sendVerificationCodeMessageToUser(@RequestBody Pho
@ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PostMapping("/phoneNumber/verify")
public SuccessNonDataResponse verifyCode(@RequestBody VerifyCodeRequestDto verifyCodeRequestDto) {
public SuccessNonDataResponse verifyCode(@Valid @RequestBody VerifyCodeRequestDto verifyCodeRequestDto) {
authService.verifyCode(verifyCodeRequestDto.phoneNumber(), verifyCodeRequestDto.verifyCode());
return SuccessNonDataResponse.success(VERIFICATION_CODE_MATCH_SUCCESS);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
package com.moddy.server.controller.auth.dto.request;

public record PhoneNumberRequestDto(String phoneNumber) {
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Pattern;

public record PhoneNumberRequestDto(
@Schema(example = "01020000000")
@Pattern(regexp = "^010[0-9]{8}$", message = "phoneNumber는 01011112222형태입니다.")
String phoneNumber
) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
package com.moddy.server.controller.auth.dto.request;

public record VerifyCodeRequestDto(String phoneNumber, String verifyCode) {
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Pattern;

public record VerifyCodeRequestDto(
@Schema(example = "01020000000")
@Pattern(regexp = "^010[0-9]{8}$", message = "phoneNumber는 01011112222형태입니다.")
String phoneNumber,
@Schema(example = "123456")
@Pattern(regexp = "[0-9]{6}$", message = "verifyCode는 123456형태입니다.")
String verifyCode
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -65,7 +66,7 @@ public SuccessResponse<DesignerMainResponse> getDesignerMainInfo(
public SuccessNonDataResponse offerCreateRequest(
@Parameter(hidden = true) @UserId Long userId,
@PathVariable(value = "applicationId") Long applicationId,
@RequestBody OfferCreateRequest offerCreateRequest) {
@Valid @RequestBody OfferCreateRequest offerCreateRequest) {
designerService.postOffer(userId, applicationId, offerCreateRequest);
return SuccessNonDataResponse.success(SuccessCode.POST_OFFER_SUCCESS);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package com.moddy.server.controller.designer.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.*;

@Builder
public record HairShopDto(
@Schema(example = "juno")
@NotBlank
@Size(min = 1, max = 25, message = "name은 1~25 글자수 사이의 글자입니다.")
String name,
@Schema(example = "서울시 강남구")
@NotBlank
String address,
@Schema(example = "선릉로 122길")
@NotBlank
@Size(min = 1, max = 30, message = "상세주소는 1~30 글자수 사이의 글자입니다.")
String detailAddress
)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.moddy.server.controller.designer.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.*;


@Builder
public record PortfolioDto(
@Schema(example = "http://instagram")
@NotBlank
@Pattern(regexp = "^[^\\s]+$", message = "url에는 공백(whitespaces)이 들어갈 수 없습니다.")
String instagramUrl,
@Schema(example = "http://naver")
@NotBlank
@Pattern(regexp = "^[^\\s]+$", message = "url에는 공백(whitespaces)이 들어갈 수 없습니다.")
String naverPlaceUrl
) {
}
Loading

0 comments on commit 0ba7b4f

Please sign in to comment.