1 | package com.example.moviezone.service.Impl;
|
---|
2 |
|
---|
3 | import com.example.moviezone.model.Film;
|
---|
4 | import com.example.moviezone.model.procedures.FilmsReturnTable;
|
---|
5 | import com.example.moviezone.repository.FilmRepository;
|
---|
6 | import com.example.moviezone.service.FilmService;
|
---|
7 | import org.springframework.stereotype.Service;
|
---|
8 |
|
---|
9 | import java.time.LocalDate;
|
---|
10 | import java.util.Collections;
|
---|
11 | import java.util.List;
|
---|
12 | import java.util.Optional;
|
---|
13 |
|
---|
14 | @Service
|
---|
15 | public class FilmServiceImpl implements FilmService {
|
---|
16 | private final FilmRepository filmRepository;
|
---|
17 |
|
---|
18 | public FilmServiceImpl(FilmRepository filmRepository) {
|
---|
19 | this.filmRepository = filmRepository;
|
---|
20 | }
|
---|
21 |
|
---|
22 | @Override
|
---|
23 | public List<Film> findAllFilms() {
|
---|
24 | return filmRepository.findAll();
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public Film save(String name, Integer duration, String actors, String genre, String age_category, String url, String director, LocalDate start_date, LocalDate end_date) {
|
---|
29 | return filmRepository.save(new Film(name,duration,actors,genre,age_category,url,director,start_date,end_date));
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override
|
---|
33 | public Optional<Film> getFilmById(Long id) {
|
---|
34 | return filmRepository.findAllById(Collections.singleton(id.intValue())).stream().findFirst();
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | public List<Film> getFilmsFromCinema(int id) {
|
---|
39 | return filmRepository.getFilmsFromCinema(id);
|
---|
40 | }
|
---|
41 |
|
---|
42 | }
|
---|