Skip to content

Commit

Permalink
Merge pull request #157 from TEAM-MODDY/fix/#155
Browse files Browse the repository at this point in the history
#155 [fix] Content Type, Json 으로 나눠서 받을 수 있도록 API 수정
  • Loading branch information
hellozo0 authored Jan 16, 2024
2 parents e7418ac + 11266ce commit 4cc10f3
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import com.moddy.server.common.dto.SuccessResponse;
import com.moddy.server.common.exception.enums.SuccessCode;
import com.moddy.server.config.resolver.user.UserId;
import com.moddy.server.controller.model.dto.requestEditor.ListPropertyEditor;
import com.moddy.server.controller.model.dto.request.ModelApplicationRequest;
import com.moddy.server.controller.model.dto.request.ModelHairServiceRequest;
import com.moddy.server.controller.model.dto.response.DetailOfferResponse;
import com.moddy.server.controller.model.dto.response.ModelMainResponse;
import com.moddy.server.controller.model.dto.response.OpenChatResponse;
Expand All @@ -22,9 +20,8 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Tag(name = "ModelController")
Expand Down Expand Up @@ -104,14 +101,11 @@ public SuccessNonDataResponse acceptOffer(
@PostMapping(value = "/application", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public SuccessNonDataResponse submitModelApplication(
@Parameter(hidden = true) @UserId Long userId,
@ModelAttribute ModelApplicationRequest request) {
modelService.postApplication(userId, request);
@RequestPart(value = "modelImgUrl", required = false) MultipartFile modelImgUrl,
@RequestPart(value = "applicationCaptureImgUrl", required = false) MultipartFile applicationCaptureImgUrl,
@RequestPart(value = "applicationInfo") ModelApplicationRequest applicationInfo) {
modelService.postApplication(userId, modelImgUrl, applicationCaptureImgUrl, applicationInfo);
return SuccessNonDataResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS);
}

@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(List.class, "hairServiceRecords", new ListPropertyEditor(ModelHairServiceRequest.class));
}

}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.moddy.server.controller.model.dto.request;

import org.springframework.web.multipart.MultipartFile;
import com.moddy.server.domain.hair_model_application.HairLength;
import java.util.List;

import com.moddy.server.domain.prefer_hair_style.HairStyle;
import io.swagger.v3.oas.annotations.media.Schema;

