[a51a591] | 1 | package com.example.service.impl;
|
---|
| 2 |
|
---|
| 3 | import com.example.exceptions.InvalidArgumentsException;
|
---|
| 4 | import com.example.model.Client;
|
---|
| 5 | import com.example.model.Enumerations.Status;
|
---|
| 6 | import com.example.model.Event;
|
---|
| 7 | import com.example.repository.ClientRepository;
|
---|
| 8 | import com.example.repository.EventRepository;
|
---|
| 9 | import com.example.repository.LocationRepository;
|
---|
| 10 | import com.example.repository.UserRepository;
|
---|
| 11 | import com.example.service.EventService;
|
---|
| 12 | import org.springframework.stereotype.Service;
|
---|
| 13 |
|
---|
| 14 | import java.util.List;
|
---|
| 15 | import java.util.Optional;
|
---|
| 16 |
|
---|
| 17 | @Service
|
---|
| 18 | public 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 | }
|
---|