1 | package com.example.moviezone.service.Impl;
|
---|
2 |
|
---|
3 | import com.example.moviezone.model.Discount;
|
---|
4 | import com.example.moviezone.model.Film;
|
---|
5 | import com.example.moviezone.model.Projection;
|
---|
6 | import com.example.moviezone.model.manytomany.ProjectionIsPlayedInRoom;
|
---|
7 | import com.example.moviezone.repository.DiscountRepository;
|
---|
8 | import com.example.moviezone.repository.FilmRepository;
|
---|
9 | import com.example.moviezone.repository.ProjectionIsPlayedInRoomRepository;
|
---|
10 | import com.example.moviezone.repository.ProjectionRepository;
|
---|
11 | import com.example.moviezone.service.ProjectionService;
|
---|
12 | import org.springframework.stereotype.Service;
|
---|
13 |
|
---|
14 | import java.time.LocalDate;
|
---|
15 | import java.time.LocalDateTime;
|
---|
16 | import java.util.List;
|
---|
17 |
|
---|
18 | @Service
|
---|
19 | public class ProjectionServiceImpl implements ProjectionService {
|
---|
20 | private final ProjectionRepository projectionRepository;
|
---|
21 | private final ProjectionIsPlayedInRoomRepository projectionIsPlayedInRoomRepository;
|
---|
22 | private final FilmRepository filmRepository;
|
---|
23 | private final DiscountRepository discountRepository;
|
---|
24 | public ProjectionServiceImpl(ProjectionRepository projectionRepository, ProjectionIsPlayedInRoomRepository projectionIsPlayedInRoomRepository, FilmRepository filmRepository, DiscountRepository discountRepository) {
|
---|
25 | this.projectionRepository = projectionRepository;
|
---|
26 | this.projectionIsPlayedInRoomRepository = projectionIsPlayedInRoomRepository;
|
---|
27 | this.filmRepository = filmRepository;
|
---|
28 | this.discountRepository = discountRepository;
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Override
|
---|
32 | public List<Projection> findAllProjections() {
|
---|
33 | return projectionRepository.findAll();
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public List<Projection> getProjectionsForFilms(int id) {
|
---|
38 | return projectionRepository.getProjectionsForFilms(id);
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public List<Projection> getProjectionsNow() {
|
---|
43 | return projectionRepository.getProjectionsNow();
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public Projection findById(Integer id_projection) {
|
---|
48 | return projectionRepository.findById(id_projection).orElseThrow(RuntimeException::new);
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public Projection save(LocalDateTime date_time_start, LocalDateTime date_time_end, String type_of_technology, Integer id_film, Integer id_room, Integer id_discount) {
|
---|
54 | Film film=filmRepository.findById(id_film).orElseThrow(RuntimeException::new);
|
---|
55 | Discount discount = discountRepository.findById(id_discount).orElseThrow(RuntimeException::new);
|
---|
56 | Projection projection = projectionRepository.save(new Projection(date_time_start,type_of_technology,date_time_end,film,discount));
|
---|
57 | projectionIsPlayedInRoomRepository.save(new ProjectionIsPlayedInRoom(projection.getId_projection(),id_room));
|
---|
58 | return projection;
|
---|
59 | }
|
---|
60 |
|
---|
61 | }
|
---|