diff --git a/src/main/java/com/moddy/server/common/exception/enums/ErrorCode.java b/src/main/java/com/moddy/server/common/exception/enums/ErrorCode.java index 449e1bed..4b2addf9 100644 --- a/src/main/java/com/moddy/server/common/exception/enums/ErrorCode.java +++ b/src/main/java/com/moddy/server/common/exception/enums/ErrorCode.java @@ -25,6 +25,7 @@ public enum ErrorCode { NOT_FOUND_PREFER_OFFER_CONDITION(HttpStatus.NOT_FOUND, "선호 제안조건을 찾을 수 없습니다."), USER_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 유저는 존재하지 않습니다."), DESIGNER_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 디자이너는 존재하지 않습니다."), + MODEL_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 모델은 존재하지 않습니다"), NOT_FOUND_OFFER_EXCEPTION(HttpStatus.NOT_FOUND, "해당 제안서를 찾을 수 없습니다."), NOT_FOUND_APPLICATION_EXCEPTION(HttpStatus.NOT_FOUND, "해당 지원서를 찾을 수 없습니다."), NOT_FOUND_RESOURCE_EXCEPTION(HttpStatus.NOT_FOUND, "해당 자원을 찾을 수 없습니다."), diff --git a/src/main/java/com/moddy/server/common/exception/enums/SuccessCode.java b/src/main/java/com/moddy/server/common/exception/enums/SuccessCode.java index de6c161b..87a16a96 100644 --- a/src/main/java/com/moddy/server/common/exception/enums/SuccessCode.java +++ b/src/main/java/com/moddy/server/common/exception/enums/SuccessCode.java @@ -9,6 +9,7 @@ public enum SuccessCode { DESIGNER_CREATE_SUCCESS(HttpStatus.OK, "디자이너 회원가입 성공"), + FIND_DESIGNER_MAIN_INFO_SUCCESS(HttpStatus.OK, "디자이너 메인 뷰 조회 성공"), MODEL_CREATE_SUCCESS(HttpStatus.OK, "모델 회원가입 성공"), SOCIAL_LOGIN_SUCCESS(HttpStatus.OK, "카카오 로그인 성공입니다."), FIND_MODEL_MAIN_INFO_SUCCESS(HttpStatus.OK, "모델 메인 뷰 조회 성공"), @@ -17,7 +18,7 @@ public enum SuccessCode { USER_MY_PAGE_SUCCESS(HttpStatus.OK, "마이페이지 유저 정보 조회 성공입니다."), OFFER_ACCEPT_SUCCESS(HttpStatus.OK, "제안서 승락 성공입니다."), FIND_REGION_LIST_SUCCESS(HttpStatus.OK, "희망 지역 리스트 조회 성공입니다."); - + private final HttpStatus httpStatus; private final String message; } diff --git a/src/main/java/com/moddy/server/controller/designer/DesignerController.java b/src/main/java/com/moddy/server/controller/designer/DesignerController.java index 65ac2a55..4d3989ad 100644 --- a/src/main/java/com/moddy/server/controller/designer/DesignerController.java +++ b/src/main/java/com/moddy/server/controller/designer/DesignerController.java @@ -1,9 +1,23 @@ package com.moddy.server.controller.designer; - +import com.moddy.server.common.dto.ErrorResponse; +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.designer.dto.response.DesignerMainResponse; +import com.moddy.server.service.designer.DesignerService; +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.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -11,4 +25,20 @@ @Tag(name = "DesignerController") @RequiredArgsConstructor public class DesignerController { + private final DesignerService designerService; + @Operation(summary = "[JWT] 디자이너 메인 뷰 조회", description = "디자이너 메인 뷰 조회 API입니다.") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "모델 메인뷰 조회 성공", content = @Content(schema = @Schema(implementation = DesignerMainResponse.class))), + @ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + }) + @GetMapping + @SecurityRequirement(name = "JWT Auth") + public SuccessResponse getDesignerMainInfo( + @Parameter(hidden = true) @UserId Long userId, + @Parameter(name = "page", description = "페이지 ") @RequestParam(value = "page") int page, + @Parameter(name = "size", description = "페이지 ") @RequestParam(value = "size") int size + ){ + return SuccessResponse.success(SuccessCode.FIND_DESIGNER_MAIN_INFO_SUCCESS, designerService.getDesignerMainView(userId, page, size)); + } } diff --git a/src/main/java/com/moddy/server/controller/designer/dto/response/DesignerMainResponse.java b/src/main/java/com/moddy/server/controller/designer/dto/response/DesignerMainResponse.java new file mode 100644 index 00000000..43855a2b --- /dev/null +++ b/src/main/java/com/moddy/server/controller/designer/dto/response/DesignerMainResponse.java @@ -0,0 +1,14 @@ +package com.moddy.server.controller.designer.dto.response; + +import io.swagger.v3.oas.annotations.media.Schema; + +import java.util.List; + +@Schema(description = "디자이너 메인 뷰 Response DTO") +public record DesignerMainResponse( + int page, + int size, + String name, + List hairModelApplications +) { +} diff --git a/src/main/java/com/moddy/server/controller/designer/dto/response/HairModelApplicationResponse.java b/src/main/java/com/moddy/server/controller/designer/dto/response/HairModelApplicationResponse.java new file mode 100644 index 00000000..8fe13d68 --- /dev/null +++ b/src/main/java/com/moddy/server/controller/designer/dto/response/HairModelApplicationResponse.java @@ -0,0 +1,16 @@ +package com.moddy.server.controller.designer.dto.response; + +import com.moddy.server.domain.prefer_hair_style.HairStyle; +import com.moddy.server.domain.user.Gender; + +import java.util.List; + +public record HairModelApplicationResponse( + Long applicationId, + String name, + int age, + String imgUrl, + String gender, + List preferHairStyles +) { +} diff --git a/src/main/java/com/moddy/server/domain/hair_model_application/repository/HairModelApplicationJpaRepository.java b/src/main/java/com/moddy/server/domain/hair_model_application/repository/HairModelApplicationJpaRepository.java index 2d123ddc..378cb48a 100644 --- a/src/main/java/com/moddy/server/domain/hair_model_application/repository/HairModelApplicationJpaRepository.java +++ b/src/main/java/com/moddy/server/domain/hair_model_application/repository/HairModelApplicationJpaRepository.java @@ -1,6 +1,8 @@ package com.moddy.server.domain.hair_model_application.repository; import com.moddy.server.domain.hair_model_application.HairModelApplication; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import java.util.Optional; @@ -9,4 +11,5 @@ public interface HairModelApplicationJpaRepository extends JpaRepository { Boolean existsByUserId(Long userId); Optional findByUserId(Long userId); + Page findAll(Pageable pageable); } diff --git a/src/main/java/com/moddy/server/domain/model/Model.java b/src/main/java/com/moddy/server/domain/model/Model.java index ed2976f4..3dc628d6 100644 --- a/src/main/java/com/moddy/server/domain/model/Model.java +++ b/src/main/java/com/moddy/server/domain/model/Model.java @@ -2,13 +2,13 @@ import com.moddy.server.domain.user.User; import jakarta.persistence.Entity; -import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -@Entity @Getter +@Entity @NoArgsConstructor @AllArgsConstructor @SuperBuilder diff --git a/src/main/java/com/moddy/server/domain/model/repository/ModelJpaRepository.java b/src/main/java/com/moddy/server/domain/model/repository/ModelJpaRepository.java index 82cee8bc..8965058e 100644 --- a/src/main/java/com/moddy/server/domain/model/repository/ModelJpaRepository.java +++ b/src/main/java/com/moddy/server/domain/model/repository/ModelJpaRepository.java @@ -1,14 +1,14 @@ package com.moddy.server.domain.model.repository; -import com.moddy.server.domain.user.User; +import com.moddy.server.domain.model.Model; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import java.util.Optional; @Repository -public interface ModelJpaRepository extends JpaRepository { - Optional findById(Long userId); +public interface ModelJpaRepository extends JpaRepository { + Optional findById(Long userId); } diff --git a/src/main/java/com/moddy/server/domain/prefer_hair_style/repository/PreferHairStyleJpaRepository.java b/src/main/java/com/moddy/server/domain/prefer_hair_style/repository/PreferHairStyleJpaRepository.java index 891a6503..567104f7 100644 --- a/src/main/java/com/moddy/server/domain/prefer_hair_style/repository/PreferHairStyleJpaRepository.java +++ b/src/main/java/com/moddy/server/domain/prefer_hair_style/repository/PreferHairStyleJpaRepository.java @@ -9,5 +9,6 @@ @Repository public interface PreferHairStyleJpaRepository extends JpaRepository { + List findTop2ByHairModelApplicationId(Long applicationId); List findAllByHairModelApplicationId(Long applicationId); } diff --git a/src/main/java/com/moddy/server/domain/user/User.java b/src/main/java/com/moddy/server/domain/user/User.java index 24ef1314..69f1ef3f 100644 --- a/src/main/java/com/moddy/server/domain/user/User.java +++ b/src/main/java/com/moddy/server/domain/user/User.java @@ -7,6 +7,8 @@ import lombok.Getter; import lombok.experimental.SuperBuilder; +import java.time.LocalDateTime; + @Entity @Getter @SuperBuilder @@ -42,4 +44,11 @@ public class User extends BaseTimeEntity { @Enumerated(EnumType.STRING) private Role role; + + public Integer getAge(String year){ + LocalDateTime currentDateTime = LocalDateTime.now(); + Integer age = currentDateTime.getYear() - Integer.parseInt(year) + 1 ; + return age; + } + } diff --git a/src/main/java/com/moddy/server/service/designer/DesignerService.java b/src/main/java/com/moddy/server/service/designer/DesignerService.java index cd3dbb8a..01f3c3ac 100644 --- a/src/main/java/com/moddy/server/service/designer/DesignerService.java +++ b/src/main/java/com/moddy/server/service/designer/DesignerService.java @@ -1,8 +1,12 @@ package com.moddy.server.service.designer; import com.moddy.server.common.dto.TokenPair; +import com.moddy.server.common.exception.enums.ErrorCode; +import com.moddy.server.common.exception.model.NotFoundException; import com.moddy.server.config.jwt.JwtService; import com.moddy.server.controller.designer.dto.request.DesignerCreateRequest; +import com.moddy.server.controller.designer.dto.response.DesignerMainResponse; +import com.moddy.server.controller.designer.dto.response.HairModelApplicationResponse; 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; @@ -10,7 +14,15 @@ 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.hair_model_application.HairModelApplication; +import com.moddy.server.domain.hair_model_application.repository.HairModelApplicationJpaRepository; +import com.moddy.server.domain.model.Model; +import com.moddy.server.domain.model.repository.ModelJpaRepository; +import com.moddy.server.domain.prefer_hair_style.HairStyle; +import com.moddy.server.domain.prefer_hair_style.PreferHairStyle; +import com.moddy.server.domain.prefer_hair_style.repository.PreferHairStyleJpaRepository; import com.moddy.server.domain.user.Role; +import com.moddy.server.domain.user.User; import com.moddy.server.external.kakao.feign.KakaoApiClient; import com.moddy.server.external.kakao.feign.KakaoAuthApiClient; import com.moddy.server.external.kakao.service.KakaoSocialService; @@ -18,8 +30,13 @@ import com.moddy.server.service.auth.AuthService; import lombok.Builder; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -33,8 +50,17 @@ public class DesignerService { private final KakaoAuthApiClient kakaoAuthApiClient; private final KakaoApiClient kakaoApiClient; private final JwtService jwtService; - private final AuthService authService; + private final HairModelApplicationJpaRepository hairModelApplicationJpaRepository; + private final PreferHairStyleJpaRepository preferHairStyleJpaRepository; + private final ModelJpaRepository modelJpaRepository; + + private Page findApplications(int page, int size){ + PageRequest pageRequest = PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC,"id")); + Page applicationPage = hairModelApplicationJpaRepository.findAll(pageRequest); + return applicationPage; + } + private final AuthService authService; @Transactional public UserCreateResponse createDesigner(String baseUrl, String code, DesignerCreateRequest request) { @@ -77,4 +103,37 @@ public UserCreateResponse createDesigner(String baseUrl, String code, DesignerCr return authService.createUserToken(designer.getId().toString()); } + + @Transactional + public DesignerMainResponse getDesignerMainView(Long userId, int page, int size){ + User user = new User(); + Designer designer = designerJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND_EXCEPTION)); + + Page applicationPage = findApplications(page, size); + + List applicationResponsesList = applicationPage.stream().map(application -> { + + Model model = modelJpaRepository.findById(application.getUser().getId()).orElseThrow(() -> new NotFoundException(ErrorCode.MODEL_NOT_FOUND_EXCEPTION)); + + List preferHairStyle = preferHairStyleJpaRepository.findTop2ByHairModelApplicationId(application.getId()); + + List top2hairStyles= preferHairStyle.stream().map(PreferHairStyle::getHairStyle).collect(Collectors.toList()); + HairModelApplicationResponse applicationResponse = new HairModelApplicationResponse( + application.getId(), + model.getName(), + user.getAge(model.getYear()), + model.getProfileImgUrl(), + model.getGender().getValue(), + top2hairStyles + ); + return applicationResponse; + }).collect(Collectors.toList()); + + return new DesignerMainResponse( + page, + size, + designer.getName(), + applicationResponsesList + ); + } } diff --git a/src/main/java/com/moddy/server/service/model/ModelService.java b/src/main/java/com/moddy/server/service/model/ModelService.java index afd158b6..c95df33d 100644 --- a/src/main/java/com/moddy/server/service/model/ModelService.java +++ b/src/main/java/com/moddy/server/service/model/ModelService.java @@ -45,8 +45,6 @@ import java.util.List; import java.util.stream.Collectors; - - @Service @RequiredArgsConstructor @Transactional(readOnly = true)