@@ -2,6 +2,7 @@ package ru.soune.nocopy.controller;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.soune.nocopy.entity.payment.Payment;
|
||||
@@ -20,13 +21,24 @@ public class PaymentController {
|
||||
private final PaymentService paymentService;
|
||||
|
||||
@PostMapping("/create")
|
||||
public ResponseEntity<Payment> createPayment(@RequestParam String email, @RequestParam Long tariffId,
|
||||
@RequestParam String operationType, @RequestParam String operationUuid) {
|
||||
public ResponseEntity<?> createPayment(@RequestParam String email, @RequestParam Long tariffId,
|
||||
@RequestParam String operationType, @RequestParam String operationUuid) {
|
||||
try {
|
||||
Payment payment = paymentService.createPayment(email, tariffId, operationType, operationUuid);
|
||||
|
||||
return ResponseEntity.ok(payment);
|
||||
} catch (TariffNotFoundException | UserNotFoundException e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
} catch (TariffNotFoundException e) {
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.NOT_FOUND)
|
||||
.body(Map.of("error", "Tariff not found", "message", e.getMessage()));
|
||||
} catch (UserNotFoundException e) {
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.NOT_FOUND)
|
||||
.body(Map.of("error", "User not found", "message", e.getMessage()));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body(Map.of("error", "Internal server error", "message", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user