source: src/main/java/finki/it/terapijamkbackend/spring/services/EventService.java

Last change on this file was 43c9090, checked in by macagaso <gasoskamarija@…>, 5 weeks ago

Updated version

  • Property mode set to 100644
File size: 1.1 KB
Line 
1package finki.it.terapijamkbackend.spring.services;
2
3import finki.it.terapijamkbackend.spring.entities.Event;
4import finki.it.terapijamkbackend.spring.repositories.EventRepository;
5import jakarta.persistence.EntityNotFoundException;
6import org.springframework.beans.factory.annotation.Autowired;
7import org.springframework.stereotype.Service;
8
9import java.util.List;
10import java.util.Optional;
11
12@Service
13public class EventService {
14
15 @Autowired
16 private EventRepository eventRepository;
17
18 public Event saveEvent(Event newsItem) {
19 return eventRepository.save(newsItem);
20 }
21
22 public List<Event> getAllEvents(){
23 return eventRepository.findAll();
24 }
25 public void deleteById(String id) {
26 Long temp=Long.parseLong(id);
27 if (eventRepository.existsById(temp)) {
28 eventRepository.deleteById(temp);
29 } else {
30 throw new EntityNotFoundException("Entity with id " + id + " not found");
31 }
32 }
33 public Optional<Event> findByIdentifier(String identifier) {
34 return eventRepository.findByTitle(identifier);
35 }
36}
Note: See TracBrowser for help on using the repository browser.