Ignore:
Timestamp:
02/04/23 21:01:13 (23 months ago)
Author:
milamihajlovska <mila.mihajlovska01@…>
Branches:
master
Children:
693f587
Parents:
a554435
Message:

home controller added mappings for add new film, event and projection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/moviezone/web/HomeController.java

    ra554435 r302b233  
    22
    33
     4import com.example.moviezone.model.Customer;
     5import com.example.moviezone.model.Film;
    46import com.example.moviezone.model.User;
    57import com.example.moviezone.model.exceptions.UserNotFoundException;
    6 import com.example.moviezone.service.EventService;
    7 import com.example.moviezone.service.FilmService;
    8 import com.example.moviezone.service.ProjectionService;
    9 import com.example.moviezone.service.UserService;
     8import com.example.moviezone.service.*;
     9import org.springframework.format.annotation.DateTimeFormat;
    1010import org.springframework.stereotype.Controller;
    1111import org.springframework.ui.Model;
     
    2626private final ProjectionService projectionService;
    2727private final EventService eventService;
     28private final TicketService ticketService;
    2829
    29     public HomeController(FilmService filmService, UserService userService, ProjectionService projectionService, EventService eventService) {
     30    public HomeController(FilmService filmService, UserService userService, ProjectionService projectionService, EventService eventService, TicketService ticketService) {
    3031        this.filmService = filmService;
    3132        this.userService = userService;
    3233        this.projectionService = projectionService;
    3334        this.eventService = eventService;
     35        this.ticketService = ticketService;
    3436    }
    3537
    36     @GetMapping
     38    @GetMapping({"/","/home"})
    3739    public String getHomePage(Model model) {
    3840        model.addAttribute("bodyContent", "home");
     
    105107        return "master-template";
    106108    }
     109    @GetMapping("/myTickets")
     110    public  String getMyTicketsPage(Model model,HttpSession session)
     111    {
     112        model.addAttribute("tickets",ticketService.findAllByCustomer((Customer) session.getAttribute("user")));
     113        model.addAttribute("bodyContent","myTickets");
     114        return "master-template";
     115    }
     116    @GetMapping("/addProjection")
     117    public  String getAddProjectionPage(Model model)
     118    {
     119        model.addAttribute("films",filmService.findAllFilms());
     120        model.addAttribute("bodyContent","addProjection");
     121        return "master-template";
     122    }
     123    @GetMapping("/addEvent")
     124    public  String getAddEventPage(Model model)
     125    {
     126        model.addAttribute("bodyContent","addEvent");
     127        return "master-template";
     128    }
     129    @GetMapping("/addFilm")
     130    public  String getAddFilmPage(Model model)
     131    {
     132        model.addAttribute("bodyContent","addFilm");
     133        return "master-template";
     134    }
     135
     136    @PostMapping("/addP")
     137    public String saveProjection(@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date_time_start,
     138                                 @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date_time_end,
     139                                 @RequestParam String type_of_technology,
     140                                 @RequestParam Integer id_film)
     141    {
     142        projectionService.save(date_time_start,date_time_end,type_of_technology,id_film);
     143         return "redirect:/home";
     144    }
     145    @PostMapping("/addE")
     146    public String saveEvent(@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate start_date,
     147                                 @RequestParam String theme,
     148                                 @RequestParam String duration,
     149                            @RequestParam String repeating)
     150    {
     151        eventService.save(start_date,theme,duration,repeating);
     152        return "redirect:/home";
     153    }
     154    @PostMapping("/addF")
     155    public String saveFilm(
     156                            @RequestParam String name,
     157                            @RequestParam Integer duration,
     158                            @RequestParam String actors,
     159                           @RequestParam String genre,
     160                           @RequestParam String age_category,
     161                           @RequestParam String url,
     162                           @RequestParam String director,
     163                            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate start_date,
     164                            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate end_date
     165                           )
     166    {
     167        filmService.save(name,duration,actors,genre,age_category,url,director,start_date,end_date);
     168        return "redirect:/home";
     169    }
    107170
    108171}
Note: See TracChangeset for help on using the changeset viewer.