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

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

fix

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