Skip to content

Commit

Permalink
#230 [refactor] git conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
hellozo0 committed Feb 2, 2024
2 parents 550888d + f471d44 commit 9016aa3
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.moddy.server.controller.model.dto.request.ModelCreateRequest;
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.ModelRegisterService;
import com.moddy.server.service.model.ModelRetrieveService;
Expand All @@ -31,7 +30,6 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

Expand Down Expand Up @@ -71,22 +69,6 @@ public SuccessResponse<UserCreateResponse> createModel(
return SuccessResponse.success(SuccessCode.MODEL_CREATE_SUCCESS, modelRegisterService.createModel(userId, modelCreateRequest));
}

@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("/model")
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<ModelMainResponse> getModelMainInfo(
@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_MODEL_MAIN_INFO_SUCCESS, modelService.getModelMainInfo(userId, page, size));
}

@Tag(name = "ModelController")
@Operation(summary = "[JWT] 제안서 상세보기 뷰 조회", description = "제안서 상세보기 API입니다.")
@ApiResponses({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.moddy.server.controller.offer;

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.offer.dto.response.ModelMainOfferResponse;
import com.moddy.server.service.offer.HairServiceOfferRetrieveService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class OfferController {

private final HairServiceOfferRetrieveService hairServiceOfferRetrieveService;

@Tag(name = "ModelController")
@Operation(summary = "[JWT] 모델 메인 뷰 조회", description = "모델 메인 뷰 조회 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모델 메인뷰 조회 성공", content = @Content(schema = @Schema(implementation = ModelMainOfferResponse.class))),
@ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@GetMapping("/model")
@SecurityRequirement(name = "JWT Auth")
public SuccessResponse<ModelMainOfferResponse> getModelMainInfo(
@Parameter(hidden = true) @UserId Long modelId,
@Parameter(name = "page", description = "페이지 ") @RequestParam(value = "page") int page,
@Parameter(name = "size", description = "페이지 ") @RequestParam(value = "size") int size) {
return SuccessResponse.success(SuccessCode.FIND_MODEL_MAIN_INFO_SUCCESS, hairServiceOfferRetrieveService.getModelMainOfferInfo(modelId, page, size));
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.moddy.server.controller.model.dto.response;
package com.moddy.server.controller.offer.dto.response;

import com.moddy.server.controller.model.dto.response.OfferResponse;
import com.moddy.server.domain.model.ModelApplyStatus;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.List;

@Schema(description = "모델 메인 뷰 Response DTO")
public record ModelMainResponse(
@Schema(description = "모델 메인 뷰 제안서 Response DTO")
public record ModelMainOfferResponse(
int page,
int size,
long total,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import com.moddy.server.controller.model.dto.ApplicationModelInfoDto;
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.ModelApplyStatus;
import com.moddy.server.domain.prefer_hair_style.PreferHairStyle;
import com.moddy.server.domain.prefer_hair_style.repository.PreferHairStyleJpaRepository;
import com.moddy.server.service.designer.DesignerRetrieveService;
import com.moddy.server.service.model.ModelRetrieveService;
import com.moddy.server.service.offer.HairServiceOfferRetrieveService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -51,6 +53,11 @@ public DesignerMainResponse getDesignerMainInfo(final Long designerId, final int
applicationResponsesList
);
}

public boolean fetchModelApplyStatus(final Long modelId){
return hairModelApplicationJpaRepository.existsByModelId(modelId);
}

private Page<HairModelApplication> findApplicationsByPaging(final int page, final int size) {
PageRequest pageRequest = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "id"));
Page<HairModelApplication> applicationPage = hairModelApplicationJpaRepository.findAll(pageRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
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.ModelApplyStatus;
import com.moddy.server.domain.model.repository.ModelJpaRepository;
import com.moddy.server.domain.region.repository.RegionJpaRepository;
import com.moddy.server.service.offer.HairServiceOfferRetrieveService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -34,4 +36,9 @@ public List<RegionResponse> getRegionList() {

return regionResponseList;
}

public String getModelName(final Long modelId) {
Model model = modelJpaRepository.findById(modelId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MODEL_INFO));
return model.getName();
}
}
50 changes: 0 additions & 50 deletions src/main/java/com/moddy/server/service/model/ModelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.moddy.server.controller.model.dto.response.ApplicationUserDetailResponse;
import com.moddy.server.controller.model.dto.response.DesignerInfoResponse;
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.OfferResponse;
import com.moddy.server.controller.model.dto.response.StyleDetailResponse;
import com.moddy.server.domain.day_off.DayOff;
import com.moddy.server.domain.day_off.repository.DayOffJpaRepository;
Expand All @@ -18,23 +16,17 @@
import com.moddy.server.domain.hair_service_offer.HairServiceOffer;
import com.moddy.server.domain.hair_service_offer.repository.HairServiceOfferJpaRepository;
import com.moddy.server.domain.model.Model;
import com.moddy.server.domain.model.ModelApplyStatus;
import com.moddy.server.domain.model.repository.ModelJpaRepository;
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_offer_condition.OfferCondition;
import com.moddy.server.domain.prefer_offer_condition.PreferOfferCondition;
import com.moddy.server.domain.prefer_offer_condition.repository.PreferOfferConditionJpaRepository;
import com.moddy.server.domain.prefer_region.repository.PreferRegionJpaRepository;
import com.moddy.server.domain.user.User;
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.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -53,34 +45,6 @@ public class ModelService {
private final PreferHairStyleJpaRepository preferHairStyleJpaRepository;
private final PreferRegionJpaRepository preferRegionJpaRepository;

public ModelMainResponse getModelMainInfo(Long userId, int page, int size) {

User user = modelJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MODEL_INFO));

Page<HairServiceOffer> offerPage = findOffersByPaging(userId, page, size);
long totalElements = offerPage.getTotalElements();

boolean applyStatus = hairModelApplicationJpaRepository.existsByModelId(userId);
boolean offerStatus = hairServiceOfferJpaRepository.existsByModelId(userId);
ModelApplyStatus modelApplyStatus = calModelStatus(applyStatus, offerStatus);

if (modelApplyStatus != ModelApplyStatus.APPLY_AND_OFFER) {
return new ModelMainResponse(page, size, totalElements, modelApplyStatus, user.getName(), new ArrayList<>());
}

List<OfferResponse> offerResponseList = offerPage.stream().map(offer -> {
Designer designer = offer.getDesigner();
List<PreferOfferCondition> preferOfferCondition = preferOfferConditionJpaRepository.findTop2ByHairServiceOfferId(offer.getId());
List<String> offerConditionTop2List = preferOfferCondition.stream().map(offerCondition -> {
return offerCondition.getOfferCondition().getValue();
}).collect(Collectors.toList());

OfferResponse offerResponse = new OfferResponse(offer.getId(), designer.getProfileImgUrl(), designer.getName(), designer.getHairShop().getName(), offerConditionTop2List, offer.getIsClicked());
return offerResponse;
}).collect(Collectors.toList());

return new ModelMainResponse(page, size, totalElements, modelApplyStatus, user.getName(), offerResponseList);
}

@Transactional
public DetailOfferResponse getOfferDetail(Long userId, Long offerId) {
Expand Down Expand Up @@ -154,20 +118,6 @@ private void handleOfferClickStatus(HairServiceOffer hairServiceOffer) {
}
}

private Page<HairServiceOffer> findOffersByPaging(Long userId, int page, int size) {
PageRequest pageRequest = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "id"));
Page<HairServiceOffer> offerPage = hairServiceOfferJpaRepository.findByModelId(userId, pageRequest);

return offerPage;
}

