1 | package com.example.fooddeliverysystem.service.impl;
|
---|
2 |
|
---|
3 | import com.example.fooddeliverysystem.exceptions.SalePlaceNotFoundException;
|
---|
4 | import com.example.fooddeliverysystem.model.Order;
|
---|
5 | import com.example.fooddeliverysystem.model.SalePlace;
|
---|
6 | import com.example.fooddeliverysystem.model.SalePlaceEmployee;
|
---|
7 | import com.example.fooddeliverysystem.model.User;
|
---|
8 | import com.example.fooddeliverysystem.repository.OrderRepository;
|
---|
9 | import com.example.fooddeliverysystem.repository.SalePlaceEmployeeRepository;
|
---|
10 | import com.example.fooddeliverysystem.repository.SalePlaceRepository;
|
---|
11 | import com.example.fooddeliverysystem.repository.UserRepository;
|
---|
12 | import com.example.fooddeliverysystem.service.SalePlaceService;
|
---|
13 | import com.example.fooddeliverysystem.service.UserService;
|
---|
14 | import org.springframework.stereotype.Service;
|
---|
15 |
|
---|
16 | import java.util.List;
|
---|
17 |
|
---|
18 | @Service
|
---|
19 | public class SalePlaceServiceImpl implements SalePlaceService {
|
---|
20 |
|
---|
21 | private SalePlaceRepository salePlaceRepository;
|
---|
22 | private OrderRepository orderRepository;
|
---|
23 |
|
---|
24 | private UserRepository userRepository;
|
---|
25 | private SalePlaceEmployeeRepository salePlaceEmployeeRepository;
|
---|
26 | public SalePlaceServiceImpl(SalePlaceRepository salePlaceRepository, OrderRepository orderRepository, UserRepository userRepository,
|
---|
27 | SalePlaceEmployeeRepository salePlaceEmployeeRepository) {
|
---|
28 | this.salePlaceRepository = salePlaceRepository;
|
---|
29 | this.orderRepository = orderRepository;
|
---|
30 | this.userRepository = userRepository;
|
---|
31 | this.salePlaceEmployeeRepository = salePlaceEmployeeRepository;
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public List<SalePlace> findAll() {
|
---|
36 | return this.salePlaceRepository.findAll();
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Override
|
---|
40 | public SalePlace findSalePlaceServiceById(Long id) throws SalePlaceNotFoundException {
|
---|
41 | return this.salePlaceRepository.findById(id).orElseThrow(() -> new SalePlaceNotFoundException("Sale place not found"));
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public List<Order> findAllCreatedOrders(String username) throws SalePlaceNotFoundException{
|
---|
47 |
|
---|
48 | return this.orderRepository.findAllBySalePlaceAndOrderStatus(findSalePlaceForUser(username), "kreirana");
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public SalePlace findSalePlaceForUser(String username){
|
---|
53 | User user = this.userRepository.findByUsername(username).get();
|
---|
54 |
|
---|
55 | SalePlaceEmployee salePlaceEmployee = this.salePlaceEmployeeRepository.findById(user.getUser_id()).get();
|
---|
56 | return salePlaceEmployee.getSalePlace();
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|