source: src/main/java/tech/techharbor/Service/Impl/OrderTableServiceImpl.java

main
Last change on this file was f4b4afa, checked in by Nikola Todoroski <nikola.todoroski@…>, 6 months ago

Pushed whole project, original project location on github:https://github.com/hehxd/Tech-Harbor

  • Property mode set to 100644
File size: 2.0 KB
Line 
1package tech.techharbor.Service.Impl;
2
3import org.springframework.stereotype.Service;
4import tech.techharbor.Model.Exceptions.OrderNotFoundException;
5import tech.techharbor.Model.OrderTableModel;
6import tech.techharbor.Repository.OrderTableRepository;
7import tech.techharbor.Service.OrderTableService;
8
9import java.util.Date;
10import java.util.List;
11
12@Service
13public class OrderTableServiceImpl implements OrderTableService {
14
15 private final OrderTableRepository orderTableRepository;
16
17 public OrderTableServiceImpl(OrderTableRepository orderTableRepository) {
18 this.orderTableRepository = orderTableRepository;
19 }
20
21 @Override
22 public OrderTableModel findById(Integer id) {
23 return this.orderTableRepository.findById(id).orElseThrow(() -> new OrderNotFoundException(id));
24 }
25
26 @Override
27 public OrderTableModel create(String orderStatus, Date date, Integer customerId) {
28 OrderTableModel order = new OrderTableModel(orderStatus, (java.sql.Date) date, customerId);
29 return this.orderTableRepository.save(order);
30 }
31
32 @Override
33 public OrderTableModel update(Integer id, String orderStatus, Date date) {
34 OrderTableModel order = this.orderTableRepository.findById(id).orElseThrow(() -> new OrderNotFoundException(id));
35 order.setOrderStatus(orderStatus);
36 order.setOrderDate((java.sql.Date) date);
37 return this.orderTableRepository.save(order);
38 }
39
40 @Override
41 public List<OrderTableModel> findByCustomerId(Integer customerId) {
42 return this.orderTableRepository.findByCustomerId(customerId);
43 }
44
45 @Override
46 public void delete(Integer id) {
47 this.orderTableRepository.deleteById(id);
48 }
49
50 @Override
51 public void updateOrderStatus(Integer orderId, String newStatus) {
52 OrderTableModel order = orderTableRepository.findById(orderId).orElse(null);
53 if (order != null) {
54 order.setOrderStatus(newStatus);
55 orderTableRepository.save(order);
56 }
57 }
58}
Note: See TracBrowser for help on using the repository browser.