Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#218 [Refactor] 모델 회원가입 시 지역 조회 하는 API Controller, Service 분리 #222

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions src/main/java/com/moddy/server/controller/auth/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
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.common.util.SmsUtil;
import com.moddy.server.config.resolver.kakao.KakaoCode;
import com.moddy.server.config.resolver.user.UserId;
import com.moddy.server.controller.auth.dto.request.PhoneNumberRequestDto;
import com.moddy.server.controller.auth.dto.request.VerifyCodeRequestDto;
import com.moddy.server.controller.auth.dto.response.LoginResponseDto;
import com.moddy.server.controller.auth.dto.response.RegionResponse;
import com.moddy.server.controller.designer.dto.request.DesignerCreateRequest;
import com.moddy.server.controller.designer.dto.response.UserCreateResponse;
import com.moddy.server.controller.model.dto.request.ModelCreateRequest;
Expand All @@ -30,7 +28,6 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -39,7 +36,6 @@
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

import static com.moddy.server.common.exception.enums.SuccessCode.LOGOUT_SUCCESS;
import static com.moddy.server.common.exception.enums.SuccessCode.SEND_VERIFICATION_CODE_SUCCESS;
Expand All @@ -56,7 +52,6 @@ public class AuthController {
private final AuthService authService;
private final DesignerService designerService;
private final ModelService modelService;
private final SmsUtil smsUtil;

@Operation(summary = "[KAKAO CODE] 로그인 API")
@ApiResponses(value = {
Expand All @@ -73,16 +68,6 @@ public SuccessResponse<LoginResponseDto> login(
return SuccessResponse.success(SOCIAL_LOGIN_SUCCESS, authService.login(request.getHeader(ORIGIN), kakaoCode));
}

@Operation(summary = "모델 회원가입 시 희망 지역 리스트 조회 API")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "희망 지역 리스트 조회 성공입니다."),
@ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping("/regions")
public SuccessResponse<List<RegionResponse>> getRegionList() {
return SuccessResponse.success(SuccessCode.FIND_REGION_LIST_SUCCESS, authService.getRegionList());
}

@Operation(summary = "[JWT] 디자이너 회원가입 API", description = "디자이너 회원가입 조회 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "디자이너 회원가입 성공", content = @Content(schema = @Schema(implementation = UserCreateResponse.class))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
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.auth.dto.response.RegionResponse;
import com.moddy.server.controller.model.dto.request.ModelApplicationRequest;
import com.moddy.server.controller.model.dto.response.ApplicationUserDetailResponse;
import com.moddy.server.controller.model.dto.response.DetailOfferResponse;
import com.moddy.server.controller.model.dto.response.ModelMainResponse;
import com.moddy.server.controller.model.dto.response.OpenChatResponse;
import com.moddy.server.service.model.ModelRetrieveService;
import com.moddy.server.service.model.ModelService;
import com.moddy.server.service.offer.HairServiceOfferRetrieveService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -33,22 +35,35 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@Tag(name = "ModelController")
@RequestMapping("/model")
@RequiredArgsConstructor
public class ModelController {

private final ModelService modelService;
private final HairServiceOfferRetrieveService hairServiceOfferRetrieveService;
private final ModelRetrieveService modelRetrieveService;

@Tag(name = "Auth Controller")
@Operation(summary = "모델 회원가입 시 희망 지역 리스트 조회 API")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "희망 지역 리스트 조회 성공입니다."),
@ApiResponse(responseCode = "500", description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping("/auth/regions")
public SuccessResponse<List<RegionResponse>> getRegionList() {
return SuccessResponse.success(SuccessCode.FIND_REGION_LIST_SUCCESS, modelRetrieveService.getRegionList());
}

@Tag(name = "ModelController")
@Operation(summary = "[JWT] 모델 메인 뷰 조회", description = "모델 메인 뷰 조회 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모델 메인뷰 조회 성공", content = @Content(schema = @Schema(implementation = ModelMainResponse.class))),
@ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@GetMapping
@GetMapping("/model")
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<ModelMainResponse> getModelMainInfo(
@Parameter(hidden = true) @UserId Long userId,
Expand All @@ -57,43 +72,46 @@ public SuccessResponse<ModelMainResponse> getModelMainInfo(
return SuccessResponse.success(SuccessCode.FIND_MODEL_MAIN_INFO_SUCCESS, modelService.getModelMainInfo(userId, page, size));
}

@Tag(name = "ModelController")
@Operation(summary = "[JWT] 제안서 상세보기 뷰 조회", description = "제안서 상세보기 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "제안서 상세보기 조회 성공", content = @Content(schema = @Schema(implementation = DetailOfferResponse.class))),
@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))),
})
@GetMapping("/offer/{offerId}")
@GetMapping("/model/offer/{offerId}")
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<DetailOfferResponse> getModelDetailOfferInfo(
@Parameter(hidden = true) @UserId Long userId,
@Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId) {
return SuccessResponse.success(SuccessCode.FIND_MODEL_DETAIL_OFFER_SUCCESS, modelService.getOfferDetail(userId, offerId));
}

@Tag(name = "ModelController")
@Operation(summary = "[JWT] 카카오톡 오픈채팅", description = "지원서 캡처 이미지 및 디자이너 정보 조회입니다")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모델 메인뷰 조회 성공", content = @Content(schema = @Schema(implementation = OpenChatResponse.class))),
@ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@GetMapping("/{offerId}/agree")
@GetMapping("/model/{offerId}/agree")
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<OpenChatResponse> getOpenChat(
@Parameter(hidden = true) @UserId Long userId,
@Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId) {
return SuccessResponse.success(SuccessCode.OPEN_CHAT_GET_SUCCESS, hairServiceOfferRetrieveService.getOpenChatInfo(userId, offerId));
}

@Tag(name = "ModelController")
@Operation(summary = "[JWT] 디자이너 제안서 승낙하기", description = "디자이너 제안서 승낙하기 API입니다.")
@ApiResponses({
@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("/offer/{offerId}")
@PutMapping("/model/offer/{offerId}")
@SecurityRequirement(name = "JWT Auth")
public SuccessNonDataResponse acceptOffer(
@Parameter(hidden = true) @UserId Long userId,
Expand All @@ -102,14 +120,15 @@ public SuccessNonDataResponse acceptOffer(
return SuccessNonDataResponse.success(SuccessCode.OFFER_ACCEPT_SUCCESS);
}

@Tag(name = "ModelController")
@Operation(summary = "[JWT] 모델 지원서 작성", description = "모델 지원서 작성 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모델 지원서 작성 성공"),
@ApiResponse(responseCode = "400", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@SecurityRequirement(name = "JWT Auth")
@PostMapping(value = "/application", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
@PostMapping(value = "/model/application", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public SuccessNonDataResponse submitModelApplication(
@Parameter(hidden = true) @UserId Long userId,
@RequestPart(value = "modelImgUrl", required = false) MultipartFile modelImgUrl,
Expand All @@ -119,6 +138,7 @@ public SuccessNonDataResponse submitModelApplication(
return SuccessNonDataResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS);
}

@Tag(name = "ModelController")
@Operation(summary = "[JWT] 모델 지원서 최종 확인 시 유저 정보 조회 API", description = "[모델 뷰] 모델 지원서 최종 확인 시 유저 정보 조회 API 입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모델 지원서 작성 성공"),
Expand All @@ -127,7 +147,7 @@ public SuccessNonDataResponse submitModelApplication(
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@SecurityRequirement(name = "JWT Auth")
@GetMapping(value = "/application/user")
@GetMapping(value = "/model/application/user")
public SuccessResponse<ApplicationUserDetailResponse> getUserDetailInApplication(@Parameter(hidden = true) @UserId Long userId) {
return SuccessResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS, modelService.getUserDetailInApplication(userId));
}
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/com/moddy/server/service/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import com.moddy.server.common.util.VerificationCodeGenerator;
import com.moddy.server.config.jwt.JwtService;
import com.moddy.server.controller.auth.dto.response.LoginResponseDto;
import com.moddy.server.controller.auth.dto.response.RegionResponse;
import com.moddy.server.controller.designer.dto.response.UserCreateResponse;
import com.moddy.server.domain.region.repository.RegionJpaRepository;
import com.moddy.server.domain.user.User;
import com.moddy.server.domain.user.repository.UserRepository;
import com.moddy.server.external.kakao.service.KakaoSocialService;
Expand All @@ -19,9 +17,7 @@
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static com.moddy.server.common.exception.enums.ErrorCode.INVALID_PHONE_NUMBER_EXCEPTION;
import static com.moddy.server.common.exception.enums.ErrorCode.NOT_FOUND_VERIFICATION_CODE_EXCEPTION;
Expand All @@ -36,7 +32,6 @@ public class AuthService {
private final JwtService jwtService;
private final KakaoSocialService kakaoSocialService;
private final UserRepository userRepository;
private final RegionJpaRepository regionJpaRepository;

public LoginResponseDto login(final String baseUrl, final String kakaoCode) {
String kakaoId = kakaoSocialService.getIdFromKakao(baseUrl, kakaoCode);
Expand All @@ -57,19 +52,6 @@ public LoginResponseDto login(final String baseUrl, final String kakaoCode) {
return new LoginResponseDto(tokenPair.accessToken(), tokenPair.refreshToken(), user.get().getRole().name());
}

public List<RegionResponse> getRegionList() {

List<RegionResponse> regionResponseList = regionJpaRepository.findAll().stream().map(region -> {
RegionResponse regionResponse = new RegionResponse(
region.getId(),
region.getName()
);
return regionResponse;
}).collect(Collectors.toList());

return regionResponseList;
}

public UserCreateResponse createUserToken(String useId) {

TokenPair tokenPair = jwtService.generateTokenPair(useId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,36 @@

import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.NotFoundException;
import com.moddy.server.controller.auth.dto.response.RegionResponse;
import com.moddy.server.controller.model.dto.ApplicationModelInfoDto;
import com.moddy.server.domain.model.Model;
import com.moddy.server.domain.model.repository.ModelJpaRepository;
import com.moddy.server.domain.region.repository.RegionJpaRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ModelRetrieveService {
private final ModelJpaRepository modelJpaRepository;
private final RegionJpaRepository regionJpaRepository;

public ApplicationModelInfoDto getApplicationModelInfo(final Long modelId){
public ApplicationModelInfoDto getApplicationModelInfo(final Long modelId) {
Model model = modelJpaRepository.findById(modelId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MODEL_INFO));
return new ApplicationModelInfoDto(model.getName(),model.getAge(), model.getGender().getValue());
return new ApplicationModelInfoDto(model.getName(), model.getAge(), model.getGender().getValue());
}

public List<RegionResponse> getRegionList() {
List<RegionResponse> regionResponseList = regionJpaRepository.findAll().stream().map(region -> {
RegionResponse regionResponse = new RegionResponse(region.getId(), region.getName());
return regionResponse;
}).collect(Collectors.toList());

return regionResponseList;
}
}
Loading