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

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

code added, trial 2

  • Property mode set to 100644
File size: 2.4 KB
Line 
1package com.example.fooddeliverysystem.service.impl;
2
3import com.example.fooddeliverysystem.exceptions.SalePlaceNotFoundException;
4import com.example.fooddeliverysystem.model.Order;
5import com.example.fooddeliverysystem.model.SalePlace;
6import com.example.fooddeliverysystem.model.SalePlaceEmployee;
7import com.example.fooddeliverysystem.model.User;
8import com.example.fooddeliverysystem.repository.OrderRepository;
9import com.example.fooddeliverysystem.repository.SalePlaceEmployeeRepository;
10import com.example.fooddeliverysystem.repository.SalePlaceRepository;
11import com.example.fooddeliverysystem.repository.UserRepository;
12import com.example.fooddeliverysystem.service.SalePlaceService;
13import com.example.fooddeliverysystem.service.UserService;
14import org.springframework.stereotype.Service;
15
16import java.util.List;
17
18@Service
19public 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
Note: See TracBrowser for help on using the repository browser.