public record ModelApplicationRequest(
@Schema(description = "모델의 현재 머리 기장 예시입니다.", example ="SHORT")
String hairLength,
HairLength hairLength,
@Schema(description = "PreferHaireStyle의 예시 JSON 배열 포맷입니다.", example ="[\"NORMAL_CUT\", \"ALL_COLOR\"]")
List<String> preferHairStyles,
List<HairStyle> preferHairStyles,
@Schema(description = "모델이 원하는 헤어스타일 예시입니다.", example = "안녕하세요 저는 숱을 많이 친 허쉬컷이 하고 싶어요 근데 머리가 곱슬이라 매직도 같이 해야지 이쁘게 될것 같아요. 그리고 머리가 얇아서 그거 감안하고 해야할것 같습니다.")
String hairDetail,
@Schema(description = "HairServiceRecords 의 예시 JSON 배열 포맷입니다.", example = "[{\"hairService\": \"PERM\", \"hairServiceTerm\": \"UNDER_ONE\"}, {\"hairService\": \"BLACK\", \"hairServiceTerm\": \"ABOVE_TWELVE\"}]")
List<ModelHairServiceRequest> hairServiceRecords,
MultipartFile modelImgUrl,
@Schema(description = "모델의 인스타그램 예시입니다.", example ="hizo0")
String instagramId,
MultipartFile applicationCaptureImgUrl
String instagramId
) {
public List<ModelHairServiceRequest> getHairServiceRecords() {
return hairServiceRecords;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.moddy.server.controller.model.dto.request;

import com.moddy.server.domain.hair_service_record.ServiceRecord;
import com.moddy.server.domain.hair_service_record.ServiceRecordTerm;

public record ModelHairServiceRequest(
String hairService,
String hairServiceTerm
ServiceRecord hairService,
ServiceRecordTerm hairServiceTerm
) {
}

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/java/com/moddy/server/domain/day_off/DayOfWeek.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
package com.moddy.server.domain.day_off;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.BadRequestException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

@Getter
@AllArgsConstructor
public enum DayOfWeek {
MON("월"), TUE("화"), WED("수"), THU("목"), FRI("금"), SAT("토"), SUN("일");

private final String value;

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static DayOfWeek findByDayOfWeek(String dayOfWeek) {
return Stream.of(DayOfWeek.values())
.filter(c -> c.name().equals(dayOfWeek))
.findFirst()
.orElseThrow(() -> new BadRequestException(ErrorCode.INVALID_DAY_OF_WEEK_EXCEPTION));
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
package com.moddy.server.domain.hair_model_application;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.BadRequestException;
import com.moddy.server.domain.user.Gender;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

@AllArgsConstructor
@Getter
public enum HairLength {
SHORT("숏"), ABOVE_SHOULDER("단발"), UNDER_SHOULDER("어깨 아래"), UNDER_WAIST("허리 아래");

private final String value;

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static HairLength findByHairLength(String hairLength) {
return Stream.of(HairLength.values())
.filter(c -> c.name().equals(hairLength))
.findFirst()
.orElseThrow(() -> new BadRequestException(ErrorCode.INVALID_HAIR_LENGTH_EXCEPTION));
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
package com.moddy.server.domain.hair_service_record;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.BadRequestException;
import com.moddy.server.domain.hair_model_application.HairLength;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

@Getter
@AllArgsConstructor
public enum ServiceRecord {
PERM("펌"), DECOLOR("탈색"), BLACK("블랙 염색"), COLOR("컬러 염색");

private final String value;

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static ServiceRecord findByServiceRecord(String serviceRecord) {
return Stream.of(ServiceRecord.values())
.filter(c -> c.name().equals(serviceRecord))
.findFirst()
.orElseThrow(() -> new BadRequestException(ErrorCode.INVALID_HAIR_SERVICE_RECORD_EXCEPTION));
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
package com.moddy.server.domain.hair_service_record;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.BadRequestException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

@Getter
@AllArgsConstructor
public enum ServiceRecordTerm {
UNDER_ONE("1 개월 미만"), ONE_THREE("1 - 3 개월"), FOUR_SIX("4 - 6 개월"), SEVEN_TWELVE("7 - 12 개월"), ABOVE_TWELVE("12 개월 초과");

private final String value;

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static ServiceRecordTerm findByServiceRecord(String serviceRecordTerm) {
return Stream.of(ServiceRecordTerm.values())
.filter(c -> c.name().equals(serviceRecordTerm))
.findFirst()
.orElseThrow(() -> new BadRequestException(ErrorCode.INVALID_HAIR_SERVICE_RECORD_TERM_EXCEPTION));
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
package com.moddy.server.domain.prefer_hair_style;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.BadRequestException;
import com.moddy.server.domain.hair_model_application.HairLength;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

@AllArgsConstructor
@Getter
public enum HairStyle {
NORMAL_CUT("일반 커트"), ALL_COLOR("전체 염색"), ALL_DECOLOR("전체 탈색"), SETTING_PERM("셋팅펌"), NORMAL_PERM("일반펌"), STRAIGHTENING("매직");

private final String value;

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static HairStyle findByHairStyle(String hairStyle) {
return Stream.of(HairStyle.values())
.filter(c -> c.name().equals(hairStyle))
.findFirst()
.orElseThrow(() -> new BadRequestException(ErrorCode.INVALID_HAIR_STYLE_EXCEPTION));
}

}

13 changes: 1 addition & 12 deletions src/main/java/com/moddy/server/domain/user/Gender.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
package com.moddy.server.domain.user;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.BadRequestException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

@Getter
@AllArgsConstructor
public enum Gender {
MALE("남성"), FEMALE("여성");
private final String value;

@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static Gender findByGender(String gender) {
return Stream.of(Gender.values())
.filter(c -> c.name().equals(gender))
.findFirst()
.orElseThrow(() -> new BadRequestException(ErrorCode.INVALID_GENDER_EXCEPTION));
}
private final String value;
}
Loading

0 comments on commit 4cc10f3

Please sign in to comment.