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 | |
---|
1 | package finki.it.terapijamkbackend.spring.services;
|
---|
2 |
|
---|
3 | import finki.it.terapijamkbackend.spring.entities.Event;
|
---|
4 | import finki.it.terapijamkbackend.spring.repositories.EventRepository;
|
---|
5 | import jakarta.persistence.EntityNotFoundException;
|
---|
6 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
7 | import org.springframework.stereotype.Service;
|
---|
8 |
|
---|
9 | import java.util.List;
|
---|
10 | import java.util.Optional;
|
---|
11 |
|
---|
12 | @Service
|
---|
13 | public 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.