PaymentSocketController

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

import com.ossovita.hesapkimde.business.abstracts.PaymentService;
import com.ossovita.hesapkimde.core.entities.Payment;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;

import java.util.List;

@Controller
public class PaymentSocketController {

    PaymentService paymentService;
    SimpMessagingTemplate messagingTemplate;

    public PaymentSocketController(PaymentService paymentService, SimpMessagingTemplate messagingTemplate) {
        this.paymentService = paymentService;
        this.messagingTemplate = messagingTemplate;
    }

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