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

#226 [refactor] 제안서 작성 service 분리 #227

Merged
merged 6 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -12,6 +12,7 @@
import com.moddy.server.controller.designer.dto.response.DownloadUrlResponseDto;
import com.moddy.server.service.application.HairModelApplicationRetrieveService;
import com.moddy.server.service.designer.DesignerService;
import com.moddy.server.service.offer.HairServiceOfferRegisterService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -42,6 +43,7 @@ public class DesignerController {

private final DesignerService designerService;
private final HairModelApplicationRetrieveService hairModelApplicationRetrieveService;
private final HairServiceOfferRegisterService hairServiceOfferRegisterService;
Copy link
Member

Choose a reason for hiding this comment

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

p2
사용하지 않는 변수는 제거해주세요!


@Operation(summary = "[JWT] 디자이너 메인 뷰 조회", description = "디자이너 메인 뷰 조회 API입니다.")
@ApiResponses({
Expand All @@ -58,23 +60,6 @@ public SuccessResponse<DesignerMainResponse> getDesignerMainInfo(
return SuccessResponse.success(SuccessCode.FIND_DESIGNER_MAIN_INFO_SUCCESS, hairModelApplicationRetrieveService.getDesignerMainInfo(designerId, page, size));
}

@Operation(summary = "[JWT] 제안서 작성하기", description = "제안서 작성하기 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "제안서 작성 성공", content = @Content(schema = @Schema(implementation = SuccessNonDataResponse.class))),
@ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "404", description = "제안서가 존재하지 않습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@SecurityRequirement(name = "JWT Auth")
@PostMapping("{applicationId}/offer")
public SuccessNonDataResponse offerCreateRequest(
@Parameter(hidden = true) @UserId Long userId,
@PathVariable(value = "applicationId") Long applicationId,
@Valid @RequestBody OfferCreateRequest offerCreateRequest) throws IOException {
designerService.postOffer(userId, applicationId, offerCreateRequest);
return SuccessNonDataResponse.success(SuccessCode.POST_OFFER_SUCCESS);
}

@Operation(summary = "[JWT] 모델 지원서 상세 조회", description = "모델 지원서 상세 조회 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모델 지원서 상세 조회 성공", content = @Content(schema = @Schema(implementation = ApplicationDetailInfoResponse.class))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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.request.OfferCreateRequest;
import com.moddy.server.controller.offer.dto.response.ModelMainOfferResponse;
import com.moddy.server.controller.offer.response.DetailOfferResponse;
import com.moddy.server.service.offer.HairServiceOfferRegisterService;
Expand All @@ -17,13 +18,18 @@
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 jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.io.IOException;

@RestController
@RequiredArgsConstructor
public class OfferController {
Expand Down Expand Up @@ -79,4 +85,22 @@ public SuccessResponse<DetailOfferResponse> getModelDetailOfferInfo(
@Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId) {
return SuccessResponse.success(SuccessCode.FIND_MODEL_DETAIL_OFFER_SUCCESS, hairServiceOfferRetrieveService.getOfferDetail(modelId, offerId));
}

@Tag(name = "DesignerController")
@Operation(summary = "[JWT] 제안서 작성하기", description = "제안서 작성하기 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "제안서 작성 성공", content = @Content(schema = @Schema(implementation = SuccessNonDataResponse.class))),
@ApiResponse(responseCode = "401", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "404", description = "제안서가 존재하지 않습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@SecurityRequirement(name = "JWT Auth")
@PostMapping("/designer/{applicationId}/offer")
public SuccessNonDataResponse offerCreateRequest(
@Parameter(hidden = true) @UserId Long designerId,
@PathVariable(value = "applicationId") Long applicationId,
@Valid @RequestBody OfferCreateRequest offerCreateRequest) throws IOException {
hairServiceOfferRegisterService.postOffer(designerId, applicationId, offerCreateRequest);
return SuccessNonDataResponse.success(SuccessCode.POST_OFFER_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import jakarta.validation.constraints.NotNull;
import lombok.*;

import java.time.LocalDateTime;

@Entity
@Getter
@Builder
Expand Down Expand Up @@ -41,10 +43,20 @@ public class HairServiceOffer extends BaseTimeEntity {
@NotNull
private Boolean isClicked;

public HairServiceOffer(@NotNull HairModelApplication hairModelApplication, @NotNull Model model, @NotNull Designer designer, @NotNull String offerDetail, @NotNull Boolean isModelAgree, @NotNull Boolean isClicked) {
Copy link
Member

Choose a reason for hiding this comment

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

p3
@NotNull 과 같은 Validation 어노테이션을 도메인에 붙인 이유가 있을까요???

p2
객체타입인 Boolean 대신 원시타입인 boolean 을 사용해주세요!

this.hairModelApplication = hairModelApplication;
this.model = model;
this.designer = designer;
this.offerDetail = offerDetail;
this.isModelAgree = isModelAgree;
this.isClicked = isClicked;
}

public void agreeOfferToModel(){
this.isModelAgree = true;
}

public void updateClickStatus() { this.isClicked = true; }


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PreferOfferCondition extends BaseTimeEntity {
Expand All @@ -28,4 +27,8 @@ public class PreferOfferCondition extends BaseTimeEntity {
@NotNull
private OfferCondition offerCondition;

public PreferOfferCondition(final HairServiceOffer hairServiceOffer, final OfferCondition offerCondition){
this.hairServiceOffer = hairServiceOffer;
this.offerCondition = offerCondition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ private HairModelApplicationResponse getApplicationResponse(final HairModelAppli
return applicationResponse;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -117,39 +117,6 @@ public UserCreateResponse createDesigner(Long userId, DesignerCreateRequest requ
return authService.createUserToken(designer.getId().toString());
}


@Transactional
public void postOffer(Long userId, Long applicationId, OfferCreateRequest request) throws IOException {
Designer designer = designerJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION));
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));

if (hairServiceOfferJpaRepository.existsByHairModelApplicationIdAndDesignerId(applicationId,designer.getId())) throw new ConflictException(ErrorCode.ALREADY_EXIST_OFFER_EXCEPTION);

HairServiceOffer offer = HairServiceOffer.builder()
.model(hairModelApplication.getModel())
.hairModelApplication(hairModelApplication)
.designer(designer)
.offerDetail(request.offerDetail())
.isModelAgree(false)
.isClicked(false)
.build();
hairServiceOfferJpaRepository.save(offer);

request.preferOfferConditions().stream()
.forEach(p -> {
PreferOfferCondition preferOfferCondition = PreferOfferCondition.builder()
.offerCondition(p)
.hairServiceOffer(offer)
.build();
preferOfferConditionJpaRepository.save(preferOfferCondition);

});

final String modelName = hairModelApplication.getModel().getName();
final String modelPhoneNumber = hairModelApplication.getModel().getPhoneNumber();
smsUtil.sendOfferToModel(modelPhoneNumber, modelName);
}

@Transactional
public ApplicationDetailInfoResponse getApplicationDetail(Long userId, Long applicationId) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
package com.moddy.server.service.offer;

import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.ConflictException;
import com.moddy.server.common.exception.model.NotFoundException;
import com.moddy.server.common.util.SmsUtil;
import com.moddy.server.controller.designer.dto.request.OfferCreateRequest;
import com.moddy.server.domain.designer.Designer;
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_offer.HairServiceOffer;
import com.moddy.server.domain.hair_service_offer.repository.HairServiceOfferJpaRepository;
import com.moddy.server.domain.model.Model;
import com.moddy.server.domain.prefer_offer_condition.PreferOfferCondition;
import com.moddy.server.domain.prefer_offer_condition.repository.PreferOfferConditionJpaRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.List;

import static com.moddy.server.common.exception.enums.ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION;

@Service
@RequiredArgsConstructor
public class HairServiceOfferRegisterService {
private final PreferOfferConditionJpaRepository preferOfferConditionJpaRepository;
private final HairServiceOfferJpaRepository hairServiceOfferJpaRepository;
private final DesignerJpaRepository designerJpaRepository;
private final HairModelApplicationJpaRepository hairModelApplicationJpaRepository;
private final SmsUtil smsUtil;

public void deleteModelHairServiceOfferInfos(final Long modelId) {
final List<HairServiceOffer> hairServiceOffers = hairServiceOfferJpaRepository.findAllByModelId(modelId);
Expand All @@ -34,9 +49,35 @@ public void deleteDesignerHairServiceOfferInfos(final Long designerId) {
}

@Transactional
public void postOffer(final Long designerId, final Long applicationId, final OfferCreateRequest request) throws IOException {
Designer designer = designerJpaRepository.findById(designerId).orElseThrow(() -> new NotFoundException(DESIGNER_NOT_FOUND_EXCEPTION));
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
Model model = hairModelApplication.getModel();
if (hairServiceOfferJpaRepository.existsByHairModelApplicationIdAndDesignerId(applicationId,designer.getId())) throw new ConflictException(ErrorCode.ALREADY_EXIST_OFFER_EXCEPTION);

HairServiceOffer offer = new HairServiceOffer(hairModelApplication,model,designer, request.offerDetail(), false,false);
hairServiceOfferJpaRepository.save(offer);

request.preferOfferConditions().stream()
.forEach(p -> {
PreferOfferCondition preferOfferCondition = new PreferOfferCondition(offer,p);
preferOfferConditionJpaRepository.save(preferOfferCondition);

});

final String modelName = model.getName();
final String modelPhoneNumber = model.getPhoneNumber();
sendSms(smsUtil, modelPhoneNumber,modelName);
}

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

hairServiceOffer.agreeOfferToModel();
}

private void sendSms(final SmsUtil smsUtil, final String modelPhoneNumber, final String modelName) throws IOException {
smsUtil.sendOfferToModel(modelPhoneNumber, modelName);
}

}
Loading