PaymentController

mail@pastecode.io avatar
unknown
java
2 years ago
2.3 kB
2
Indexable
Never
package com.ossovita.hesapkimde.controllers;

import com.ossovita.hesapkimde.business.abstracts.PaymentService;
import com.ossovita.hesapkimde.core.entities.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/1.0/payments")
@CrossOrigin
public class PaymentController {


    PaymentService paymentService;

    @Autowired
    public PaymentController(PaymentService paymentService) {
        this.paymentService = paymentService;
    }

    @GetMapping
    List<Payment> getAllPayments() {
        return paymentService.getAllPayments();
    }

    @PostMapping("/create")
    Payment createPayment(@RequestBody Payment payment) {
        return paymentService.createPayment(payment);
    }

    @MessageMapping("/get-payments-by-orderfk")
    @SendTo("/api/1.0/payments/get-payments-by-orderfk")
    List<Payment> getPaymentsByOrderFk(@Payload long orderFk) {
        System.out.println("gelen orderFk:"+orderFk);
        return paymentService.getPaymentsByOrderFk(orderFk);
    }

    @GetMapping("/get-randomly-payments-by-orderfk")
    public List<Payment> getRandomlyPaymentByOrderFk(@RequestParam long orderFk, @RequestParam int piece) {
        return paymentService.getRandomlyPaymentsByOrderFk(orderFk, piece);
    }

    @GetMapping("/update-payment-informations-of-selected-payment")//@TODO will be replaced with @PutMapping
    public Payment updatePaymentInformationsOfSelectedPayment(@RequestParam long orderFk, @RequestParam long paymentPk, @RequestParam int paymentAmount, @RequestParam String paymentType, @RequestParam String paymentStatus) {
        return paymentService.updatePaymentInformationsOfSelectedPayment(orderFk, paymentPk, paymentAmount, paymentType, paymentStatus);
    }

    @DeleteMapping("/delete-payment-by-paymentpk")
    public void deletePaymentByPaymentPk(@RequestParam long paymentPk) {
        paymentService.deletePaymentByPaymentPk(paymentPk);
    }


}