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

[PEAUTY-107] Impl sending estimate proposal #33

Merged
merged 7 commits into from
Dec 3, 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
@@ -0,0 +1,10 @@
package com.peauty.customer.business.bidding;

import com.peauty.domain.bidding.BiddingProcess;

public interface BiddingProcessPort {

BiddingProcess getProcessById(Long processId);
BiddingProcess save(BiddingProcess process);
BiddingProcess initProcess(BiddingProcess process);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.peauty.customer.business.bidding;

public interface BiddingThreadPort {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.peauty.customer.business.bidding;

import com.peauty.customer.business.bidding.dto.AcceptEstimateResult;
import com.peauty.customer.business.bidding.dto.SendEstimateProposalCommand;
import com.peauty.customer.business.bidding.dto.SendEstimateProposalResult;

public interface CustomerBiddingService {

SendEstimateProposalResult sendEstimateProposal(
Long userId,
Long puppyId,
SendEstimateProposalCommand command
);

AcceptEstimateResult acceptEstimate(
Long userId,
Long puppyId,
Long processId,
Long threadId
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.peauty.customer.business.bidding;

import com.peauty.customer.business.bidding.dto.AcceptEstimateResult;
import com.peauty.customer.business.bidding.dto.SendEstimateProposalCommand;
import com.peauty.customer.business.bidding.dto.SendEstimateProposalResult;
import com.peauty.domain.bidding.BiddingProcess;
import com.peauty.domain.bidding.DesignerId;
import com.peauty.domain.bidding.PuppyId;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class CustomerBiddingServiceImpl implements CustomerBiddingService {

private final BiddingProcessPort biddingProcessPort;

// TODO ν”„λ‘œμ„ΈμŠ€ μ ‘κ·Ό 검증 ex) μ˜¬λ°”λ₯Έ μœ μ €μΈμ§€...
// TODO κ²¬μ μš”μ²­μ„œ μ €μž₯
@Override
@Transactional
public SendEstimateProposalResult sendEstimateProposal(
Long userId,
Long puppyId,
SendEstimateProposalCommand command
) {
BiddingProcess process = biddingProcessPort.initProcess(BiddingProcess.createNewProcess(new PuppyId(puppyId)));
command.designerIds()
.forEach(id -> process.addNewThread(new DesignerId(id)));
BiddingProcess savedProcess = biddingProcessPort.save(process);
return SendEstimateProposalResult.from(savedProcess);
}

@Override
@Transactional
public AcceptEstimateResult acceptEstimate(
Long userId,
Long puppyId,
Long processId,
Long threadId
) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.peauty.customer.business.bidding.dto;

public record AcceptEstimateResult() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.peauty.customer.business.bidding.dto;

import java.util.List;

public record SendEstimateProposalCommand(
List<Long> designerIds
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.peauty.customer.business.bidding.dto;

import com.peauty.domain.bidding.BiddingProcess;
import com.peauty.domain.bidding.BiddingProcessStatus;
import com.peauty.domain.bidding.BiddingProcessTimeInfo;
import com.peauty.domain.bidding.BiddingThread;

import java.util.List;

public record SendEstimateProposalResult(
Long processId,
Long puppyId,
List<Long> designerIds,
BiddingProcessStatus processStatus,
BiddingProcessTimeInfo processTimeInfo
) {

public static SendEstimateProposalResult from(BiddingProcess process) {
return new SendEstimateProposalResult(
process.getId().orElse(new BiddingProcess.ID(0L)).value(),
process.getPuppyId().value(),
process.getThreads().stream()
.map(thread -> thread.getDesignerId().value())
.toList(),
process.getStatus(),
process.getTimeInfo()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.peauty.customer.implementaion.bidding;

import com.peauty.domain.bidding.*;
import com.peauty.persistence.bidding.BiddingProcessEntity;
import com.peauty.persistence.bidding.BiddingThreadEntity;

import java.util.List;

public class BiddingMapper {

public static BiddingProcess toProcessDomain(
BiddingProcessEntity processEntity,
List<BiddingThreadEntity> threadEntities
) {
List<BiddingThread> threads = threadEntities.stream()
.map(BiddingMapper::toThreadDomain)
.toList();

return BiddingProcess.loadProcess(
new BiddingProcess.ID(processEntity.getId()),
new PuppyId(processEntity.getPuppyId()),
processEntity.getStatus(),
new BiddingProcessTimeInfo(processEntity.getCreatedAt(), processEntity.getStatusModifiedAt()),
threads
);
}

public static BiddingProcessEntity toProcessEntity(BiddingProcess process) {
return BiddingProcessEntity.builder()
.id(process.getId().map(BiddingProcess.ID::value).orElse(null))
.puppyId(process.getPuppyId().value())
.status(process.getStatus())
.createdAt(process.getTimeInfo().getCreatedAt())
.statusModifiedAt(process.getTimeInfo().getStatusModifiedAt())
.build();
}

public static BiddingThread toThreadDomain(BiddingThreadEntity threadEntity) {
return BiddingThread.loadThread(
new BiddingThread.ID(threadEntity.getId()),
new BiddingProcess.ID(threadEntity.getBiddingProcessId()),
new DesignerId(threadEntity.getDesignerId()),
threadEntity.getStep(),
threadEntity.getStatus(),
new BiddingThreadTimeInfo(
threadEntity.getCreatedAt(),
threadEntity.getStepModifiedAt(),
threadEntity.getStatusModifiedAt()
)
);
}

public static BiddingThreadEntity toThreadEntity(BiddingThread thread) {
return BiddingThreadEntity.builder()
.id(thread.getId().map(BiddingThread.ID::value).orElse(null))
.biddingProcessId(thread.getProcessId().value())
.designerId(thread.getDesignerId().value())
.step(thread.getStep())
.status(thread.getStatus())
.createdAt(thread.getTimeInfo().getCreatedAt())
.stepModifiedAt(thread.getTimeInfo().getStepModifiedAt())
.statusModifiedAt(thread.getTimeInfo().getStatusModifiedAt())
.build();
}

public static List<BiddingThreadEntity> toThreadEntities(List<BiddingThread> threads) {
return threads.stream()
.map(BiddingMapper::toThreadEntity)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.peauty.customer.implementaion.bidding;

import com.peauty.customer.business.bidding.BiddingProcessPort;
import com.peauty.domain.bidding.BiddingProcess;
import com.peauty.domain.exception.PeautyException;
import com.peauty.domain.response.PeautyResponseCode;
import com.peauty.persistence.bidding.BiddingProcessEntity;
import com.peauty.persistence.bidding.BiddingProcessRepository;
import com.peauty.persistence.bidding.BiddingThreadEntity;
import com.peauty.persistence.bidding.BiddingThreadRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class BiddingProcessAdapter implements BiddingProcessPort {

private final BiddingProcessRepository biddingProcessRepository;
private final BiddingThreadRepository biddingThreadRepository;

@Override
public BiddingProcess getProcessById(Long processId) {
BiddingProcessEntity foundProcessEntity = biddingProcessRepository.findById(processId)
.orElseThrow(() -> new PeautyException(PeautyResponseCode.NOT_FOUND_BIDDING_PROCESS));
List<BiddingThreadEntity> foundBiddingThreadEntities = biddingThreadRepository.findByBiddingProcessId(processId);
return BiddingMapper.toProcessDomain(foundProcessEntity, foundBiddingThreadEntities);
}

@Override
public BiddingProcess save(BiddingProcess process) {
checkInitProcess(process);
BiddingProcessEntity processEntityToSave = BiddingMapper.toProcessEntity(process);
List<BiddingThreadEntity> threadEntitiesToSave = BiddingMapper.toThreadEntities(process.getThreads());
BiddingProcessEntity savedProcessEntity = biddingProcessRepository.save(processEntityToSave);
List<BiddingThreadEntity> savedThreadEntities = biddingThreadRepository.saveAll(threadEntitiesToSave);
return BiddingMapper.toProcessDomain(savedProcessEntity, savedThreadEntities);
}

@Override
public BiddingProcess initProcess(BiddingProcess process) {
BiddingProcessEntity processEntityToSave = BiddingMapper.toProcessEntity(process);
BiddingProcessEntity savedProcessEntity = biddingProcessRepository.save(processEntityToSave);
return BiddingMapper.toProcessDomain(savedProcessEntity, List.of());
}

// TODO init 을 κ°•μ œν•˜κΈ° μœ„ν•¨μΈλ°.. λ‹€λ₯Έ 방법이 μžˆλ‚˜ μ•Œμ•„λ³΄κΈ°
private void checkInitProcess(BiddingProcess process) {
process.getId().orElseThrow(() -> new PeautyException(PeautyResponseCode.NOT_INITIALIZED_PROCESS));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.peauty.customer.presentation.controller.bidding;

import com.peauty.customer.business.bidding.CustomerBiddingService;
import com.peauty.customer.business.bidding.dto.AcceptEstimateResult;
import com.peauty.customer.business.bidding.dto.SendEstimateProposalResult;
import com.peauty.customer.presentation.controller.bidding.dto.AcceptEstimateRequest;
import com.peauty.customer.presentation.controller.bidding.dto.AcceptEstimateResponse;
import com.peauty.customer.presentation.controller.bidding.dto.SendEstimateProposalRequest;
import com.peauty.customer.presentation.controller.bidding.dto.SendEstimateProposalResponse;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/users")
@RequiredArgsConstructor
public class CustomerBiddingController {

private final CustomerBiddingService customerBiddingService;

@PostMapping("/{userId}/puppies/{puppyId}/biddings")
@Operation(summary = "μž…μ°° ν”„λ‘œμ„ΈμŠ€ μ‹œμž‘", description = "λ””μžμ΄λ„ˆλ“€μ—κ²Œ 견적 μ œμ•ˆμ„ μ „μ†‘ν•˜λ©΄μ„œ μž…μ°° ν”„λ‘œμ„ΈμŠ€λ₯Ό μ‹œμž‘ν•©λ‹ˆλ‹€.")
public SendEstimateProposalResponse initProcessWithSendEstimateProposal(
@PathVariable Long userId,
@PathVariable Long puppyId,
@RequestBody SendEstimateProposalRequest request
) {
SendEstimateProposalResult result = customerBiddingService.sendEstimateProposal(userId, puppyId, request.toCommand());
return SendEstimateProposalResponse.from(result);
}

@PostMapping("/{userId}/puppies/{puppyId}/biddings/{processId}/threads/{threadId}/accept")
@Operation(summary = "견적 수락", description = "λ””μžμ΄λ„ˆκ°€ μ œμ•ˆν•œ 견적을 μˆ˜λ½ν•©λ‹ˆλ‹€.")
public AcceptEstimateResponse acceptEstimate(
@PathVariable Long userId,
@PathVariable Long puppyId,
@PathVariable Long processId,
@PathVariable Long threadId,
@RequestBody AcceptEstimateRequest request
) {
AcceptEstimateResult result = customerBiddingService.acceptEstimate(
userId,
puppyId,
processId,
threadId
);
return AcceptEstimateResponse.from(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.peauty.customer.presentation.controller.bidding.dto;

public record AcceptEstimateRequest() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.peauty.customer.presentation.controller.bidding.dto;

import com.peauty.customer.business.bidding.dto.AcceptEstimateResult;

public record AcceptEstimateResponse(
) {

public static AcceptEstimateResponse from(AcceptEstimateResult result) {
return new AcceptEstimateResponse(

);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.peauty.customer.presentation.controller.bidding.dto;

import com.peauty.customer.business.bidding.dto.SendEstimateProposalCommand;

import java.util.List;

public record SendEstimateProposalRequest(
List<Long> designerIds
) {
public SendEstimateProposalCommand toCommand() {
return new SendEstimateProposalCommand(designerIds);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.peauty.customer.presentation.controller.bidding.dto;

import com.peauty.customer.business.bidding.dto.SendEstimateProposalResult;

import java.time.format.DateTimeFormatter;
import java.util.List;

public record SendEstimateProposalResponse(
Long processId,
Long puppyId,
List<Long> designerIds,
String processStatus,
String createdAt
) {

public static SendEstimateProposalResponse from(SendEstimateProposalResult result) {
return new SendEstimateProposalResponse(
result.processId(),
result.puppyId(),
result.designerIds(),
result.processStatus().getDescription(),
result.processTimeInfo().getCreatedAt().format(DateTimeFormatter.BASIC_ISO_DATE)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.peauty.designer.business.bidding;

import com.peauty.designer.business.bidding.dto.CompleteGroomingResult;
import com.peauty.designer.business.bidding.dto.SendEstimateCommand;
import com.peauty.designer.business.bidding.dto.SendEstimateResult;

public interface DesignerBiddingService {

SendEstimateResult sendEstimate(
Long userId,
Long processId,
Long threadId,
SendEstimateCommand command
);

CompleteGroomingResult completeGrooming(
Long userId,
Long processId,
Long threadId
);
}
Loading
Loading