Skip to content

Commit

Permalink
#224 [refactor] 디자이너 회원가입 desigerRegisterService 변경, builder 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
pkl0912 committed Jan 31, 2024
1 parent d085aa0 commit 3070cff
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.moddy.server.controller.designer.dto.request.DesignerCreateRequest;
import com.moddy.server.controller.designer.dto.response.UserCreateResponse;
import com.moddy.server.service.auth.AuthService;
import com.moddy.server.service.designer.DesignerService;
import com.moddy.server.service.designer.DesignerRegisterService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -48,7 +48,7 @@ public class AuthController {

private static final String ORIGIN = "origin";
private final AuthService authService;
private final DesignerService designerService;
private final DesignerRegisterService designerRegisterService;


@Operation(summary = "[KAKAO CODE] 로그인 API")
Expand Down Expand Up @@ -77,7 +77,7 @@ SuccessResponse<UserCreateResponse> createDesigner(
@Parameter(hidden = true) @UserId Long userId,
@RequestPart(value = "profileImg", required = false) MultipartFile profileImg,
@Valid @RequestPart("designerInfo") DesignerCreateRequest designerInfo) {
return SuccessResponse.success(SuccessCode.DESIGNER_CREATE_SUCCESS, designerService.createDesigner(userId, designerInfo, profileImg));
return SuccessResponse.success(SuccessCode.DESIGNER_CREATE_SUCCESS, designerRegisterService.createDesigner(userId, designerInfo, profileImg));
}

@Operation(summary = "인증번호 요청 API", description = "인증번호 요청 API입니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,64 @@
package com.moddy.server.service.designer;

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.request.DesignerCreateRequest;
import com.moddy.server.controller.designer.dto.response.UserCreateResponse;
import com.moddy.server.controller.user.dto.UserUpdateDto;
import com.moddy.server.domain.day_off.DayOff;
import com.moddy.server.domain.day_off.repository.DayOffJpaRepository;
import com.moddy.server.domain.designer.Designer;
import com.moddy.server.domain.designer.HairShop;
import com.moddy.server.domain.designer.Portfolio;
import com.moddy.server.domain.designer.repository.DesignerJpaRepository;
import com.moddy.server.domain.user.Role;
import com.moddy.server.domain.user.User;
import com.moddy.server.domain.user.repository.UserRepository;
import com.moddy.server.external.s3.S3Service;
import com.moddy.server.service.auth.AuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

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;

@Service
@RequiredArgsConstructor
public class DesignerRegisterService {
private final DesignerJpaRepository designerJpaRepository;
private final DayOffJpaRepository dayOffJpaRepository;
private final S3Service s3Service;
private final AuthService authService;
private final UserRepository userRepository;

@Transactional
public UserCreateResponse createDesigner(Long designerId, DesignerCreateRequest request, MultipartFile profileImg) {

String profileImgUrl = s3Service.uploadProfileImage(profileImg, Role.HAIR_DESIGNER);

User user = userRepository.findById(designerId).orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION));
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());

designerJpaRepository.designerRegister(user.getId(), hairShop.getAddress(), hairShop.getDetailAddress(), hairShop.getName(), portfolio.getInstagramUrl(), portfolio.getNaverPlaceUrl(), request.introduction(), request.kakaoOpenChatUrl());
Designer designer = designerJpaRepository.findById(user.getId()).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION));
request.dayOffs().stream()
.forEach(d -> {
DayOff dayOff = DayOff.builder()
.dayOfWeek(d)
.designer(designer)
.build();
dayOffJpaRepository.save(dayOff);

});
return authService.createUserToken(designer.getId().toString());
}
public void deleteDesignerInfo(final User designer) {
dayOffJpaRepository.deleteAllByDesignerId(designer.getId());
s3Service.deleteS3Image(designer.getProfileImgUrl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,40 +84,6 @@ public class DesignerService {
private final HairServiceOfferJpaRepository hairServiceOfferJpaRepository;
private final SmsUtil smsUtil;

@Transactional
public UserCreateResponse createDesigner(Long userId, DesignerCreateRequest request, MultipartFile profileImg) {

String profileImgUrl = s3Service.uploadProfileImage(profileImg, Role.HAIR_DESIGNER);

User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND_EXCEPTION));
if (designerJpaRepository.existsById(userId))
throw new ConflictException(ErrorCode.ALREADY_EXIST_USER_EXCEPTION);
user.update(request.name(), request.gender(), request.phoneNumber(), request.isMarketingAgree(), profileImgUrl, Role.HAIR_DESIGNER);

HairShop hairShop = HairShop.builder()
.name(request.hairShop().name())
.address(request.hairShop().address())
.detailAddress(request.hairShop().detailAddress())
.build();
Portfolio portfolio = Portfolio.builder()
.instagramUrl(request.portfolio().instagramUrl())
.naverPlaceUrl(request.portfolio().naverPlaceUrl())
.build();
designerJpaRepository.designerRegister(user.getId(), hairShop.getAddress(), hairShop.getDetailAddress(), hairShop.getName(), portfolio.getInstagramUrl(), portfolio.getNaverPlaceUrl(), request.introduction(), request.kakaoOpenChatUrl());
Designer designer = designerJpaRepository.findById(user.getId()).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION));
request.dayOffs().stream()
.forEach(d -> {
DayOff dayOff = DayOff.builder()
.dayOfWeek(d)
.designer(designer)
.build();
dayOffJpaRepository.save(dayOff);

});
return authService.createUserToken(designer.getId().toString());
}


@Transactional
public void postOffer(Long userId, Long applicationId, OfferCreateRequest request) throws IOException {
Designer designer = designerJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION));
Expand Down

0 comments on commit 3070cff

Please sign in to comment.