diff --git a/src/main/java/com/moddy/server/common/exception/enums/SuccessCode.java b/src/main/java/com/moddy/server/common/exception/enums/SuccessCode.java index edc194bf..aab685ec 100644 --- a/src/main/java/com/moddy/server/common/exception/enums/SuccessCode.java +++ b/src/main/java/com/moddy/server/common/exception/enums/SuccessCode.java @@ -31,7 +31,8 @@ public enum SuccessCode { CHECK_VALID_APPLICATION_SUCCESS(HttpStatus.OK, "유효한 지원서 입니다."), APPLICATION_DELETE_SUCCESS(HttpStatus.OK, "지원서 삭제하기 성공"), FIND_DESIGNER_INFO_SUCCESS(HttpStatus.OK, "디자이너 정보 조회 성공"), - FIND_MODEL_INFO_SUCCESS(HttpStatus.OK, "모델 정보 조회 성공"); + FIND_MODEL_INFO_SUCCESS(HttpStatus.OK, "모델 정보 조회 성공"), + MODEL_UPDATE_SUCCESS(HttpStatus.OK,"모델 정보 수정 성공"); private final HttpStatus httpStatus; private final String message; diff --git a/src/main/java/com/moddy/server/controller/model/ModelRegisterController.java b/src/main/java/com/moddy/server/controller/model/ModelRegisterController.java index f64b4f31..532bf09e 100644 --- a/src/main/java/com/moddy/server/controller/model/ModelRegisterController.java +++ b/src/main/java/com/moddy/server/controller/model/ModelRegisterController.java @@ -1,11 +1,13 @@ package com.moddy.server.controller.model; import com.moddy.server.common.dto.ErrorResponse; +import com.moddy.server.common.dto.SuccessNonDataResponse; 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.designer.dto.response.UserCreateResponse; import com.moddy.server.controller.model.dto.request.ModelCreateRequest; +import com.moddy.server.controller.model.dto.request.ModelUpdateRequest; import com.moddy.server.service.model.ModelRegisterService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -18,6 +20,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -44,4 +47,21 @@ public SuccessResponse createModel( @Valid @RequestBody ModelCreateRequest modelCreateRequest) { return SuccessResponse.success(SuccessCode.MODEL_CREATE_SUCCESS, modelRegisterService.createModel(userId, modelCreateRequest)); } + + @Operation(summary = "[JWT] 모델 마이페이지 수정 API", description = "모델 마이페이지 수정 API입니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "모델 마이페이지 수정 성공"), + @ApiResponse(responseCode = "401", description = "인증오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse(responseCode = "404", description = "유효하지 않은 값을 입력했습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class))) + }) + @PutMapping + @SecurityRequirement(name = "JWT Auth") + public SuccessNonDataResponse updateModel( + @Parameter(hidden = true) @UserId Long modelId, + @Valid @RequestBody ModelUpdateRequest modelUpdateRequest) { + modelRegisterService.updateModel(modelId, modelUpdateRequest); + return SuccessNonDataResponse.success(SuccessCode.MODEL_UPDATE_SUCCESS); + } + } diff --git a/src/main/java/com/moddy/server/controller/model/dto/request/ModelCreateRequest.java b/src/main/java/com/moddy/server/controller/model/dto/request/ModelCreateRequest.java index 2c9e9a03..02ba7be2 100644 --- a/src/main/java/com/moddy/server/controller/model/dto/request/ModelCreateRequest.java +++ b/src/main/java/com/moddy/server/controller/model/dto/request/ModelCreateRequest.java @@ -17,7 +17,7 @@ @NotNull public record ModelCreateRequest( @Schema(description = "모델 회원가입 유저 이름 예시입니다.", example ="안현주") - @Size(min = 0, max = 10, message = "name은 1~10 글자수 사이의 글자입니다.") + @Size(min = 0, max = 10, message = "name은 1~5 글자수 사이의 글자입니다.") String name, @Schema(description = "모델 회원가입 유저 나이 예시입니다.", example ="2000") @NotBlank diff --git a/src/main/java/com/moddy/server/controller/model/dto/request/ModelUpdateRequest.java b/src/main/java/com/moddy/server/controller/model/dto/request/ModelUpdateRequest.java new file mode 100644 index 00000000..b3067b4c --- /dev/null +++ b/src/main/java/com/moddy/server/controller/model/dto/request/ModelUpdateRequest.java @@ -0,0 +1,32 @@ +package com.moddy.server.controller.model.dto.request; + +import com.moddy.server.common.validation.prefer_regions.ValidPreferRegions; +import com.moddy.server.common.validation.year.ValidYear; +import com.moddy.server.domain.user.Gender; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; + +import java.util.List; + +@NotNull +public record ModelUpdateRequest( + @Schema(description = "모델 회원가입 유저 이름 예시입니다.", example ="안현주") + @Size(min = 0, max = 5, message = "name은 1~5 글자수 사이의 글자입니다.") + String name, + @Schema(description = "모델 회원가입 유저 나이 예시입니다.", example ="2000") + @NotBlank + @ValidYear + String year, + @Schema(description = "모델 회원가입 유저 성별 예시입니다.", example ="FEMALE") + @Enumerated(EnumType.STRING) + @NotNull + Gender gender, + @Schema(description = "모델 회원가입 선호 지역 예시입니다.", example ="[\"3\", \"15\"]") + @ValidPreferRegions + List preferRegions +) { +} diff --git a/src/main/java/com/moddy/server/domain/model/Model.java b/src/main/java/com/moddy/server/domain/model/Model.java index 224a0856..ee3943f2 100644 --- a/src/main/java/com/moddy/server/domain/model/Model.java +++ b/src/main/java/com/moddy/server/domain/model/Model.java @@ -6,7 +6,6 @@ import lombok.Getter; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; -import lombok.Setter; import lombok.experimental.SuperBuilder; import java.time.LocalDateTime; @@ -20,9 +19,14 @@ public class Model extends User { @NotNull private String year; + public int getAge() { LocalDateTime currentDateTime = LocalDateTime.now(); Integer age = currentDateTime.getYear() - Integer.parseInt(this.year) + 1; return age; } + + public void update(String year){ + this.year = year; + } } diff --git a/src/main/java/com/moddy/server/domain/model/repository/ModelJpaRepository.java b/src/main/java/com/moddy/server/domain/model/repository/ModelJpaRepository.java index 56859c85..81b9fc4d 100644 --- a/src/main/java/com/moddy/server/domain/model/repository/ModelJpaRepository.java +++ b/src/main/java/com/moddy/server/domain/model/repository/ModelJpaRepository.java @@ -7,7 +7,6 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import java.util.Optional; @Repository public interface ModelJpaRepository extends JpaRepository { @@ -15,6 +14,6 @@ public interface ModelJpaRepository extends JpaRepository { @Modifying(clearAutomatically = true) @Query(value = "insert into model (id, year) VALUES (:id, :year)", nativeQuery = true) void modelRegister(@Param("id") Long id, @Param("year") String year); - + } diff --git a/src/main/java/com/moddy/server/domain/prefer_region/PreferRegion.java b/src/main/java/com/moddy/server/domain/prefer_region/PreferRegion.java index dde72080..8db465ad 100644 --- a/src/main/java/com/moddy/server/domain/prefer_region/PreferRegion.java +++ b/src/main/java/com/moddy/server/domain/prefer_region/PreferRegion.java @@ -3,7 +3,6 @@ import com.moddy.server.domain.BaseTimeEntity; import com.moddy.server.domain.model.Model; import com.moddy.server.domain.region.Region; -import com.moddy.server.domain.user.User; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; @@ -15,7 +14,6 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; @Entity @Getter diff --git a/src/main/java/com/moddy/server/service/model/ModelRegisterService.java b/src/main/java/com/moddy/server/service/model/ModelRegisterService.java index 4419f9f7..e706b6f7 100644 --- a/src/main/java/com/moddy/server/service/model/ModelRegisterService.java +++ b/src/main/java/com/moddy/server/service/model/ModelRegisterService.java @@ -5,6 +5,7 @@ import com.moddy.server.common.exception.model.NotFoundException; import com.moddy.server.controller.designer.dto.response.UserCreateResponse; import com.moddy.server.controller.model.dto.request.ModelCreateRequest; +import com.moddy.server.controller.model.dto.request.ModelUpdateRequest; import com.moddy.server.controller.user.dto.request.UserUpdateDto; import com.moddy.server.domain.model.Model; import com.moddy.server.domain.model.repository.ModelJpaRepository; @@ -45,6 +46,18 @@ public UserCreateResponse createModel(final Long userId, ModelCreateRequest requ return authService.createUserToken(userId.toString()); } + @Transactional + public void updateModel(final Long modelId, ModelUpdateRequest modelUpdateRequest) { + Model model = modelJpaRepository.findById(modelId).orElseThrow(() -> new NotFoundException(ErrorCode.MODEL_NOT_FOUND_EXCEPTION)); + + UserUpdateDto userUpdateDto = new UserUpdateDto(modelUpdateRequest.name(), modelUpdateRequest.gender(), model.getPhoneNumber(), model.getIsMarketingAgree()); + updateUserInfos(modelId, userUpdateDto); + model.update(modelUpdateRequest.year()); + modelJpaRepository.save(model); + deleteModelPreferRegions(modelId); + createModelPreferRegions(modelId, modelUpdateRequest.preferRegions()); + } + private void updateUserInfos(final Long userId, final UserUpdateDto userUpdateDto) { final User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); user.update(userUpdateDto.name(), userUpdateDto.gender(), userUpdateDto.phoneNumber(), userUpdateDto.isMarketingAgree(), s3Service.getDefaultProfileImageUrl(), Role.MODEL);