1 | package com.example.skychasemk.controller;
|
---|
2 |
|
---|
3 | import com.example.skychasemk.dto.PaymentDTO;
|
---|
4 | import com.example.skychasemk.model.Payment;
|
---|
5 | import com.example.skychasemk.services.PaymentService;
|
---|
6 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
7 | import org.springframework.http.ResponseEntity;
|
---|
8 | import org.springframework.web.bind.annotation.*;
|
---|
9 |
|
---|
10 | import java.util.List;
|
---|
11 | import java.util.Optional;
|
---|
12 |
|
---|
13 | @RestController
|
---|
14 | @RequestMapping("/api")
|
---|
15 | public class PaymentController {
|
---|
16 |
|
---|
17 | @Autowired
|
---|
18 | private PaymentService paymentService;
|
---|
19 |
|
---|
20 | // Get payment by ID
|
---|
21 | @GetMapping("/payments/{id}")
|
---|
22 | public Optional<Payment> getPaymentById(@PathVariable("id") Integer paymentID) {
|
---|
23 | return paymentService.getPaymentById(paymentID);
|
---|
24 | }
|
---|
25 |
|
---|
26 | @PostMapping("/payments")
|
---|
27 | public ResponseEntity<Payment> createPayment(@RequestBody PaymentDTO dto) {
|
---|
28 | Payment payment = paymentService.createTransaction(dto);
|
---|
29 | return ResponseEntity.ok(payment);
|
---|
30 | }
|
---|
31 |
|
---|
32 | // Update an existing payment
|
---|
33 | @PutMapping("/payments/{id}")
|
---|
34 | public Payment updatePayment(@PathVariable("id") Integer paymentID, @RequestBody Payment payment) {
|
---|
35 | return paymentService.updatePayment(paymentID, payment);
|
---|
36 | }
|
---|
37 |
|
---|
38 | // Delete a payment
|
---|
39 | @DeleteMapping("/payments/{id}")
|
---|
40 | public void deletePayment(@PathVariable("id") Integer paymentID) {
|
---|
41 | paymentService.deletePayment(paymentID);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|