Skip to content

Commit

Permalink
Merge pull request #209 from TEAM-MODDY/feat/#198
Browse files Browse the repository at this point in the history
#200 [feat] user 컨트롤러 서비스 제거 및 devleop 적용
  • Loading branch information
KWY0218 authored Jan 30, 2024
2 parents c12ec0d + 2dc81cc commit e1cb95a
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 192 deletions.
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.moddy.server.controller.user;

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.config.resolver.user.UserId;
import com.moddy.server.controller.user.dto.response.UserDetailResponseDto;
import com.moddy.server.service.user.UserService;
import com.moddy.server.service.user.UserRetrieveService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -15,20 +14,18 @@
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.moddy.server.common.exception.enums.SuccessCode.USER_MY_PAGE_SUCCESS;
import static com.moddy.server.common.exception.enums.SuccessCode.USER_WITHDRAW_SUCCESS;

@Tag(name = "User Controller", description = "유저 정보 조회 및 탈퇴 API 입니다.")
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {
private final UserService userService;
@Tag(name = "User Controller", description = "유저 정보 조회 및 탈퇴 API 입니다.")
@RequestMapping("/user")
public class UserRetrieveController {
private final UserRetrieveService userRetrieveService;

@GetMapping
@Operation(summary = "[JWT] 유저 마이페이지 조회 API")
Expand All @@ -39,21 +36,7 @@ public class UserController {
@ApiResponse(responseCode = "500", description = "서버 내부 오류입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<UserDetailResponseDto> getUserDetail(@Parameter(hidden = true) @UserId Long userId) {
return SuccessResponse.success(USER_MY_PAGE_SUCCESS, userService.getUserDetail(userId));
}

@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 Long userId) {
userService.withdraw(userId);
return SuccessNonDataResponse.success(USER_WITHDRAW_SUCCESS);
public SuccessResponse<UserDetailResponseDto> getUserDetail(@Parameter(hidden = true) @UserId final Long userId) {
return SuccessResponse.success(USER_MY_PAGE_SUCCESS, userRetrieveService.getUserDetail(userId));
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/moddy/server/external/s3/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class S3Service {
private final static String APPLICATION_PATH = "APPLICATION";
private final static String MODEL_PROFILE_PATH = "HAIR_MODEL_PROFILE";
private final static String MODEL_PROFILE_IMAGE_NAME = "/model_default_profile.png";
private final static int IMAGE_URL_PREFIX_LENGTH = 54;
private final static int IMAGE_URL_PREFIX_LENGTH = 41;
private final static int EXPIRED_TIME = 3;
private final AmazonS3 amazonS3;
@Value("${cloud.aws.s3.bucket}")
Expand Down Expand Up @@ -76,7 +76,7 @@ private String uploadImage(MultipartFile multipartFile, String path) {
}

private String getImageUrlToKey(final String imageUrl) {
return imageUrl.substring(IMAGE_URL_PREFIX_LENGTH);
return imageUrl.substring(IMAGE_URL_PREFIX_LENGTH + bucket.length());
}

private Date getExpiredTime() {
Expand Down
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());
}
}
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());
}
}
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);
}
}
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());
});
}
}
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());
}
}
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());
}
}
Loading

0 comments on commit e1cb95a

Please sign in to comment.