Changeset 8d49568 for src/main/java/com


Ignore:
Timestamp:
02/07/23 23:14:46 (23 months ago)
Author:
DenicaKj <dkorvezir@…>
Branches:
master
Children:
64ee7f4
Parents:
cb5debb
Message:

trying to call a function from database

Location:
src/main/java/com/example/moviezone
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/moviezone/model/procedures/FilmsReturnTable.java

    rcb5debb r8d49568  
    1818        this.name = name;
    1919    }
     20
     21    public Integer getId_film() {
     22        return id_film;
     23    }
     24
     25    public LocalDate getStart_date() {
     26        return start_date;
     27    }
     28
     29    public String getName() {
     30        return name;
     31    }
    2032}
  • src/main/java/com/example/moviezone/repository/FilmRepository.java

    rcb5debb r8d49568  
    77import org.springframework.data.repository.query.Param;
    88
     9import javax.transaction.Transactional;
    910import java.util.List;
    10 
     11@Transactional
    1112public interface FilmRepository extends JpaRepository<Film,Integer> {
    1213    @Procedure("project.getFilmsFromCinema")
  • src/main/java/com/example/moviezone/service/FilmService.java

    rcb5debb r8d49568  
    22
    33import com.example.moviezone.model.Film;
     4import com.example.moviezone.model.procedures.FilmsReturnTable;
    45
    56import java.time.LocalDate;
     
    1213              String age_category, String url, String director, LocalDate start_date,LocalDate end_date);
    1314    Optional<Film> getFilmById(Long id);
     15    List<FilmsReturnTable> getFilmsFromCinema(int id);
    1416}
  • src/main/java/com/example/moviezone/service/Impl/FilmServiceImpl.java

    rcb5debb r8d49568  
    22
    33import com.example.moviezone.model.Film;
     4import com.example.moviezone.model.procedures.FilmsReturnTable;
    45import com.example.moviezone.repository.FilmRepository;
    56import com.example.moviezone.service.FilmService;
     
    3435    }
    3536
     37    @Override
     38    public List<FilmsReturnTable> getFilmsFromCinema(int id) {
     39        return filmRepository.getFilmsFromCinema(id);
     40    }
     41
    3642}
  • src/main/java/com/example/moviezone/web/HomeController.java

    rcb5debb r8d49568  
    44import com.example.moviezone.model.*;
    55import com.example.moviezone.model.exceptions.PasswordsDoNotMatchException;
     6
    67import com.example.moviezone.model.manytomany.ProjectionIsPlayedInRoom;
    78import com.example.moviezone.repository.ProjectionIsPlayedInRoomRepository;
     9
     10import com.example.moviezone.model.procedures.FilmsReturnTable;
     11
    812import com.example.moviezone.service.*;
    913import org.springframework.format.annotation.DateTimeFormat;
     
    1418import javax.servlet.http.HttpSession;
    1519import java.time.LocalDate;
     20import java.util.LinkedList;
    1621import java.util.List;
    1722import java.util.stream.Collectors;
     
    3540
    3641    public HomeController(FilmService filmService, UserService userService, ProjectionService projectionService, EventService eventService, TicketService ticketService, WorkerService workerService, CustomerRatesFilmService customerRatesFilmService, CinemaService cinemaService, CinemaOrganizesEventService cinemaOrganizesEventService, CinemaPlaysFilmService cinemaPlaysFilmService, ProjectionIsPlayedInRoomRepository projectionIsPlayedInRoomRepository) {
    37        
     42
    3843        this.filmService = filmService;
    3944        this.userService = userService;
     
    127132
    128133    }
    129 
    130134    @GetMapping("/films")
    131135    public String getFilmsPage(Model model){
    132136        model.addAttribute("cinemas",cinemaService.findAllCinemas());
    133         model.addAttribute("films",filmService.findAllFilms());
     137            List<FilmsReturnTable> pom=new LinkedList<>();
     138            model.addAttribute("films",pom);
     139            boolean h=pom.isEmpty();
     140            List<FilmsReturnTable> help=filmService.getFilmsFromCinema(2);
    134141        model.addAttribute("bodyContent","films");
    135142        return "master-template";
    136143    }
    137144
     145    public String getFilmsPage1(Model model,Integer id_cinema){
     146        model.addAttribute("cinemas",cinemaService.findAllCinemas());
     147        if (id_cinema!=null) {
     148            model.addAttribute("films",filmService.getFilmsFromCinema(id_cinema.intValue()));
     149        }else{
     150            List<FilmsReturnTable> pom=new LinkedList<>();
     151            model.addAttribute("films",pom);
     152        }
     153
     154        model.addAttribute("bodyContent","films");
     155        return "master-template";
     156    }
     157    @PostMapping("/getFilmsFromCinema")
     158    public String getFilmsFromCinema(@RequestParam Integer cinema, Model model){
     159        return getFilmsPage1(model,cinema);
     160    }
    138161    @GetMapping("/projections")
    139162    public String getProjectionsPage(Model model)
Note: See TracChangeset for help on using the changeset viewer.