source: src/main/java/com/example/service/impl/EventServiceImpl.java

Last change on this file was a51a591, checked in by colovik <j.colovik@…>, 14 months ago

final

  • Property mode set to 100644
File size: 2.0 KB
Line 
1package com.example.service.impl;
2
3import com.example.exceptions.InvalidArgumentsException;
4import com.example.model.Client;
5import com.example.model.Enumerations.Status;
6import com.example.model.Event;
7import com.example.repository.ClientRepository;
8import com.example.repository.EventRepository;
9import com.example.repository.LocationRepository;
10import com.example.repository.UserRepository;
11import com.example.service.EventService;
12import org.springframework.stereotype.Service;
13
14import java.util.List;
15import java.util.Optional;
16
17@Service
18public class EventServiceImpl implements EventService {
19 private final EventRepository eventRepository;
20 private final ClientRepository clientRepository;
21 private final LocationRepository locationRepository;
22 private final UserRepository userRepository;
23
24 public EventServiceImpl(EventRepository eventRepository, ClientRepository clientRepository, LocationRepository locationRepository, UserRepository userRepository) {
25 this.eventRepository = eventRepository;
26 this.clientRepository = clientRepository;
27 this.locationRepository = locationRepository;
28 this.userRepository = userRepository;
29 }
30
31 @Override
32 public List<Event> findAll() {
33 return this.eventRepository.findAll();
34 }
35
36 @Override
37 public void update(Event e) {
38 eventRepository.save(e);
39 }
40
41 @Override
42 public Event findById(Integer id) {
43 return eventRepository.findById(id).get();
44 }
45
46 @Override
47 public List<Event> findByClient(Integer client_id) {
48 Optional<Client> client = clientRepository.findById(client_id);
49// User user = userRepository.findById(user_id).get();
50// return eventRepository.findByUser(user);
51 return eventRepository.findByClient(client);
52 }
53
54 @Override
55 public Optional<Event> updateStatus(Integer event_id, Status status) {
56 Event event = eventRepository.findById(event_id).orElseThrow(InvalidArgumentsException::new);
57 event.setStatus(status);
58 return Optional.of(eventRepository.save(event));
59 }
60
61}
Note: See TracBrowser for help on using the repository browser.