-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#224 [refactor] 디자이너 회원가입 service 분리
- Loading branch information
Showing
9 changed files
with
99 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
import lombok.*; | ||
|
||
@Embeddable | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Builder | ||
@ToString | ||
public class Portfolio { | ||
@NotNull | ||
|
48 changes: 48 additions & 0 deletions
48
src/main/java/com/moddy/server/service/designer/DesignerRegisterService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,70 @@ | ||
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.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(final Long designerId, final DesignerCreateRequest request, final 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()); | ||
createDesignerDayoffs(designerId,request); | ||
return authService.createUserToken(designerId.toString()); | ||
} | ||
public void deleteDesignerInfo(final User designer) { | ||
dayOffJpaRepository.deleteAllByDesignerId(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); | ||
|
||
}); | ||
} | ||
} |
Oops, something went wrong.