source: src/main/java/com/example/fooddeliverysystem/service/impl/OrderPaymentServiceImpl.java

Last change on this file was 8d11f8c, checked in by jovanmanchev <jovanmanchev3003@…>, 18 months ago

code added, trial 2

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[8d11f8c]1package com.example.fooddeliverysystem.service.impl;
2
3import com.example.fooddeliverysystem.exceptions.FoodItemNotFoundException;
4import com.example.fooddeliverysystem.exceptions.OrderNotFoundException;
5import com.example.fooddeliverysystem.model.Consumer;
6import com.example.fooddeliverysystem.model.Deliver;
7import com.example.fooddeliverysystem.model.Order;
8import com.example.fooddeliverysystem.model.OrderPayment;
9import com.example.fooddeliverysystem.repository.OrderPaymentRepository;
10import com.example.fooddeliverysystem.service.OrderPaymentService;
11import com.example.fooddeliverysystem.service.OrderService;
12import org.springframework.stereotype.Service;
13
14import java.sql.Timestamp;
15import java.time.LocalDateTime;
16
17@Service
18public 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}
Note: See TracBrowser for help on using the repository browser.