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