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

#90 [feat] 모델 지원서 상세보기 기능 구현 #93

Merged
merged 7 commits into from
Jan 11, 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 @@ -13,6 +13,7 @@ public enum SuccessCode {
MODEL_CREATE_SUCCESS(HttpStatus.OK, "모델 회원가입 성공"),
SOCIAL_LOGIN_SUCCESS(HttpStatus.OK, "카카오 로그인 성공입니다."),
FIND_MODEL_MAIN_INFO_SUCCESS(HttpStatus.OK, "모델 메인 뷰 조회 성공"),
MODEL_APPLICATION_DETAil_INFO_SUCCESS(HttpStatus.OK, "지원서 가져오기 성공"),
FIND_MODEL_DETAIL_OFFER_SUCCESS(HttpStatus.OK, "제안서 조회 성공"),
OPEN_CHAT_GET_SUCCESS(HttpStatus.OK, "오픈채팅방 연결 성공"),
USER_MY_PAGE_SUCCESS(HttpStatus.OK, "마이페이지 유저 정보 조회 성공입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.ApplicationDetailInfoResponse;
import com.moddy.server.controller.designer.dto.response.DesignerMainResponse;
import com.moddy.server.service.designer.DesignerService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -15,10 +16,7 @@
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;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/designer")
Expand All @@ -28,7 +26,7 @@ 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 = "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))),
})
Expand All @@ -41,4 +39,20 @@ public SuccessResponse<DesignerMainResponse> getDesignerMainInfo(
){
return SuccessResponse.success(SuccessCode.FIND_DESIGNER_MAIN_INFO_SUCCESS, designerService.getDesignerMainView(userId, page, size));
}

@Operation(summary = "[JWT] 모델 지원서 상세 조회", description = "모델 지원서 상세 조회 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모델 지원서 상세 조회 성공", content = @Content(schema = @Schema(implementation = ApplicationDetailInfoResponse.class))),
@ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
Copy link
Member

Choose a reason for hiding this comment

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

p3:
여기에 applicationId가 잘못왔을 때에 대한 404 에러도 있어야할것 같아요

