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

release: 서버 배포 #276

Merged
merged 18 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a5b3af0
#264 feat: 채팅 및 편지 결제 api 추가
aeyongdodam Oct 5, 2024
9e862cd
#264 feat: 일대다 상담 api 추가
aeyongdodam Oct 5, 2024
f42b73d
Merge branch 'develop' of https://github.com/sharemindteam/sharemind-…
aeyongdodam Oct 5, 2024
bd2d66d
#270 feat: Payment에 지급일자 나타내는 settledAt 필드 추가
letskuku Oct 28, 2024
a940aea
#270 fix: PaymentGetCounselorResponse에서 지급일자 필드명 수정, 상담일자 필드 추가
letskuku Oct 28, 2024
efbe218
#270 feat: 정산 총금액 필드 dto에 한번만 사용되도록 dto 구조 수정
letskuku Oct 28, 2024
f72bde9
#270 fix: PaymentGetCustomerResponse에서 상담 결제 날짜 알맞게 반환되도록 수정
letskuku Oct 28, 2024
d46bdf9
Merge pull request #272 from sharemindteam/fix/270-counselor-payment
letskuku Oct 31, 2024
b1d788e
#270 fix: PaymentGetCounselorResponse에서 total 필드 제거
letskuku Oct 31, 2024
ea75121
Merge pull request #273 from sharemindteam/fix/270-counselor-payment
letskuku Oct 31, 2024
1c33236
#271 fix: 수수료율 수정
letskuku Nov 2, 2024
0543dcc
#271 feat: Payment에 수수료 필드 추가
letskuku Nov 2, 2024
a7f9ab5
#271 feat: 순수익 계산 로직 수정
letskuku Nov 2, 2024
90d122e
#271 refactor: 코드 로직 형식 통일
letskuku Nov 2, 2024
3ab1eb1
Merge pull request #274 from sharemindteam/fix/271-payment-fee
letskuku Nov 4, 2024
98e7084
feat: 상담 상태 및 내림차순 정렬
aeyongdodam Nov 11, 2024
5f5ac4d
Merge branch 'develop' of https://github.com/sharemindteam/sharemind-…
aeyongdodam Nov 11, 2024
2f73dd6
Merge pull request #275 from sharemindteam/feature/264-admin-paid-api
aeyongdodam Nov 18, 2024
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 @@ -16,6 +16,8 @@
public interface AdminService {
List<ConsultGetUnpaidResponse> getUnpaidConsults();

List<ConsultGetUnpaidResponse> getPaidConsults();

SmsGetResponse updateConsultIsPaid(Long consultId);
List<CounselorGetProfileResponse> getPendingCounselors();

Expand All @@ -31,6 +33,8 @@ public interface AdminService {

List<PostGetUnpaidPrivateResponse> getUnpaidPrivatePosts();

List<PostGetUnpaidPrivateResponse> getPaidPrivatePosts();

void updatePostIsPaid(Long postId);

List<CustomerGetByNicknameOrEmailResponse> getCustomersByNicknameOrEmail(String keyword);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public List<ConsultGetUnpaidResponse> getUnpaidConsults() {
.toList();
}

@Override
public List<ConsultGetUnpaidResponse> getPaidConsults() {
return consultService.getPaidConsults().stream()
.map(ConsultGetUnpaidResponse::of)
.toList();
}

@Transactional
public SmsGetResponse updateConsultIsPaid(Long consultId) {
Consult consult = consultService.getConsultByConsultId(consultId);
Expand Down Expand Up @@ -177,6 +184,13 @@ public List<PostGetUnpaidPrivateResponse> getUnpaidPrivatePosts() {
.toList();
}

@Override
public List<PostGetUnpaidPrivateResponse> getPaidPrivatePosts() {
return postService.getPaidPrivatePosts().stream()
.map(PostGetUnpaidPrivateResponse::of)
.toList();
}

@Transactional
@Override
public void updatePostIsPaid(Long postId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ public class ConsultGetUnpaidResponse {
@Schema(description = "상담 신청 일시")
private final LocalDateTime createdAt;

@Schema(description = "상담 상태")
private final String consultStatus;

@Builder
public ConsultGetUnpaidResponse(Long consultId, String customerName, String customerEmail,
String counselorName, String counselorEmail, String counselorPhoneNumber,
String consultType, Long cost, LocalDateTime createdAt) {
String consultType, Long cost, LocalDateTime createdAt, String consultStatus) {
this.consultId = consultId;
this.customerName = customerName;
this.customerEmail = customerEmail;
Expand All @@ -52,6 +55,7 @@ public ConsultGetUnpaidResponse(Long consultId, String customerName, String cust
this.consultType = consultType;
this.cost = cost;
this.createdAt = createdAt;
this.consultStatus = consultStatus;
}


Expand All @@ -69,6 +73,7 @@ public static ConsultGetUnpaidResponse of(Consult consult) {
.consultType(consult.getConsultType().getDisplayName())
.cost(consult.getCost())
.createdAt(consult.getCreatedAt())
.consultStatus(consult.getConsultStatus().toString())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ public class PostGetUnpaidPrivateResponse {
@Schema(description = "상담 신청 일시")
private final LocalDateTime createdAt;

@Schema(description = "상담 상태")
private final String postStatus;

@Builder
public PostGetUnpaidPrivateResponse(Long postId, String customerName, String customerEmail,
Long cost, Boolean isPublic, LocalDateTime createdAt) {
Long cost, Boolean isPublic, LocalDateTime createdAt, String postStatus) {
this.postId = postId;
this.customerName = customerName;
this.customerEmail = customerEmail;
this.cost = cost;
this.isPublic = isPublic;
this.createdAt = createdAt;
this.postStatus = postStatus;
}

public static PostGetUnpaidPrivateResponse of(Post post) {
Expand All @@ -49,6 +53,7 @@ public static PostGetUnpaidPrivateResponse of(Post post) {
.cost(post.getCost())
.isPublic(post.getIsPublic())
.createdAt(post.getCreatedAt())
.postStatus(post.getPostStatus().toString())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public ResponseEntity<List<ConsultGetUnpaidResponse>> getUnpaidConsults() {
return ResponseEntity.ok(adminService.getUnpaidConsults());
}

@Operation(summary = "결제 상담(편지/채팅) 리스트 조회", description = "결제 여부(isPaid)가 true인 consult 리스트 조회")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공")
})
@GetMapping("/paid-consults")
public ResponseEntity<List<ConsultGetUnpaidResponse>> getPaidConsults() {
return ResponseEntity.ok(adminService.getPaidConsults());
}

@Operation(summary = "상담(편지/채팅) 결제 여부 수정", description = "결제 여부(isPaid)가 false인 consult를 true로 수정")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "수정 성공, resultCode로 sms api 발송 여부가 전달됩니다."),
Expand Down Expand Up @@ -172,6 +181,15 @@ public ResponseEntity<List<PostGetUnpaidPrivateResponse>> getUnpaidPrivatePosts(
return ResponseEntity.ok(adminService.getUnpaidPrivatePosts());
}

@Operation(summary = "결제 일대다 상담 리스트 조회", description = "결제 여부(isPaid)가 true인 일대다 상담 리스트 조회")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공")
})
@GetMapping("/paid-posts")
public ResponseEntity<List<PostGetUnpaidPrivateResponse>> getPaidPrivatePosts() {
return ResponseEntity.ok(adminService.getPaidPrivatePosts());
}

@Operation(summary = "일대다 비공개 상담 결제 여부 수정", description = "결제 여부(isPaid)가 false인 일대다 상담을 true로 수정")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "수정 성공"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface ConsultService {

List<Consult> getUnpaidConsults();

List<Consult> getPaidConsults();

List<Consult> getConsultsByCustomerIdAndConsultTypeAndIsPaid(Long customerId, ConsultType consultType);

List<Consult> getConsultsByCounselorIdAndConsultTypeAndIsPaid(Long counselorId, ConsultType consultType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public List<Consult> getUnpaidConsults() {
return consultRepository.findAllByIsPaidIsFalseAndIsActivatedIsTrue();
}

@Override
public List<Consult> getPaidConsults() {
return consultRepository.findAllByIsPaidIsTrueAndIsActivatedIsTrueOrderByCreatedAtDesc();
}

@Override
public List<Consult> getConsultsByCustomerIdAndConsultTypeAndIsPaid(Long customerId, ConsultType consultType) {
return consultRepository.findByCustomerIdAndConsultTypeAndIsPaid(customerId, consultType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public interface ConsultRepository extends JpaRepository<Consult, Long> {
@Query("SELECT c FROM Consult c JOIN FETCH c.payment p WHERE p.isPaid = false AND c.isActivated = true")
List<Consult> findAllByIsPaidIsFalseAndIsActivatedIsTrue();

@Query("SELECT c FROM Consult c JOIN FETCH c.payment p WHERE p.isPaid = true AND c.isActivated = true ORDER BY c.createdAt DESC")
List<Consult> findAllByIsPaidIsTrueAndIsActivatedIsTrueOrderByCreatedAtDesc();

@Query("SELECT chat.chatId FROM Consult c JOIN c.chat chat " +
"WHERE c.customer.customerId = :customerId AND c.isActivated = true AND c.consultStatus != 'FINISH'")
List<Long> findChatIdsByCustomerId(Long customerId); //todo: 쿼리 최적화 필요
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void updateCompleteMonth(Long amount) {
}

public void updateCompleteAll(Long amount) {
this.completeAll = amount;
this.completeAll += amount;
}

public void clearAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Constants {
public static final Boolean IS_CHAT = true;
public static final Boolean IS_LETTER = false;

public static final Long FEE = 1000L;
public static final Double FEE = 0.2;

public static final Long MAX_COMMENTS = 5L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.example.sharemind.customer.domain.Customer;
import com.example.sharemind.payment.domain.Payment;
import com.example.sharemind.payment.dto.response.PaymentGetCounselorHomeResponse;
import com.example.sharemind.payment.dto.response.PaymentGetCounselorResponse;
import com.example.sharemind.payment.dto.response.PaymentGetCounselorResponses;
import com.example.sharemind.payment.dto.response.PaymentGetCustomerResponse;

import java.util.List;
Expand All @@ -20,7 +20,7 @@ public interface PaymentService {

List<Payment> getRefundWaitingPayments();

List<PaymentGetCounselorResponse> getPaymentsByCounselor(Long paymentId, String status, String sort, Long customerId);
PaymentGetCounselorResponses getPaymentsByCounselor(Long paymentId, String status, String sort, Long customerId);

void updateSettlementOngoingByCounselor(Long paymentId, Long customerId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.example.sharemind.payment.domain.Payment;
import com.example.sharemind.payment.dto.response.PaymentGetCounselorHomeResponse;
import com.example.sharemind.payment.dto.response.PaymentGetCounselorResponse;
import com.example.sharemind.payment.dto.response.PaymentGetCounselorResponses;
import com.example.sharemind.payment.dto.response.PaymentGetCustomerResponse;
import com.example.sharemind.payment.exception.PaymentErrorCode;
import com.example.sharemind.payment.exception.PaymentException;
Expand All @@ -27,8 +28,6 @@
import java.time.LocalDateTime;
import java.util.List;

import static com.example.sharemind.global.constants.Constants.FEE;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
Expand Down Expand Up @@ -97,7 +96,7 @@ public List<Payment> getRefundWaitingPayments() {
}

@Override
public List<PaymentGetCounselorResponse> getPaymentsByCounselor(Long paymentId, String status,
public PaymentGetCounselorResponses getPaymentsByCounselor(Long paymentId, String status,
String sort, Long customerId) {
Counselor counselor = counselorService.getCounselorByCustomerId(customerId);
PaymentCounselorStatus counselorStatus = PaymentCounselorStatus.getPaymentCounselorStatusByName(
Expand Down Expand Up @@ -138,16 +137,15 @@ public List<PaymentGetCounselorResponse> getPaymentsByCounselor(Long paymentId,
}

Pageable pageable = PageRequest.of(DEFAULT_PAGE_NUMBER, PAYMENT_COUNSELOR_PAGE_SIZE);
Long finalTotal = total;
Page<PaymentGetCounselorResponse> page =
(paymentId == 0 ?
paymentRepository.findAllByCounselorAndCounselorStatusAndUpdatedAtIsBefore(
counselor, counselorStatus, sortTime, pageable) :
paymentRepository.findAllByPaymentIdLessThanAndCounselorAndCounselorStatusAndUpdatedAtIsBefore(
paymentId, counselor, counselorStatus, sortTime, pageable))
.map(payment -> PaymentGetCounselorResponse.of(payment, finalTotal));
.map(PaymentGetCounselorResponse::of);

return page.getContent();
return PaymentGetCounselorResponses.of(total, page.getContent());
}

@Transactional
Expand Down Expand Up @@ -213,7 +211,7 @@ public void updateSettlement(Counselor counselor) {
paymentRepository.findAllByConsultCounselorAndCounselorStatusAndIsActivatedIsTrue(counselor,
PaymentCounselorStatus.SETTLEMENT_WAITING)
.forEach(payment -> {
Long amount = payment.getConsult().getCost() - FEE;
Long amount = payment.getConsult().getCost() - payment.getFee();
settlement.updateWaitingAll(amount);
if (payment.getUpdatedAt().isAfter(LocalDateTime.now().minusWeeks(1))) {
settlement.updateWaitingWeek(amount);
Expand All @@ -225,7 +223,7 @@ public void updateSettlement(Counselor counselor) {
paymentRepository.findAllByConsultCounselorAndCounselorStatusAndIsActivatedIsTrue(counselor,
PaymentCounselorStatus.SETTLEMENT_ONGOING)
.forEach(payment -> {
Long amount = payment.getConsult().getCost() - FEE;
Long amount = payment.getConsult().getCost() - payment.getFee();
settlement.updateOngoingAll(amount);
if (payment.getUpdatedAt().isAfter(LocalDateTime.now().minusWeeks(1))) {
settlement.updateOngoingWeek(amount);
Expand All @@ -237,7 +235,7 @@ public void updateSettlement(Counselor counselor) {
paymentRepository.findAllByConsultCounselorAndCounselorStatusAndIsActivatedIsTrue(counselor,
PaymentCounselorStatus.SETTLEMENT_COMPLETE)
.forEach(payment -> {
Long amount = payment.getConsult().getCost() - FEE;
Long amount = payment.getConsult().getCost() - payment.getFee();
settlement.updateCompleteAll(amount);
if (payment.getUpdatedAt().isAfter(LocalDateTime.now().minusWeeks(1))) {
settlement.updateCompleteWeek(amount);
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/example/sharemind/payment/domain/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class Payment extends BaseEntity {
@Column
private String method;

@Column(nullable = false)
private Long fee;

@Column(name = "is_paid", nullable = false)
private Boolean isPaid;

Expand All @@ -53,13 +56,17 @@ public class Payment extends BaseEntity {
@Column(name = "approved_at")
private LocalDateTime approvedAt;

@Column(name = "settled_at")
private LocalDateTime settledAt;

@OneToOne(mappedBy = "payment", optional = false)
private Consult consult;

@Builder
public Payment(String customerPhoneNumber, Consult consult) {
this.customerPhoneNumber = customerPhoneNumber;
this.consult = consult;
this.fee = Math.round(consult.getCost() * FEE);
this.isPaid = false;
updateBothStatusNone();
}
Expand Down Expand Up @@ -110,7 +117,7 @@ public void updateCounselorStatusSettlementWaiting() {

public void updateCounselorStatusSettlementOngoing() {
Settlement settlement = this.consult.getCounselor().getSettlement();
long amount = this.consult.getCost() - FEE;
long amount = this.consult.getCost() - this.fee;
if (this.getUpdatedAt().isAfter(LocalDateTime.now().minusWeeks(1))) {
settlement.updateWaitingWeek(-amount);
}
Expand All @@ -127,7 +134,7 @@ public void updateCounselorStatusSettlementOngoing() {

public void updateCounselorStatusSettlementComplete() {
Settlement settlement = this.consult.getCounselor().getSettlement();
long amount = this.consult.getCost() - FEE;
long amount = this.consult.getCost() - this.fee;
if (this.getUpdatedAt().isAfter(LocalDateTime.now().minusWeeks(1))) {
settlement.updateOngoingWeek(-amount);
}
Expand All @@ -140,6 +147,7 @@ public void updateCounselorStatusSettlementComplete() {
settlement.updateCompleteAll(amount);

this.counselorStatus = PaymentCounselorStatus.SETTLEMENT_COMPLETE;
this.settledAt = LocalDateTime.now();
}

public void checkUpdateAuthorityByCustomer(Long customerId) {
Expand Down
Loading