source: src/main/java/com/example/moviezone/service/Impl/ProjectionServiceImpl.java

Last change on this file was 1e7126f, checked in by DenicaKj <dkorvezir@…>, 15 months ago

fix

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[11dea8f]1package com.example.moviezone.service.Impl;
2
[1e7126f]3import com.example.moviezone.model.Discount;
[302b233]4import com.example.moviezone.model.Film;
[11dea8f]5import com.example.moviezone.model.Projection;
[1e7126f]6import com.example.moviezone.model.manytomany.ProjectionIsPlayedInRoom;
7import com.example.moviezone.repository.DiscountRepository;
[302b233]8import com.example.moviezone.repository.FilmRepository;
[1e7126f]9import com.example.moviezone.repository.ProjectionIsPlayedInRoomRepository;
[1b248e4]10import com.example.moviezone.repository.ProjectionRepository;
[11dea8f]11import com.example.moviezone.service.ProjectionService;
12import org.springframework.stereotype.Service;
13
[a554435]14import java.time.LocalDate;
[1e7126f]15import java.time.LocalDateTime;
[11dea8f]16import java.util.List;
17
18@Service
19public 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}
Note: See TracBrowser for help on using the repository browser.