|
| 1 | +package com.Catch_Course.domain.payments.controller; |
| 2 | + |
| 3 | +import com.Catch_Course.domain.member.entity.Member; |
| 4 | +import com.Catch_Course.domain.payments.dto.PaymentDto; |
| 5 | +import com.Catch_Course.domain.payments.service.PaymentService; |
| 6 | +import com.Catch_Course.global.Rq; |
| 7 | +import com.Catch_Course.global.dto.RsData; |
| 8 | +import io.swagger.v3.oas.annotations.Operation; |
| 9 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 10 | +import jakarta.validation.Valid; |
| 11 | +import jakarta.validation.constraints.NotBlank; |
| 12 | +import jakarta.validation.constraints.NotNull; |
| 13 | +import lombok.RequiredArgsConstructor; |
| 14 | +import org.hibernate.validator.constraints.Length; |
| 15 | +import org.springframework.web.bind.annotation.*; |
| 16 | + |
| 17 | +import java.util.List; |
| 18 | + |
| 19 | +@Tag(name = "paymentController", description = "결제 관련 API") |
| 20 | +@RestController |
| 21 | +@RequestMapping("/api/payment") |
| 22 | +@RequiredArgsConstructor |
| 23 | +public class PaymentController { |
| 24 | + |
| 25 | + private final PaymentService paymentService; |
| 26 | + private final Rq rq; |
| 27 | + |
| 28 | + |
| 29 | + @Operation(summary = "수강신청 정보로 결제 정보 조회") |
| 30 | + @GetMapping("/{reservationId}") |
| 31 | + public RsData<PaymentDto> getPayment(@PathVariable Long reservationId) { |
| 32 | + |
| 33 | + Member member = rq.getMember(rq.getDummyMember()); // 실제 멤버 객체 |
| 34 | + |
| 35 | + PaymentDto paymentDto = paymentService.getPayment(member, reservationId); |
| 36 | + |
| 37 | + return new RsData<>( |
| 38 | + "200-1", |
| 39 | + "결제 정보 조회가 완료되었습니다.", |
| 40 | + paymentDto |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + @Operation(summary = "결제 목록 조회") |
| 45 | + @GetMapping() |
| 46 | + public RsData<List<PaymentDto>> getPayments() { |
| 47 | + |
| 48 | + Member member = rq.getMember(rq.getDummyMember()); // 실제 멤버 객체 |
| 49 | + |
| 50 | + List<PaymentDto> paymentDtos = paymentService.getPayments(member); |
| 51 | + |
| 52 | + return new RsData<>( |
| 53 | + "200-1", |
| 54 | + "신청 목록 조회가 완료되었습니다.", |
| 55 | + paymentDtos |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | + @Operation(summary = "결제 생성 및 요청") |
| 61 | + @PostMapping("/request") |
| 62 | + public RsData<PaymentDto> requestPayment(@RequestParam Long reservationId) { |
| 63 | + |
| 64 | + Member member = rq.getMember(rq.getDummyMember()); // 실제 멤버 객체 |
| 65 | + |
| 66 | + PaymentDto paymentDto = paymentService.requestPayment(member, reservationId); |
| 67 | + |
| 68 | + return new RsData<>( |
| 69 | + "200-1", |
| 70 | + "신청 목록 조회가 완료되었습니다.", |
| 71 | + paymentDto |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + record confirmPaymentReqBody(@NotBlank String paymentKey, |
| 76 | + @NotBlank @Length(min = 3) String orderId, |
| 77 | + @NotNull Long amount) { |
| 78 | + } |
| 79 | + |
| 80 | + @Operation(summary = "결제 승인") |
| 81 | + @PostMapping("/confirm") |
| 82 | + public RsData<PaymentDto> confirmPayment(@RequestBody @Valid confirmPaymentReqBody body) { |
| 83 | + |
| 84 | + PaymentDto paymentDto = paymentService.confirmPayment(body.paymentKey, body.orderId, body.amount); |
| 85 | + |
| 86 | + return new RsData<>( |
| 87 | + "200-1", |
| 88 | + "신청 목록 조회가 완료되었습니다.", |
| 89 | + paymentDto |
| 90 | + ); |
| 91 | + } |
| 92 | + |
| 93 | + @Operation(summary = "결제 취소") |
| 94 | + @DeleteMapping("/{reservationId}") |
| 95 | + public RsData<PaymentDto> getReservations(@PathVariable Long reservationId) { |
| 96 | + Member member = rq.getMember(rq.getDummyMember()); // 실제 멤버 객체 |
| 97 | + |
| 98 | + PaymentDto paymentDto = paymentService.deletePaymentRequest(member, reservationId); |
| 99 | + |
| 100 | + return new RsData<>( |
| 101 | + "200-1", |
| 102 | + "결제 취소요청이 접수되었습니다.", |
| 103 | + paymentDto |
| 104 | + ); |
| 105 | + } |
| 106 | + |
| 107 | +} |
0 commit comments