private ModelApplyStatus calModelStatus(boolean apply, boolean offer) {

if (!apply && !offer) return ModelApplyStatus.NOTHING;
else if (apply && !offer) return ModelApplyStatus.APPLY;
else if (apply && offer) return ModelApplyStatus.APPLY_AND_OFFER;
else throw new NotFoundException(ErrorCode.NOT_FOUND_MODEL_STATUS);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,39 @@
import com.moddy.server.common.exception.model.NotFoundException;
import com.moddy.server.controller.model.dto.DesignerInfoOpenChatDto;
import com.moddy.server.controller.model.dto.response.DesignerInfoOpenChatResponse;
import com.moddy.server.controller.model.dto.response.OfferResponse;
import com.moddy.server.controller.model.dto.response.OpenChatResponse;
import com.moddy.server.controller.offer.dto.response.ModelMainOfferResponse;
import com.moddy.server.domain.designer.Designer;
import com.moddy.server.domain.hair_service_offer.HairServiceOffer;
import com.moddy.server.domain.hair_service_offer.repository.HairServiceOfferJpaRepository;
import com.moddy.server.domain.model.ModelApplyStatus;
import com.moddy.server.domain.prefer_offer_condition.PreferOfferCondition;
import com.moddy.server.domain.prefer_offer_condition.repository.PreferOfferConditionJpaRepository;
import com.moddy.server.service.application.HairModelApplicationRetrieveService;
import com.moddy.server.service.designer.DesignerRetrieveService;
import com.moddy.server.service.model.ModelRetrieveService;
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.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class HairServiceOfferRetrieveService {

private final HairServiceOfferJpaRepository hairServiceOfferJpaRepository;
private final PreferOfferConditionJpaRepository preferOfferConditionJpaRepository;
private final DesignerRetrieveService designerRetrieveService;
private final HairModelApplicationRetrieveService hairModelApplicationRetrieveService;
private final ModelRetrieveService modelRetrieveService;

public OpenChatResponse getOpenChatInfo(final Long userId, final Long offerId) {
HairServiceOffer hairServiceOffer = hairServiceOfferJpaRepository.findById(offerId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUNT_OFFER_EXCEPTION));
Expand All @@ -36,4 +52,49 @@ public OpenChatResponse getOpenChatInfo(final Long userId, final Long offerId) {

return openChatResponse;
}

public ModelMainOfferResponse getModelMainOfferInfo(final Long modelId, final int page, final int size) {
String modelName = modelRetrieveService.getModelName(modelId);

Page<HairServiceOffer> offerPage = findOffersByPaging(modelId, page, size);
long totalElements = offerPage.getTotalElements();

ModelApplyStatus modelApplyStatus = calModelApplyAndOfferStatus(modelId);
if (modelApplyStatus != ModelApplyStatus.APPLY_AND_OFFER) {
return new ModelMainOfferResponse(page, size, totalElements, modelApplyStatus, modelName, new ArrayList<>());
}
return new ModelMainOfferResponse(page, size, totalElements, modelApplyStatus, modelName, getModelMainOfferList(offerPage));
}

private ModelApplyStatus calModelApplyAndOfferStatus(final Long modelId) {
boolean applyStatus = hairModelApplicationRetrieveService.fetchModelApplyStatus(modelId);
boolean offerStatus = hairServiceOfferJpaRepository.existsByModelId(modelId);

if (!applyStatus && !offerStatus) return ModelApplyStatus.NOTHING;
else if (applyStatus && !offerStatus) return ModelApplyStatus.APPLY;
else if (applyStatus && offerStatus) return ModelApplyStatus.APPLY_AND_OFFER;
else throw new NotFoundException(ErrorCode.NOT_FOUND_MODEL_STATUS);
}

private List<OfferResponse> getModelMainOfferList(final Page<HairServiceOffer> offerPage) {
List<OfferResponse> offerResponseList = offerPage.stream().map(offer -> {
Designer designer = offer.getDesigner();
List<PreferOfferCondition> preferOfferCondition = preferOfferConditionJpaRepository.findTop2ByHairServiceOfferId(offer.getId());
List<String> offerConditionTop2List = preferOfferCondition.stream().map(offerCondition -> {
return offerCondition.getOfferCondition().getValue();
}).collect(Collectors.toList());

OfferResponse offerResponse = new OfferResponse(offer.getId(), designer.getProfileImgUrl(), designer.getName(), designer.getHairShop().getName(), offerConditionTop2List, offer.getIsClicked());
return offerResponse;
}).collect(Collectors.toList());

return offerResponseList;
}

private Page<HairServiceOffer> findOffersByPaging(final Long modelId, final int page, final int size) {
PageRequest pageRequest = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "createdAt"));
Page<HairServiceOffer> offerPage = hairServiceOfferJpaRepository.findByModelId(modelId, pageRequest);

return offerPage;
}
}

0 comments on commit 9016aa3

Please sign in to comment.