Skip to content

Commit

Permalink
Merge pull request #275 from sharemindteam/feature/264-admin-paid-api
Browse files Browse the repository at this point in the history
feat: 어드민 결제 내역 api 추가
  • Loading branch information
aeyongdodam authored Nov 18, 2024
2 parents 3ab1eb1 + 5f5ac4d commit 2f73dd6
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 3 deletions.
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 @@ -17,6 +17,8 @@ public interface PostService {

List<Post> getUnpaidPrivatePosts();

List<Post> getPaidPrivatePosts();

Post getPostByPostId(Long postId);

Post getPostByPayAppId(String payAppId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public List<Post> getUnpaidPrivatePosts() {
return postRepository.findAllByIsPaidIsFalseAndIsActivatedIsTrue();
}

@Override
public List<Post> getPaidPrivatePosts() {
return postRepository.findAllByIsPaidIsTrueAndIsActivatedIsTrueOrderByCreatedAtDesc();
}

@Override
public Post getPostByPostId(Long postId) {
return postRepository.findByPostIdAndIsActivatedIsTrue(postId).orElseThrow(
Expand Down Expand Up @@ -250,7 +255,7 @@ public Boolean getIsPostOwner(Long postId, Long customerId) {
@Transactional
public void checkPostStatus() {
postRepository.findAllWaitingPublicPostsAfter24Hours()
.forEach(BaseEntity::updateIsActivatedFalse);
.forEach(BaseEntity::updateIsActivatedFalse);

postRepository.findAllCommentedProceedingPublicPostsAfter72Hours()
.forEach(post -> post.updatePostStatus(PostStatus.TIME_OUT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface PostRepository extends JpaRepository<Post, Long>, PostCustomRep

List<Post> findAllByIsPaidIsFalseAndIsActivatedIsTrue();

List<Post> findAllByIsPaidIsTrueAndIsActivatedIsTrueOrderByCreatedAtDesc();

@Query(value = "SELECT * FROM post " +
"WHERE is_public = true AND post_status = 'WAITING' AND is_activated = true "
+ "AND created_at <= CURRENT_TIMESTAMP - INTERVAL 1 DAY ", nativeQuery = true)
Expand Down

0 comments on commit 2f73dd6

Please sign in to comment.