1 | package com.example.demo.service.ServiceImpl;
|
---|
2 |
|
---|
3 | import com.example.demo.model.Movie;
|
---|
4 | import com.example.demo.model.MovieProjection;
|
---|
5 | import com.example.demo.repository.MovieProjectionRepository;
|
---|
6 | import com.example.demo.repository.MovieRepository;
|
---|
7 | import com.example.demo.service.MovieProjectionService;
|
---|
8 | import org.springframework.stereotype.Service;
|
---|
9 | import org.springframework.transaction.annotation.Transactional;
|
---|
10 |
|
---|
11 | import java.util.List;
|
---|
12 | import java.util.Optional;
|
---|
13 |
|
---|
14 | @Service
|
---|
15 | public class MovieProjectionImpl implements MovieProjectionService {
|
---|
16 |
|
---|
17 | private final MovieProjectionRepository projectionRepository;
|
---|
18 | private final MovieRepository movieRepository;
|
---|
19 |
|
---|
20 |
|
---|
21 | public MovieProjectionImpl(MovieProjectionRepository projectionRepository, MovieRepository movieRepository) {
|
---|
22 | this.projectionRepository = projectionRepository;
|
---|
23 | this.movieRepository = movieRepository;
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public List<MovieProjection> findAll() {
|
---|
29 | return this.projectionRepository.findAll();
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override
|
---|
33 | public Optional<MovieProjection> findById(Integer projection_id) {
|
---|
34 | return this.projectionRepository.findById(projection_id);
|
---|
35 | }
|
---|
36 |
|
---|
37 | public List<MovieProjection> findAllProjections(Integer projection_id){
|
---|
38 | return this.projectionRepository.findAllProjections(projection_id);
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | @Transactional
|
---|
43 | public Optional<MovieProjection> save(
|
---|
44 | Integer projection_id,
|
---|
45 | String projection_movie_start,
|
---|
46 | String projection_movie_end,
|
---|
47 | String projection_screening_date,
|
---|
48 | String projection_type,
|
---|
49 | Float projection_price,Integer movie_id) {
|
---|
50 | Movie movie = this.movieRepository.findById(movie_id).get();
|
---|
51 | return Optional.of(this.projectionRepository.save(new MovieProjection(projection_id,projection_movie_start,projection_movie_end,
|
---|
52 | projection_screening_date,projection_type,projection_price,movie)));
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override
|
---|
56 | public void deleteById(Integer projection_id) {
|
---|
57 | this.projectionRepository.deleteById(projection_id);
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | public List<MovieProjection> findByMovieID(Integer movie_id){
|
---|
63 | return this.projectionRepository.findByMovieID(movie_id);
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | }
|
---|