Skip to content

Commit

Permalink
#274 [feat] 모델 정보 수정 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
hellozo0 committed Apr 21, 2024
1 parent 8299976 commit 7559c9f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -44,4 +47,21 @@ public SuccessResponse<UserCreateResponse> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7559c9f

Please sign in to comment.