Skip to content

Commit

Permalink
Merge pull request #139 from TEAM-MODDY/feat/#137
Browse files Browse the repository at this point in the history
#137 [feat] erd user 에서 model로 수정
  • Loading branch information
KWY0218 authored Jan 16, 2024
2 parents ec685f4 + a0deebe commit a18e0b8
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/moddy/server/domain/day_off/DayOff.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DayOff extends BaseTimeEntity {
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@JoinColumn(name = "designer_id")
@NotNull
private Designer designer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.moddy.server.domain.hair_model_application;

import com.moddy.server.domain.BaseTimeEntity;
import com.moddy.server.domain.model.Model;
import com.moddy.server.domain.user.User;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
Expand All @@ -20,9 +21,9 @@ public class HairModelApplication extends BaseTimeEntity {
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@JoinColumn(name = "model_id")
@NotNull
private User user;
private Model model;

@Enumerated(value = EnumType.STRING)
@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

@Repository
public interface HairModelApplicationJpaRepository extends JpaRepository<HairModelApplication, Long> {
Boolean existsByUserId(Long userId);
Boolean existsByModelId(Long modelId);

Optional<HairModelApplication> findByUserId(Long userId);
Optional<HairModelApplication> findByModelId(Long modelId);

Page<HairModelApplication> findAll(Pageable pageable);

List<HairModelApplication> findAllByUserId(Long userId);
List<HairModelApplication> findAllByModelId(Long modelId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.moddy.server.domain.BaseTimeEntity;
import com.moddy.server.domain.designer.Designer;
import com.moddy.server.domain.hair_model_application.HairModelApplication;
import com.moddy.server.domain.model.Model;
import com.moddy.server.domain.user.User;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
Expand All @@ -23,9 +24,9 @@ public class HairServiceOffer extends BaseTimeEntity {
private HairModelApplication hairModelApplication;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@JoinColumn(name = "model_id")
@NotNull
private User user;
private Model model;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "designer_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import java.util.Optional;

public interface HairServiceOfferJpaRepository extends JpaRepository<HairServiceOffer, Long> {
Page<HairServiceOffer> findByUserId(Long userId, Pageable pageable);
Page<HairServiceOffer> findByModelId(Long modelId, Pageable pageable);

Optional<HairServiceOffer> findByHairModelApplicationIdAndUserId(Long applicationId, Long userId);
Optional<HairServiceOffer> findByHairModelApplicationIdAndModelId(Long applicationId, Long modelId);

Boolean existsByUserId(Long userId);
Boolean existsByModelId(Long modelId);

List<HairServiceOffer> findAllByUserId(Long userId);
List<HairServiceOffer> findAllByModelId(Long modelId);

List<HairServiceOffer> findAllByDesignerId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.moddy.server.domain.prefer_region;

import com.moddy.server.domain.BaseTimeEntity;
import com.moddy.server.domain.model.Model;
import com.moddy.server.domain.region.Region;
import com.moddy.server.domain.user.User;
import jakarta.persistence.Entity;
Expand All @@ -27,9 +28,9 @@ public class PreferRegion extends BaseTimeEntity {
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@JoinColumn(name = "model_id")
@NotNull
private User user;
private Model model;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "region_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;

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

void deleteAllByModelId(Long modelId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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_offer_condition.PreferOfferCondition;
Expand Down Expand Up @@ -68,13 +67,13 @@ public class DesignerService {
private final HairServcieRecordJpaRepository hairServiceRecordJpaRepository;
private final AuthService authService;
private final PreferRegionJpaRepository preferRegionJpaRepository;
private final HairServcieRecordJpaRepository hairServcieRecordJpaRepository;
private final HairServcieRecordJpaRepository hairServcieRecordJpaRepository;
private final UserRepository userRepository;
private final HairServiceOfferJpaRepository hairServiceOfferJpaRepository;


@Transactional
public DesignerMainResponse getDesignerMainInfo(Long userId, int page, int size){
public DesignerMainResponse getDesignerMainInfo(Long userId, int page, int size) {
User user = new User();
Designer designer = designerJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND_EXCEPTION));

Expand All @@ -83,13 +82,13 @@ public DesignerMainResponse getDesignerMainInfo(Long userId, int page, int size)

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

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

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

List<String> top2hairStyles= preferHairStyle.stream().map( haireStyle -> {
return haireStyle.getHairStyle().getValue();
}).collect(Collectors.toList());
List<String> top2hairStyles = preferHairStyle.stream().map(haireStyle -> {
return haireStyle.getHairStyle().getValue();
}).collect(Collectors.toList());

HairModelApplicationResponse applicationResponse = new HairModelApplicationResponse(
application.getId(),
Expand Down Expand Up @@ -118,7 +117,7 @@ public UserCreateResponse createDesigner(Long userId, DesignerCreateRequest requ

User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND_EXCEPTION));

user.update(request.name(),request.gender(), request.phoneNumber(), request.isMarketingAgree(), profileImgUrl, Role.HAIR_DESIGNER);
user.update(request.name(), request.gender(), request.phoneNumber(), request.isMarketingAgree(), profileImgUrl, Role.HAIR_DESIGNER);

HairShop hairShop = HairShop.builder()
.name(request.hairShop().name())
Expand Down Expand Up @@ -149,7 +148,7 @@ public void postOffer(Long userId, Long applicationId, OfferCreateRequest reques
Designer designer = designerJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION));
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
HairServiceOffer offer = HairServiceOffer.builder()
.user(hairModelApplication.getUser())
.model(hairModelApplication.getModel())
.hairModelApplication(hairModelApplication)
.designer(designer)
.offerDetail(request.offerDetail())
Expand All @@ -170,12 +169,12 @@ public void postOffer(Long userId, Long applicationId, OfferCreateRequest reques
}

@Transactional
public ApplicationDetailInfoResponse getApplicationDetail(Long userId, Long applicationId){
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));
Model model = modelJpaRepository.findById(hairModelApplication.getModel().getId()).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));

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

Expand All @@ -186,16 +185,16 @@ public ApplicationDetailInfoResponse getApplicationDetail(Long userId, Long appl
List<HairServiceRecord> hairServiceRecords = hairServiceRecordJpaRepository.findAllByHairModelApplicationId(applicationId);
hairServiceRecords.sort(Comparator.comparingInt(e -> e.getServiceRecordTerm().ordinal()));

List <PreferRegion> preferRegions = preferRegionJpaRepository.findAllByUserId(model.getId());
List<PreferRegion> preferRegions = preferRegionJpaRepository.findAllByModelId(model.getId());

List<String> regionList = preferRegions.stream().map(preferregion ->{
return preferregion.getRegion().getName();
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()
HairRecordResponse hairRecordResponse = new HairRecordResponse(
records.getServiceRecordTerm().getValue(),
records.getServiceRecord().getValue()
);
return hairRecordResponse;
}).collect(Collectors.toList());
Expand Down Expand Up @@ -225,15 +224,15 @@ public ApplicationDetailInfoResponse getApplicationDetail(Long userId, Long appl
);
}

private Page<HairModelApplication> findApplicationsByPaging(int page, int size){
PageRequest pageRequest = PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC,"id"));
private Page<HairModelApplication> findApplicationsByPaging(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 Boolean getIsSendStatus(Long applicationId, Long userId){
Optional<HairServiceOffer> offer = hairServiceOfferJpaRepository.findByHairModelApplicationIdAndUserId(applicationId, userId);
private Boolean getIsSendStatus(Long applicationId, Long userId) {
Optional<HairServiceOffer> offer = hairServiceOfferJpaRepository.findByHairModelApplicationIdAndModelId(applicationId, userId);
return offer.isPresent();
}
}
52 changes: 29 additions & 23 deletions src/main/java/com/moddy/server/service/model/ModelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@

import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.NotFoundException;
import com.moddy.server.controller.designer.dto.response.UserCreateResponse;
import com.moddy.server.controller.model.dto.request.ModelApplicationRequest;
import com.moddy.server.controller.model.dto.request.ModelCreateRequest;
import com.moddy.server.controller.designer.dto.response.UserCreateResponse;
import com.moddy.server.controller.model.dto.response.*;
import com.moddy.server.controller.model.dto.response.DesignerInfoOpenChatResponse;
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.OpenChatResponse;
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;
import com.moddy.server.domain.designer.Designer;
Expand Down Expand Up @@ -70,18 +76,18 @@ public class ModelService {
private final S3Service s3Service;


public ModelMainResponse getModelMainInfo(Long userId, int page, int size){
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.existsByUserId(userId);
boolean offerStatus = hairServiceOfferJpaRepository.existsByUserId(userId);
boolean applyStatus = hairModelApplicationJpaRepository.existsByModelId(userId);
boolean offerStatus = hairServiceOfferJpaRepository.existsByModelId(userId);
ModelApplyStatus modelApplyStatus = calModelStatus(applyStatus, offerStatus);

if(modelApplyStatus != ModelApplyStatus.APPLY_AND_OFFER){
if (modelApplyStatus != ModelApplyStatus.APPLY_AND_OFFER) {
return new ModelMainResponse(
page,
size,
Expand All @@ -95,7 +101,7 @@ public ModelMainResponse getModelMainInfo(Long userId, int page, int size){
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->{
List<String> offerConditionTop2List = preferOfferCondition.stream().map(offerCondition -> {
return offerCondition.getOfferCondition().getValue();
}).collect(Collectors.toList());

Expand Down Expand Up @@ -140,22 +146,22 @@ public UserCreateResponse createModel(String baseUrl, String code, ModelCreateRe

request.preferRegions().stream().forEach(preferRegionId -> {
Region region = regionJpaRepository.findById(preferRegionId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_REGION_EXCEPTION));
PreferRegion preferRegion = PreferRegion.builder().user(model).region(region).build();
PreferRegion preferRegion = PreferRegion.builder().model(model).region(region).build();
preferRegionJpaRepository.save(preferRegion);
});

return authService.createUserToken(model.getId().toString());
}

@Transactional
public void postApplication(Long userId, ModelApplicationRequest request){
public void postApplication(Long userId, ModelApplicationRequest request) {

Model model = modelJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MODEL_INFO));
String modelImgUrl = s3Service.uploadProfileImage(request.modelImgUrl(), model.getRole());
String applicationCaptureUmgUrl = s3Service.uploadApplicationImage(request.applicationCaptureImgUrl());

HairModelApplication hairModelApplication = HairModelApplication.builder()
.user(model)
.model(model)
.hairLength(HairLength.findByHairLength(request.hairLength()))
.hairDetail(request.hairDetail())
.modelImgUrl(modelImgUrl)
Expand Down Expand Up @@ -185,7 +191,7 @@ public void postApplication(Long userId, ModelApplicationRequest request){
}

@Transactional
public DetailOfferResponse getOfferDetail(Long userId, Long offerId){
public DetailOfferResponse getOfferDetail(Long userId, Long offerId) {

HairServiceOffer hairServiceOffer = hairServiceOfferJpaRepository.findById(offerId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_OFFER_EXCEPTION));

Expand All @@ -197,7 +203,7 @@ public DetailOfferResponse getOfferDetail(Long userId, Long offerId){
}

@Transactional
public void updateOfferAgreeStatus(Long offerId){
public void updateOfferAgreeStatus(Long offerId) {
HairServiceOffer hairServiceOffer = hairServiceOfferJpaRepository.findById(offerId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_OFFER_EXCEPTION));

hairServiceOffer.setIsModelAgree(true);
Expand Down Expand Up @@ -225,7 +231,7 @@ public OpenChatResponse getOpenChatInfo(Long userId, Long offerId) {
return openChatResponse;
}

private DesignerInfoResponse getDesignerInfoResponse(HairServiceOffer hairServiceOffer, Long userId, Long offerId){
private DesignerInfoResponse getDesignerInfoResponse(HairServiceOffer hairServiceOffer, Long userId, Long offerId) {

Designer designer = designerJpaRepository.findById(hairServiceOffer.getDesigner().getId()).orElseThrow(() -> new NotFoundException(ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION));

Expand All @@ -247,7 +253,7 @@ private DesignerInfoResponse getDesignerInfoResponse(HairServiceOffer hairServic
designer.getHairShop().getDetailAddress()
);

return designerInfoResponse;
return designerInfoResponse;

}

Expand All @@ -262,7 +268,7 @@ private StyleDetailResponse getStyleDetailResponse(HairServiceOffer hairServiceO

List<PreferOfferCondition> preferOfferConditionList = preferOfferConditionJpaRepository.findAllByHairServiceOfferId(offerId);
List<OfferCondition> offerConditionList = preferOfferConditionList.stream().map(PreferOfferCondition::getOfferCondition).collect(Collectors.toList());
List<Boolean> preferOfferConditionBooleanList = Arrays.stream(OfferCondition.values()).map(condition ->{
List<Boolean> preferOfferConditionBooleanList = Arrays.stream(OfferCondition.values()).map(condition -> {
if (offerConditionList.contains(condition)) return true;
else return false;
}).collect(Collectors.toList());
Expand All @@ -275,26 +281,26 @@ private StyleDetailResponse getStyleDetailResponse(HairServiceOffer hairServiceO
preferOfferConditionBooleanList
);

return styleDetailResponse;
return styleDetailResponse;
}

private void handleOfferClickStatus(HairServiceOffer hairServiceOffer){
private void handleOfferClickStatus(HairServiceOffer hairServiceOffer) {

if(!hairServiceOffer.getIsClicked()){
if (!hairServiceOffer.getIsClicked()) {
hairServiceOffer.updateClickStatus();
}
}

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.findByUserId(userId, pageRequest);
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){
private ModelApplyStatus calModelStatus(boolean apply, boolean offer) {

if(!apply && !offer) return ModelApplyStatus.NOTHING;
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);
Expand Down
Loading

0 comments on commit a18e0b8

Please sign in to comment.