-
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
#200 [feat] user 컨트롤러 서비스 제거 및 devleop 적용
- Loading branch information
Showing
11 changed files
with
228 additions
and
192 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/com/moddy/server/controller/user/UserRegisterController.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.moddy.server.controller.user; | ||
|
||
import com.moddy.server.common.dto.ErrorResponse; | ||
import com.moddy.server.common.dto.SuccessNonDataResponse; | ||
import com.moddy.server.config.resolver.user.UserId; | ||
import com.moddy.server.service.user.UserRegisterService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static com.moddy.server.common.exception.enums.SuccessCode.USER_WITHDRAW_SUCCESS; | ||
|
||
@Tag(name = "User Controller", description = "유저 정보 조회 및 탈퇴 API 입니다.") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/user") | ||
public class UserRegisterController { | ||
private final UserRegisterService userRegisterService; | ||
|
||
@DeleteMapping | ||
@Operation(summary = "[JWT] 유저 탈퇴하기 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))) | ||
}) | ||
@SecurityRequirement(name = "JWT Auth") | ||
public SuccessNonDataResponse withdraw(@Parameter(hidden = true) @UserId final Long userId) { | ||
userRegisterService.withdraw(userId); | ||
return SuccessNonDataResponse.success(USER_WITHDRAW_SUCCESS); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/moddy/server/service/application/HairModelApplicationRegisterService.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.moddy.server.service.application; | ||
|
||
import com.moddy.server.domain.hair_model_application.HairModelApplication; | ||
import com.moddy.server.domain.hair_model_application.repository.HairModelApplicationJpaRepository; | ||
import com.moddy.server.domain.hair_service_record.repository.HairServiceRecordJpaRepository; | ||
import com.moddy.server.domain.prefer_hair_style.repository.PreferHairStyleJpaRepository; | ||
import com.moddy.server.external.s3.S3Service; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class HairModelApplicationRegisterService { | ||
private final S3Service s3Service; | ||
private final HairModelApplicationJpaRepository hairModelApplicationJpaRepository; | ||
private final PreferHairStyleJpaRepository preferHairStyleJpaRepository; | ||
private final HairServiceRecordJpaRepository hairServiceRecordJpaRepository; | ||
|
||
public void deleteModelApplications(final Long modelId) { | ||
List<HairModelApplication> hairModelApplications = hairModelApplicationJpaRepository.findAllByModelId(modelId); | ||
hairModelApplications.forEach(hairModelApplication -> { | ||
deleteApplicationImage(hairModelApplication); | ||
preferHairStyleJpaRepository.deleteAllByHairModelApplication(hairModelApplication); | ||
hairServiceRecordJpaRepository.deleteAllByHairModelApplication(hairModelApplication); | ||
hairModelApplicationJpaRepository.deleteById(hairModelApplication.getId()); | ||
}); | ||
} | ||
|
||
private void deleteApplicationImage(final HairModelApplication hairModelApplication) { | ||
s3Service.deleteS3Image(hairModelApplication.getApplicationCaptureUrl()); | ||
s3Service.deleteS3Image(hairModelApplication.getModelImgUrl()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.moddy.server.service.designer; | ||
|
||
import com.moddy.server.domain.day_off.repository.DayOffJpaRepository; | ||
import com.moddy.server.domain.designer.repository.DesignerJpaRepository; | ||
import com.moddy.server.domain.user.User; | ||
import com.moddy.server.external.s3.S3Service; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class DesignerRegisterService { | ||
private final DesignerJpaRepository designerJpaRepository; | ||
private final DayOffJpaRepository dayOffJpaRepository; | ||
private final S3Service s3Service; | ||
|
||
public void deleteDesignerInfo(final User designer) { | ||
dayOffJpaRepository.deleteAllByDesignerId(designer.getId()); | ||
s3Service.deleteS3Image(designer.getProfileImgUrl()); | ||
designerJpaRepository.deleteById(designer.getId()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/moddy/server/service/model/ModelRegisterService.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.moddy.server.service.model; | ||
|
||
import com.moddy.server.domain.model.repository.ModelJpaRepository; | ||
import com.moddy.server.domain.prefer_region.repository.PreferRegionJpaRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ModelRegisterService { | ||
private final PreferRegionJpaRepository preferRegionJpaRepository; | ||
private final ModelJpaRepository modelJpaRepository; | ||
|
||
public void deleteModelInfo(final Long modelId) { | ||
deleteModelPreferRegions(modelId); | ||
modelJpaRepository.deleteById(modelId); | ||
} | ||
|
||
private void deleteModelPreferRegions(final Long modelId) { | ||
preferRegionJpaRepository.deleteAllByModelId(modelId); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/moddy/server/service/offer/HairServiceOfferRegisterService.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.moddy.server.service.offer; | ||
|
||
import com.moddy.server.domain.hair_service_offer.HairServiceOffer; | ||
import com.moddy.server.domain.hair_service_offer.repository.HairServiceOfferJpaRepository; | ||
import com.moddy.server.domain.prefer_offer_condition.repository.PreferOfferConditionJpaRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class HairServiceOfferRegisterService { | ||
private final PreferOfferConditionJpaRepository preferOfferConditionJpaRepository; | ||
private final HairServiceOfferJpaRepository hairServiceOfferJpaRepository; | ||
|
||
public void deleteModelHairServiceOfferInfos(final Long modelId) { | ||
final List<HairServiceOffer> hairServiceOffers = hairServiceOfferJpaRepository.findAllByModelId(modelId); | ||
hairServiceOffers.forEach(hairServiceOffer -> { | ||
preferOfferConditionJpaRepository.deleteAllByHairServiceOffer(hairServiceOffer); | ||
hairServiceOfferJpaRepository.deleteById(hairServiceOffer.getId()); | ||
}); | ||
} | ||
|
||
public void deleteDesignerHairServiceOfferInfos(final Long designerId) { | ||
final List<HairServiceOffer> hairServiceOffers = hairServiceOfferJpaRepository.findAllByDesignerId(designerId); | ||
hairServiceOffers.forEach(hairServiceOffer -> { | ||
preferOfferConditionJpaRepository.deleteAllByHairServiceOffer(hairServiceOffer); | ||
hairServiceOfferJpaRepository.deleteById(hairServiceOffer.getId()); | ||
}); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/moddy/server/service/user/UserRegisterService.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.moddy.server.service.user; | ||
|
||
import com.moddy.server.common.exception.model.NotFoundException; | ||
import com.moddy.server.domain.user.User; | ||
import com.moddy.server.domain.user.repository.UserRepository; | ||
import com.moddy.server.service.application.HairModelApplicationRegisterService; | ||
import com.moddy.server.service.designer.DesignerRegisterService; | ||
import com.moddy.server.service.model.ModelRegisterService; | ||
import com.moddy.server.service.offer.HairServiceOfferRegisterService; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import static com.moddy.server.common.exception.enums.ErrorCode.USER_NOT_FOUND_EXCEPTION; | ||
import static com.moddy.server.domain.user.Role.MODEL; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserRegisterService { | ||
private final UserRepository userRepository; | ||
private final HairServiceOfferRegisterService hairServiceOfferRegisterService; | ||
private final HairModelApplicationRegisterService hairModelApplicationRegisterService; | ||
private final ModelRegisterService modelRegisterService; | ||
private final DesignerRegisterService designerRegisterService; | ||
|
||
@Transactional | ||
public void withdraw(final Long userId) { | ||
final User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); | ||
if (user.getRole() == MODEL) deleteModelInfos(userId); | ||
else deleteDesignerInfos(user); | ||
} | ||
|
||
private void deleteModelInfos(final Long modelId) { | ||
hairServiceOfferRegisterService.deleteModelHairServiceOfferInfos(modelId); | ||
hairModelApplicationRegisterService.deleteModelApplications(modelId); | ||
modelRegisterService.deleteModelInfo(modelId); | ||
userRepository.deleteById(modelId); | ||
} | ||
|
||
private void deleteDesignerInfos(final User designer) { | ||
hairServiceOfferRegisterService.deleteDesignerHairServiceOfferInfos(designer.getId()); | ||
designerRegisterService.deleteDesignerInfo(designer); | ||
userRepository.deleteById(designer.getId()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/moddy/server/service/user/UserRetrieveService.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.moddy.server.service.user; | ||
|
||
import com.moddy.server.common.exception.model.NotFoundException; | ||
import com.moddy.server.controller.user.dto.response.UserDetailResponseDto; | ||
import com.moddy.server.domain.user.User; | ||
import com.moddy.server.domain.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import static com.moddy.server.common.exception.enums.ErrorCode.USER_NOT_FOUND_EXCEPTION; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserRetrieveService { | ||
private final UserRepository userRepository; | ||
|
||
public UserDetailResponseDto getUserDetail(final Long userId) { | ||
final User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); | ||
return new UserDetailResponseDto(user.getId(), user.getProfileImgUrl(), user.getName(), user.getRole()); | ||
} | ||
} |
Oops, something went wrong.