@ApiResponse(responseCode = "404", description = "제안서 아이디가 존재하지 않습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@GetMapping("/{applicationId}")
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<ApplicationDetailInfoResponse> getApplicationDetailInfo(
@Parameter(hidden = true) @UserId Long userId,
@PathVariable(value = "applicationId") Long applicationId
){
return SuccessResponse.success(SuccessCode.MODEL_APPLICATION_DETAil_INFO_SUCCESS, designerService.getApplicationDetail(userId, applicationId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.moddy.server.controller.designer.dto.response;

public record ApplicationDetailInfoResponse(
ApplicationInfoResponse applicationInfo,
ModelInfoResponse modelInfo
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.moddy.server.controller.designer.dto.response;

import com.moddy.server.domain.hair_model_application.HairLength;
import com.moddy.server.domain.prefer_hair_style.HairStyle;

import java.util.List;

public record ApplicationInfoResponse(
Long applicationId,
String modelImgUrl,
HairLength hairLength,
List<String> preferHairstyles,
List<HairRecordResponse> hairServiceRecords,
String hairDetail,
Boolean isSend
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.moddy.server.controller.designer.dto.response;

public record HairRecordResponse(
String hairServiceTerm,
String hairService
) {
}
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.user.Gender;

import java.util.List;

public record ModelInfoResponse(
Long modelId,
String name,
Integer age,
String gender,
List<String> preferRegions,
String instagramId

) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.moddy.server.controller.model.dto.response;

import com.moddy.server.domain.hair_model_application.HairLength;
import com.moddy.server.domain.prefer_hair_style.HairStyle;

import java.util.List;

public record ApplicationDetailResponse(
Long applicationId,
String modelImgUrl,
HairLength hairLength,
List<HairStyle> preferHairStyles

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public record OpenChatResponse(
String applicationImgUrl,
String kakaoUrl,
DesignerInfoOpenChatResponse designerInfoOpenChatResponse
DesignerInfoOpenChatResponse designerInfo
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum DayOfWeek {
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static DayOfWeek findByDayOfWeek(String dayOfWeek) {
return Stream.of(DayOfWeek.values())
.filter(c -> c.getValue().equals(dayOfWeek))
.filter(c -> c.name().equals(dayOfWeek))
.findFirst()
.orElseThrow(() -> new BadRequestException(ErrorCode.INVALID_DAY_OF_WEEK_EXCEPTION));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.moddy.server.domain.hair_model_application.HairModelApplication;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;

@Entity
@Getter
public class HairServiceRecord extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.moddy.server.domain.hair_service_record.repository;

import com.moddy.server.domain.hair_service_record.HairServiceRecord;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface HairServcieRecordJpaRepository extends JpaRepository<HairServiceRecord, Long> {
List<HairServiceRecord> findAllByHairModelApplicationId(Long applicationId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.moddy.server.domain.prefer_region.PreferRegion;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface PreferRegionJpaRepository extends JpaRepository<PreferRegion, Long> {
List<PreferRegion> findAllByUserId(Long userId);

}
2 changes: 1 addition & 1 deletion src/main/java/com/moddy/server/domain/user/Gender.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum Gender {
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static Gender findByGender(String gender) {
return Stream.of(Gender.values())
.filter(c -> c.getValue().equals(gender))
.filter(c -> c.name().equals(gender))
.findFirst()
.orElseThrow(() -> new BadRequestException(ErrorCode.INVALID_GENDER_EXCEPTION));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
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.controller.designer.dto.response.*;
import com.moddy.server.domain.day_off.DayOff;
import com.moddy.server.domain.day_off.repository.DayOffJpaRepository;
import com.moddy.server.domain.designer.Designer;
Expand All @@ -16,11 +13,15 @@
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.hair_service_record.HairServiceRecord;
import com.moddy.server.domain.hair_service_record.repository.HairServcieRecordJpaRepository;
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.prefer_region.PreferRegion;
import com.moddy.server.domain.prefer_region.repository.PreferRegionJpaRepository;
import com.moddy.server.domain.user.Role;
import com.moddy.server.domain.user.User;
import com.moddy.server.external.kakao.feign.KakaoApiClient;
Expand All @@ -35,6 +36,7 @@
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -53,14 +55,17 @@ public class DesignerService {
private final HairModelApplicationJpaRepository hairModelApplicationJpaRepository;
private final PreferHairStyleJpaRepository preferHairStyleJpaRepository;
private final ModelJpaRepository modelJpaRepository;
private final HairServcieRecordJpaRepository hairServiceRecordJpaRepository;
private final AuthService authService;
private final PreferRegionJpaRepository preferRegionJpaRepository;
private final HairServcieRecordJpaRepository hairServcieRecordJpaRepository;

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 @@ -136,4 +141,60 @@ public DesignerMainResponse getDesignerMainView(Long userId, int page, int size)
applicationResponsesList
);
}

@Transactional
public ApplicationDetailInfoResponse getApplicationDetail(Long userId, Long applicationId){
User user = new User();

HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));

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

List<PreferHairStyle> preferHairStyles = preferHairStyleJpaRepository.findAllByHairModelApplicationId(applicationId);

List<String> preferhairStyleList = preferHairStyles.stream().map(hairStyle -> {
return hairStyle.getHairStyle().getValue();
}).collect(Collectors.toList());

List<HairServiceRecord> hairServiceRecords = hairServiceRecordJpaRepository.findAllByHairModelApplicationId(applicationId);
hairServiceRecords.sort(Comparator.comparingInt(e -> e.getServiceRecordTerm().ordinal()));

List <PreferRegion> preferRegions = preferRegionJpaRepository.findAllByUserId(userId);

List<String> regionList = preferRegions.stream().map(preferregion ->{
return preferregion.getRegion().getName();
}).collect(Collectors.toList());

List<HairRecordResponse> recordResponseList = hairServiceRecords.stream().map(records -> {
HairRecordResponse hairRecordResponse = new HairRecordResponse(
records.getServiceRecordTerm().getValue(),
records.getServiceRecord().getValue()
);
return hairRecordResponse;
}).collect(Collectors.toList());

ApplicationInfoResponse applicationInfoResponse = new ApplicationInfoResponse(
applicationId,
hairModelApplication.getModelImgUrl(),
hairModelApplication.getHairLength(),
preferhairStyleList,
recordResponseList,
hairModelApplication.getHairDetail(),
hairModelApplication.getIsSend()
);

ModelInfoResponse modelInfoResponse = new ModelInfoResponse(
model.getId(),
model.getName(),
user.getAge(model.getYear()),
model.getGender().getValue(),
regionList,
hairModelApplication.getInstagramId()
);

return new ApplicationDetailInfoResponse(
applicationInfoResponse,
modelInfoResponse
);
}
}