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

#71 [feat] 디자이너 메인 뷰 기능 구현 #88

Merged
merged 16 commits into from
Jan 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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, "해당 자원을 찾을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "모델 메인 뷰 조회 성공"),
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
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
@RequestMapping("/designer")
@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<DesignerMainResponse> 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));
}
}
Original file line number Diff line number Diff line change
@@ -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<HairModelApplicationResponse> hairModelApplications
) {
}
Original file line number Diff line number Diff line change
@@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p1
enum 클래스 내부에 있는 함수 때문에 Gender enum 을 그대로 사용해도 잘 들어옵니다!

List<HairStyle> preferHairStyles
) {
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,4 +11,5 @@
public interface HairModelApplicationJpaRepository extends JpaRepository<HairModelApplication, Long> {
Boolean existsByUserId(Long userId);
Optional<HairModelApplication> findByUserId(Long userId);
Page<HairModelApplication> findAll(Pageable pageable);
}
4 changes: 2 additions & 2 deletions src/main/java/com/moddy/server/domain/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<User, Long> {
Optional<User> findById(Long userId);
public interface ModelJpaRepository extends JpaRepository<Model, Long> {
Optional<Model> findById(Long userId);

}

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
@Repository
public interface PreferHairStyleJpaRepository extends JpaRepository<PreferHairStyle, Long> {

List<PreferHairStyle> findTop2ByHairModelApplicationId(Long applicationId);
List<PreferHairStyle> findAllByHairModelApplicationId(Long applicationId);
}
9 changes: 9 additions & 0 deletions src/main/java/com/moddy/server/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import lombok.Getter;
import lombok.experimental.SuperBuilder;

import java.time.LocalDateTime;

@Entity
@Getter
@SuperBuilder
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
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;
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.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;
import com.moddy.server.external.s3.S3Service;
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
Expand All @@ -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<HairModelApplication> findApplications(int page, int size){
PageRequest pageRequest = PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC,"id"));
Page<HairModelApplication> applicationPage = hairModelApplicationJpaRepository.findAll(pageRequest);
return applicationPage;
}

private final AuthService authService;
@Transactional
public UserCreateResponse createDesigner(String baseUrl, String code, DesignerCreateRequest request) {

Expand Down Expand Up @@ -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<HairModelApplication> applicationPage = findApplications(page, size);

List<HairModelApplicationResponse> applicationResponsesList = applicationPage.stream().map(application -> {

Model model = modelJpaRepository.findById(application.getUser().getId()).orElseThrow(() -> new NotFoundException(ErrorCode.MODEL_NOT_FOUND_EXCEPTION));

List<PreferHairStyle> preferHairStyle = preferHairStyleJpaRepository.findTop2ByHairModelApplicationId(application.getId());

List<HairStyle> 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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
import java.util.List;
import java.util.stream.Collectors;



@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand Down