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