1 | package com.example.fooddeliverysystem.service.impl;
|
---|
2 |
|
---|
3 | import com.example.fooddeliverysystem.exceptions.FoodItemNotFoundException;
|
---|
4 | import com.example.fooddeliverysystem.exceptions.OrderNotFoundException;
|
---|
5 | import com.example.fooddeliverysystem.model.Consumer;
|
---|
6 | import com.example.fooddeliverysystem.model.Deliver;
|
---|
7 | import com.example.fooddeliverysystem.model.Order;
|
---|
8 | import com.example.fooddeliverysystem.model.OrderPayment;
|
---|
9 | import com.example.fooddeliverysystem.repository.OrderPaymentRepository;
|
---|
10 | import com.example.fooddeliverysystem.service.OrderPaymentService;
|
---|
11 | import com.example.fooddeliverysystem.service.OrderService;
|
---|
12 | import org.springframework.stereotype.Service;
|
---|
13 |
|
---|
14 | import java.sql.Timestamp;
|
---|
15 | import java.time.LocalDateTime;
|
---|
16 |
|
---|
17 | @Service
|
---|
18 | public class OrderPaymentServiceImpl implements OrderPaymentService {
|
---|
19 |
|
---|
20 | private final OrderService orderService;
|
---|
21 | private final OrderPaymentRepository orderPaymentRepository;
|
---|
22 |
|
---|
23 | public OrderPaymentServiceImpl(OrderService orderService, OrderPaymentRepository orderPaymentRepository) {
|
---|
24 | this.orderService = orderService;
|
---|
25 | this.orderPaymentRepository = orderPaymentRepository;
|
---|
26 | }
|
---|
27 |
|
---|
28 |
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public void createOrderPayment(Long orderId) throws OrderNotFoundException, FoodItemNotFoundException {
|
---|
32 | Order order = this.orderService.findOrderById(orderId);
|
---|
33 | Integer orderCost = this.orderService.calculateCostOfOrder(orderId);
|
---|
34 | Deliver deliver = order.getDeliver();
|
---|
35 | Consumer consumer = order.getConsumer();
|
---|
36 | OrderPayment orderPayment = new OrderPayment(orderCost, order.getTypeOfPayment(), Timestamp.valueOf(LocalDateTime.now()), consumer, deliver);
|
---|
37 | order.setOrderStatus("zavrsena");
|
---|
38 | OrderPayment orderPayment1 = this.orderPaymentRepository.save(orderPayment);
|
---|
39 | Order order1 = this.orderService.findOrderById(orderId);
|
---|
40 | order1.setOrderPayment(orderPayment1);
|
---|
41 | this.orderService.saveOrder(order1);
|
---|
42 | }
|
---|
43 | }
|
---|