| 1 | package com.nikola.web3ednevnikbackend.controller;
|
|---|
| 2 |
|
|---|
| 3 | import com.nikola.web3ednevnikbackend.dto.payments.*;
|
|---|
| 4 | import com.nikola.web3ednevnikbackend.service.payment.PlakjanjeService;
|
|---|
| 5 | import jakarta.persistence.EntityNotFoundException;
|
|---|
| 6 | import jakarta.validation.Valid;
|
|---|
| 7 | import lombok.RequiredArgsConstructor;
|
|---|
| 8 | import org.springframework.http.HttpStatus;
|
|---|
| 9 | import org.springframework.http.ResponseEntity;
|
|---|
| 10 | import org.springframework.web.bind.annotation.*;
|
|---|
| 11 |
|
|---|
| 12 | import java.util.List;
|
|---|
| 13 | import java.util.UUID;
|
|---|
| 14 | import java.util.UUID;
|
|---|
| 15 |
|
|---|
| 16 | @RestController
|
|---|
| 17 | @RequestMapping("/api/payments")
|
|---|
| 18 | public class PaymentController {
|
|---|
| 19 | private final PlakjanjeService plakjanjeService;
|
|---|
| 20 |
|
|---|
| 21 | public PaymentController(PlakjanjeService plakjanjeService) {
|
|---|
| 22 | this.plakjanjeService = plakjanjeService;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | //TODO:Se kreira payment
|
|---|
| 26 | @PostMapping("/create")
|
|---|
| 27 | public ResponseEntity<PlakjanjeCreatedResponseDTO> createPayment(@RequestBody @Valid CreatePaymentRequestDTO createPaymentRequestDTO) {
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | PlakjanjeCreatedResponseDTO plakjanjeCreatedResponseDTO = this.plakjanjeService.createPayment(createPaymentRequestDTO);
|
|---|
| 31 | return new ResponseEntity<PlakjanjeCreatedResponseDTO>(plakjanjeCreatedResponseDTO, HttpStatus.CREATED);
|
|---|
| 32 |
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | //TODO: Roditel (client) prakja tx_hash
|
|---|
| 36 | @PostMapping("/{paymentId}/submit-tx")
|
|---|
| 37 | public ResponseEntity<Void> submitTransactionHash(@PathVariable UUID paymentId,
|
|---|
| 38 | @RequestBody @Valid SubmitTXHashRequestDTO submitTXHashRequestDTO) {
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | this.plakjanjeService.submitTransactionHash(paymentId, submitTXHashRequestDTO);
|
|---|
| 42 | return new ResponseEntity<>(HttpStatus.CREATED);
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | //TODO:Validacija
|
|---|
| 46 | @PostMapping("/{paymentId}/validate")
|
|---|
| 47 | public ResponseEntity<Void> validatePayment(@PathVariable UUID paymentId) {
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 | this.plakjanjeService.validatePayment(paymentId);
|
|---|
| 51 | return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | //TODO:Kompletiranje na payment
|
|---|
| 55 | @PostMapping("/{paymentId}/complete")
|
|---|
| 56 | public ResponseEntity<Void> completePayment(@PathVariable UUID paymentId) {
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | this.plakjanjeService.completePayment(paymentId);
|
|---|
| 60 | return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | //TODO: Get plakjanja za roditel
|
|---|
| 64 | @GetMapping("/parent/{roditelId}")
|
|---|
| 65 | public ResponseEntity<List<PlakjanjeResponseDTO>> getPaymentsByParent(@PathVariable UUID roditelId) {
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | List<PlakjanjeResponseDTO> plakjanja_roditel = this.plakjanjeService.getByRoditel(roditelId);
|
|---|
| 69 |
|
|---|
| 70 | return new ResponseEntity<>(plakjanja_roditel, HttpStatus.OK);
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | //TODO: Get payments by soopstenie
|
|---|
| 74 | @GetMapping("/notice/{soopstenieId}")
|
|---|
| 75 | public ResponseEntity<List<PlakjanjeResponseDTO>> getPaymentsBySoopstenie(@PathVariable UUID soopstenieId) {
|
|---|
| 76 | List<PlakjanjeResponseDTO> plakjanjaBySoopstenie = this.plakjanjeService.getBySoopstenie(soopstenieId);
|
|---|
| 77 |
|
|---|
| 78 | return new ResponseEntity<>(plakjanjaBySoopstenie, HttpStatus.OK);
|
|---|
| 79 | }
|
|---|
| 80 | } |
|---|