Skip to content

Commit

Permalink
[KAN-255] feat(euna): 청구서 조회 백엔드 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
EunaAhn committed Jul 26, 2024
1 parent 1f298c4 commit 5ee2315
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import kr.or.kosa.cmsplusmain.domain.billing.dto.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -15,12 +16,6 @@
import kr.or.kosa.cmsplusmain.domain.base.dto.PageReq;
import kr.or.kosa.cmsplusmain.domain.base.dto.PageRes;
import kr.or.kosa.cmsplusmain.domain.base.security.VendorId;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingCreateReq;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingDetailRes;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingListItemRes;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingProductRes;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingSearchReq;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingUpdateReq;
import kr.or.kosa.cmsplusmain.domain.billing.service.BillingService;
import lombok.RequiredArgsConstructor;

Expand All @@ -42,7 +37,7 @@ public void createBilling(@VendorId Long vendorId, @RequestBody @Valid BillingCr
/*
* 청구서 발송
* */
@GetMapping("invoice/{billingId}")
@GetMapping("send-invoice/{billingId}")
public void sendInvoice(@VendorId Long vendorId, @PathVariable Long billingId) {
billingService.sendInvoice(vendorId, billingId);
}
Expand Down Expand Up @@ -87,6 +82,15 @@ public BillingDetailRes getBillingDetail(@VendorId Long vendorId, @PathVariable
return billingService.getBillingDetail(vendorId, billingId);
}


/**
* 청구서 조회
* */
@GetMapping("invoice/{billingId}")
public InvoiceRes getInvoice(@PathVariable Long billingId) {
return billingService.getInvoice(billingId);
}

/**
* 청구상품 조회
* */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package kr.or.kosa.cmsplusmain.domain.billing.dto;

import kr.or.kosa.cmsplusmain.domain.billing.entity.Billing;
import kr.or.kosa.cmsplusmain.domain.billing.entity.BillingStatus;
import kr.or.kosa.cmsplusmain.domain.member.dto.MemberDto;
import kr.or.kosa.cmsplusmain.domain.member.entity.Member;
import kr.or.kosa.cmsplusmain.domain.payment.dto.type.PaymentTypeInfoRes;
import kr.or.kosa.cmsplusmain.domain.payment.entity.type.PaymentType;
import kr.or.kosa.cmsplusmain.domain.payment.entity.type.PaymentTypeInfo;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class InvoiceRes {
private final Long billingId;
private final String billingStatus;
private final MemberDto member;
private final String invoiceName;
private final String invoiceMessage;
private final Long billingPrice;
private final PaymentTypeInfoRes paymentType;

public static InvoiceRes fromEntity(Billing billing, Member member, PaymentTypeInfoRes paymentType) {
return InvoiceRes.builder()
.billingId(billing.getId())
.billingStatus(billing.getBillingStatus().getTitle())
.member(MemberDto.fromEntity(member))
.invoiceName(billing.getInvoiceName())
.invoiceMessage(billing.getInvoiceMessage())
.billingPrice(billing.getBillingPrice())
.paymentType(paymentType)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
import java.util.Map;
import java.util.stream.Collectors;

import kr.or.kosa.cmsplusmain.domain.billing.dto.*;
import kr.or.kosa.cmsplusmain.domain.billing.entity.BillingStatus;
import kr.or.kosa.cmsplusmain.domain.payment.dto.type.PaymentTypeInfoRes;
import kr.or.kosa.cmsplusmain.domain.payment.entity.Payment;
import kr.or.kosa.cmsplusmain.domain.payment.entity.type.PaymentTypeInfo;
import kr.or.kosa.cmsplusmain.domain.payment.service.PaymentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import jakarta.persistence.EntityNotFoundException;
import kr.or.kosa.cmsplusmain.domain.base.dto.PageReq;
import kr.or.kosa.cmsplusmain.domain.base.dto.PageRes;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingCreateReq;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingDetailRes;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingListItemRes;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingProductReq;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingProductRes;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingSearchReq;
import kr.or.kosa.cmsplusmain.domain.billing.dto.BillingUpdateReq;
import kr.or.kosa.cmsplusmain.domain.billing.entity.Billing;
import kr.or.kosa.cmsplusmain.domain.billing.entity.BillingProduct;
import kr.or.kosa.cmsplusmain.domain.billing.entity.BillingState;
Expand All @@ -45,6 +44,8 @@ public class BillingService {
private final ContractCustomRepository contractCustomRepository;
// private final KafkaMessagingService kafkaMessagingService;

private final PaymentService paymentService;

// 청구서 URL(청구 ID), 청구서 메시지 내용
private static final String INVOICE_URL_FORMAT = "https://localhost:8080/invoice/%d";
private static final String INVOICE_MESSAGE_FORMAT =
Expand Down Expand Up @@ -194,6 +195,21 @@ public BillingDetailRes getBillingDetail(Long vendorId, Long billingId) {
return BillingDetailRes.fromEntity(billing, fieldToState);
}

/**
* 청구서 조회 |
* 2회 쿼리 발생 | 청구존재여부, 청구상세
* */
public InvoiceRes getInvoice(Long billingId) {
Billing billing = billingCustomRepository.findBillingWithContract(billingId);

Contract contract = billing.getContract();
Member member = contract.getMember();
Payment payment = contract.getPayment();
PaymentTypeInfoRes paymentTypeInfoRes = paymentService.getPaymentTypeInfo(payment);

return InvoiceRes.fromEntity(billing, member, paymentTypeInfoRes);
}

/**
* 특정 청구의 모든 청구상품 조회
* 2회 쿼리 발생 | 청구존재여부, 청구상품
Expand Down

0 comments on commit 5ee2315

Please sign in to comment.