Skip to content

Commit

Permalink
Merge pull request #279 from TEAM-MODDY/feat/#275
Browse files Browse the repository at this point in the history
#275 [feat] 디자이너 정보 수정하는 기능
  • Loading branch information
hellozo0 authored Apr 21, 2024
2 parents d777d44 + 9ea06da commit 519cc99
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public enum SuccessCode {
APPLICATION_DELETE_SUCCESS(HttpStatus.OK, "지원서 삭제하기 성공"),
FIND_DESIGNER_INFO_SUCCESS(HttpStatus.OK, "디자이너 정보 조회 성공"),
FIND_MODEL_INFO_SUCCESS(HttpStatus.OK, "모델 정보 조회 성공"),
MODEL_UPDATE_SUCCESS(HttpStatus.OK,"모델 정보 수정 성공");
MODEL_UPDATE_SUCCESS(HttpStatus.OK,"모델 정보 수정 성공"),
DESIGNER_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,10 +1,12 @@
package com.moddy.server.controller.designer;

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.request.DesignerCreateRequest;
import com.moddy.server.controller.designer.dto.request.DesignerUpdateRequest;
import com.moddy.server.controller.designer.dto.response.UserCreateResponse;
import com.moddy.server.service.designer.DesignerRegisterService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -19,6 +21,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -44,4 +47,21 @@ SuccessResponse<UserCreateResponse> createDesigner(
@Valid @RequestPart("designerInfo") DesignerCreateRequest designerInfo) {
return SuccessResponse.success(SuccessCode.DESIGNER_CREATE_SUCCESS, designerRegisterService.createDesigner(designerId, designerInfo, profileImg));
}

@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(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
@SecurityRequirement(name = "JWT Auth")
public SuccessNonDataResponse updateModel(
@Parameter(hidden = true) @UserId Long designerId,
@RequestPart(value = "profileImg", required = false) MultipartFile profileImg,
@RequestPart(value = "designerUpdateInfo") @Valid DesignerUpdateRequest designerUpdateInfo){
designerRegisterService.updateDesigner(designerId, profileImg, designerUpdateInfo);
return SuccessNonDataResponse.success(SuccessCode.DESIGNER_UPDATE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.moddy.server.controller.designer.dto.request;

import com.moddy.server.common.validation.unique_dayofweek.UniqueDayOfWeek;
import com.moddy.server.controller.designer.dto.HairShopDto;
import com.moddy.server.controller.designer.dto.PortfolioDto;
import com.moddy.server.domain.day_off.DayOfWeek;
import com.moddy.server.domain.designer.HairShop;
import com.moddy.server.domain.designer.Portfolio;
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.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

import java.util.List;

@NotNull
public record DesignerUpdateRequest(
@Schema(example = "introduction")
@NotNull
@Size(min = 0, max = 200, message = "introduction은 1~200 글자수 사이의 글자입니다.")
String introduction,
@Schema(example = "안현주")
@NotNull
@Size(min = 0, max = 5, message = "name은 1~5 글자수 사이의 글자입니다.")
String name,
@Schema(example = "MALE")
@NotNull
@Enumerated(EnumType.STRING)
Gender gender,
@Valid
HairShopDto hairShop,
@UniqueDayOfWeek
List<DayOfWeek> dayOffs,
@Valid
PortfolioDto portfolio,
@Schema(example = "http://.kakao")
@NotNull
String kakaoOpenChatUrl
) {
}

This file was deleted.

9 changes: 8 additions & 1 deletion src/main/java/com/moddy/server/domain/designer/Designer.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.moddy.server.domain.designer;

import com.moddy.server.controller.designer.dto.request.DesignerUpdateRequest;
import com.moddy.server.domain.user.User;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

@Entity
Expand All @@ -27,4 +27,11 @@ public class Designer extends User {

@NotNull
private String kakaoOpenChatUrl;

public void update(HairShop hairShop, Portfolio portfolio, String introduction, String kakaoOpenChatUrl){
this.hairShop = hairShop;
this.portfolio = portfolio;
this.introduction = introduction;
this.kakaoOpenChatUrl = kakaoOpenChatUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.ConflictException;
import com.moddy.server.common.exception.model.NotFoundException;
import com.moddy.server.controller.designer.dto.HairShopDto;
import com.moddy.server.controller.designer.dto.request.DesignerCreateRequest;
import com.moddy.server.controller.designer.dto.request.DesignerUpdateRequest;
import com.moddy.server.controller.designer.dto.response.UserCreateResponse;
import com.moddy.server.controller.user.dto.request.UserUpdateDto;
import com.moddy.server.domain.day_off.DayOfWeek;
import com.moddy.server.domain.day_off.DayOff;
import com.moddy.server.domain.day_off.repository.DayOffJpaRepository;
import com.moddy.server.domain.designer.Designer;
Expand All @@ -21,6 +25,8 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

import static com.moddy.server.common.exception.enums.ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION;
import static com.moddy.server.common.exception.enums.ErrorCode.USER_NOT_FOUND_EXCEPTION;

Expand All @@ -42,29 +48,51 @@ public UserCreateResponse createDesigner(final Long designerId, final DesignerCr
if (designerJpaRepository.existsById(designerId))
throw new ConflictException(ErrorCode.ALREADY_EXIST_USER_EXCEPTION);
user.update(request.name(), request.gender(), request.phoneNumber(), request.isMarketingAgree(), profileImgUrl, Role.HAIR_DESIGNER);
HairShop hairShop = new HairShop(request.hairShop().name(), request.hairShop().address(),request.hairShop().detailAddress());
Portfolio portfolio = new Portfolio(request.portfolio().instagramUrl(),request.portfolio().naverPlaceUrl());
HairShop hairShop = new HairShop(request.hairShop().name(), request.hairShop().address(), request.hairShop().detailAddress());
Portfolio portfolio = new Portfolio(request.portfolio().instagramUrl(), request.portfolio().naverPlaceUrl());

designerJpaRepository.designerRegister(user.getId(), hairShop.getAddress(), hairShop.getDetailAddress(), hairShop.getName(), portfolio.getInstagramUrl(), portfolio.getNaverPlaceUrl(), request.introduction(), request.kakaoOpenChatUrl());
createDesignerDayoffs(designerId,request);
createDesignerDayoffs(designerId, request.dayOffs());
return authService.createUserToken(designerId.toString());
}

@Transactional
public void updateDesigner(final Long designerId, final MultipartFile profileImg, final DesignerUpdateRequest designerUpdateRequest) {
Designer designer = designerJpaRepository.findById(designerId).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION));
s3Service.deleteS3Image(designer.getProfileImgUrl());
String updatedProfileImgUrl = s3Service.uploadProfileImage(profileImg, Role.HAIR_DESIGNER);

updateUserInfos(designerId, new UserUpdateDto(designerUpdateRequest.name(), designerUpdateRequest.gender(), designer.getPhoneNumber(), designer.getIsMarketingAgree()), updatedProfileImgUrl);
designer.update(new HairShop(designerUpdateRequest.hairShop().name(), designerUpdateRequest.hairShop().address(), designerUpdateRequest.hairShop().detailAddress()), new Portfolio(designerUpdateRequest.portfolio().instagramUrl(), designer.getPortfolio().getNaverPlaceUrl()), designerUpdateRequest.introduction(), designerUpdateRequest.kakaoOpenChatUrl());
designerJpaRepository.save(designer);
deleteDesignerDayoffs(designerId);
createDesignerDayoffs(designerId, designerUpdateRequest.dayOffs());
}

public void deleteDesignerInfo(final User designer) {
dayOffJpaRepository.deleteAllByDesignerId(designer.getId());
deleteDesignerDayoffs(designer.getId());
s3Service.deleteS3Image(designer.getProfileImgUrl());
designerJpaRepository.deleteById(designer.getId());
}

private void createDesignerDayoffs(final Long designerId, final DesignerCreateRequest request){
Designer designer = designerJpaRepository.findById(designerId).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION));
request.dayOffs().stream()
.forEach(d -> {
DayOff dayOff = DayOff.builder()
.dayOfWeek(d)
.designer(designer)
.build();
dayOffJpaRepository.save(dayOff);
private void updateUserInfos(final Long userId, final UserUpdateDto userUpdateDto, final String profilImgUrl) {
final User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION));
user.update(userUpdateDto.name(), userUpdateDto.gender(), userUpdateDto.phoneNumber(), userUpdateDto.isMarketingAgree(), profilImgUrl, Role.HAIR_DESIGNER);
}

});
private void deleteDesignerDayoffs(final Long designerId) {
dayOffJpaRepository.deleteAllByDesignerId(designerId);
}

private void createDesignerDayoffs(final Long designerId, final List<DayOfWeek> dayOffs) {
Designer designer = designerJpaRepository.findById(designerId).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION));
dayOffs.forEach(dayOffId -> {
DayOff dayOff = DayOff.builder()
.dayOfWeek(dayOffId)
.designer(designer)
.build();
dayOffJpaRepository.save(dayOff);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public UserCreateResponse createModel(final Long userId, ModelCreateRequest requ
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);
updateUserInfos(modelId, new UserUpdateDto(modelUpdateRequest.name(), modelUpdateRequest.gender(), model.getPhoneNumber(), model.getIsMarketingAgree()));
model.update(modelUpdateRequest.year());
modelJpaRepository.save(model);
deleteModelPreferRegions(modelId);
Expand Down

0 comments on commit 519cc99

Please sign in to comment.