Skip to content

Commit

Permalink
Merge pull request #278 from TEAM-MODDY/feat/#274
Browse files Browse the repository at this point in the history
#274 [feat] 모델 마이페이지 수정 기능 구현
  • Loading branch information
hellozo0 authored Apr 21, 2024
2 parents 085f88e + 7559c9f commit d777d44
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Long> preferRegions
) {
}
6 changes: 5 additions & 1 deletion src/main/java/com/moddy/server/domain/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.Getter;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface ModelJpaRepository extends JpaRepository<Model, Long> {

@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);

}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +14,6 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Entity
@Getter
Expand Down
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 d777d44

Please sign in to comment.