1 | package com.example.demo.service.ServiceImpl;
|
---|
2 |
|
---|
3 | import com.example.demo.model.Movie;
|
---|
4 | import com.example.demo.model.dto.MovieDto;
|
---|
5 | import com.example.demo.repository.MovieRepository;
|
---|
6 | import com.example.demo.service.MovieService;
|
---|
7 | import org.springframework.stereotype.Service;
|
---|
8 | import org.springframework.transaction.annotation.Transactional;
|
---|
9 |
|
---|
10 | import java.util.List;
|
---|
11 | import java.util.Optional;
|
---|
12 |
|
---|
13 | @Service
|
---|
14 | public class MovieServiceImpl implements MovieService {
|
---|
15 | private final MovieRepository movieRepository;
|
---|
16 |
|
---|
17 | public MovieServiceImpl(MovieRepository movieRepository) {
|
---|
18 | this.movieRepository = movieRepository;
|
---|
19 | }
|
---|
20 |
|
---|
21 | @Override
|
---|
22 | public List<Movie> findAll() {
|
---|
23 | return this.movieRepository.findAll();
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public List<Movie> listMovies() {
|
---|
28 | return this.movieRepository.findAll();
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Override
|
---|
32 | public Optional<Movie> findAllByID(Integer id) {
|
---|
33 | return this.movieRepository.findAllByID(id);
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public Optional<Movie> findById(Integer id) {
|
---|
38 | return this.movieRepository.findById(id);
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public void deleteById(Integer movie_id){
|
---|
43 | this.movieRepository.deleteById(movie_id);
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public Optional<Movie> save(Integer movie_id, String movie_name,String movie_age_category,String movie_cast,String movie_production,String film_director,String movie_time_duration) {
|
---|
48 | return Optional.of(this.movieRepository.save(new Movie(movie_id, movie_name, movie_age_category, movie_cast, movie_production,film_director, movie_time_duration)));
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public Optional<Movie> save(MovieDto movieDto) {
|
---|
54 | this.movieRepository.deleteById(movieDto.getMovie_id());
|
---|
55 | return Optional.of(this.movieRepository.save(new Movie(movieDto.getMovie_id(),movieDto.getMovie_name(), movieDto.getMovie_cast(), movieDto.getMovie_age_category(), movieDto.getMovie_production(),movieDto.getMovie_film_director(), movieDto.getMovie_time_duration())));
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public Optional<Movie> findByName(String movie_name) {
|
---|
60 | return this.movieRepository.findByName(movie_name);
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public void deleteByName(String movie_name) {
|
---|
65 | this.movieRepository.deleteMovieByName(movie_name);
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | public Optional<Movie> findAllByName(String s) {
|
---|
70 | return this.movieRepository.findAllByName(s);
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | }
|
---|