Ignore:
Timestamp:
02/10/23 11:18:48 (21 months ago)
Author:
DenicaKj <dkorvezir@…>
Branches:
master
Children:
04153a9
Parents:
7926d68
Message:

Interested in event

Location:
src/main/java/com/example/moviezone
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/moviezone/config/WebSecurityConfig.java

    r7926d68 ref84238  
    3333                .authorizeRequests()
    3434                .antMatchers("/","/films","/home/projections","/home/events","/home/getProjections/**","/home/films","/home/getFilm/**","/getFilm/**","/home/getEvent/**","/getEvent/**","/login","/events","/projections" ,"/home", "/assets/**", "/register", "/api/**").permitAll()
    35                 .antMatchers("/home/getSeats/**","/myTickets","/home/addRating/**","/addRating/**","/getProjection/**","/home/makeReservation","/profileUser").hasRole("USER")
     35                .antMatchers("/home/getSeats/**","/myTickets","/home/addInterestedEvent/**","/home/deleteInterestedEvent/**","/home/addRating/**","/addRating/**","/getProjection/**","/home/makeReservation","/profileUser").hasRole("USER")
    3636                .antMatchers("/**").hasRole("ADMIN")
    3737                .anyRequest()
  • src/main/java/com/example/moviezone/model/manytomany/CustomerIsInterestedInEvent.java

    r7926d68 ref84238  
    2525    @Id
    2626    @Column(name = "id_customer")
    27     Integer id_customer;
     27    Integer idcustomer;
    2828    @Column(name = "id_event")
    2929    @Id
    30     Integer id_event;
     30    Integer idevent;
     31
     32    public CustomerIsInterestedInEvent(Integer id_customer, Integer id_event) {
     33        this.idcustomer = id_customer;
     34        this.idevent = id_event;
     35    }
    3136}
  • src/main/java/com/example/moviezone/model/manytomany/CustomerIsInterestedInEventId.java

    r7926d68 ref84238  
    77@Data
    88public class CustomerIsInterestedInEventId implements Serializable {
    9     Integer id_customer;
    10     Integer id_event;
     9    Integer idcustomer;
     10    Integer idevent;
    1111
    1212}
  • src/main/java/com/example/moviezone/repository/CustomerIsInterestedInEventRepository.java

    r7926d68 ref84238  
    88@Repository
    99public interface CustomerIsInterestedInEventRepository extends JpaRepository<CustomerIsInterestedInEvent, CustomerIsInterestedInEventId> {
     10    CustomerIsInterestedInEvent save(CustomerIsInterestedInEvent customerIsInterestedInEvent);
     11    void delete(CustomerIsInterestedInEvent customerIsInterestedInEvent);
     12    CustomerIsInterestedInEvent findFirstByIdeventAndAndIdcustomer(int id_event,int id_customer);
     13
    1014}
  • src/main/java/com/example/moviezone/repository/EventRepository.java

    r7926d68 ref84238  
    66import org.springframework.data.jpa.repository.query.Procedure;
    77
     8import javax.transaction.Transactional;
    89import java.util.List;
    9 
     10@Transactional
    1011public interface EventRepository extends JpaRepository<Event,Integer> {
    1112    @Procedure("project.getEventsFromCinema")
     
    1314    @Procedure("project.getEventsFromNow")
    1415    List<Event> getFilmsFromCinemaNow();
    15 
     16    @Procedure("project.getEventsForCustomer")
     17    List<Event> getEventsForCustomer(int id);
    1618}
  • src/main/java/com/example/moviezone/service/EventService.java

    r7926d68 ref84238  
    11package com.example.moviezone.service;
    22
     3import ch.qos.logback.core.encoder.EchoEncoder;
    34import com.example.moviezone.model.Event;
    45
     
    1314    List<Event> getEventsFromCinema(int id);
    1415    Optional<Event> getEventById(Long id);
     16    List<Event> getEventsForCustomer(int id);
    1517}
  • src/main/java/com/example/moviezone/service/Impl/EventServiceImpl.java

    r7926d68 ref84238  
    4343        return eventRepository.findAllById(Collections.singleton(id.intValue())).stream().findFirst();
    4444    }
     45
     46    @Override
     47    public List<Event> getEventsForCustomer(int id) {
     48        return eventRepository.getEventsForCustomer(id);
     49    }
    4550}
  • src/main/java/com/example/moviezone/web/HomeController.java

    r7926d68 ref84238  
    2424import java.util.LinkedList;
    2525import java.util.List;
    26 import java.util.Objects;
    2726import java.util.stream.Collectors;
    2827
     
    4645private final CustomerService customerService;
    4746private final Projection_RoomService projectionRoomService;
    48 
    49     public HomeController(FilmService filmService, UserService userService, ProjectionService projectionService, EventService eventService, TicketService ticketService, WorkerService workerService, CustomerRatesFilmService customerRatesFilmService, CinemaService cinemaService, CinemaOrganizesEventService cinemaOrganizesEventService, CinemaPlaysFilmService cinemaPlaysFilmService, ProjectionIsPlayedInRoomService projectionIsPlayedInRoomService, CategoryService categoryService, SeatService seatService, CustomerService customerService, Projection_RoomService projectionRoomService)
     47private final CustomerIsInterestedInEventService customerIsInterestedInEventService;
     48
     49    public HomeController(FilmService filmService, UserService userService, ProjectionService projectionService, EventService eventService, TicketService ticketService, WorkerService workerService, CustomerRatesFilmService customerRatesFilmService, CinemaService cinemaService, CinemaOrganizesEventService cinemaOrganizesEventService, CinemaPlaysFilmService cinemaPlaysFilmService, ProjectionIsPlayedInRoomService projectionIsPlayedInRoomService, CategoryService categoryService, SeatService seatService, CustomerService customerService, Projection_RoomService projectionRoomService, CustomerIsInterestedInEventService customerIsInterestedInEventService)
    5050    {
    5151
     
    6565        this.customerService = customerService;
    6666        this.projectionRoomService = projectionRoomService;
     67        this.customerIsInterestedInEventService = customerIsInterestedInEventService;
    6768    }
    6869
     
    412413    }
    413414    @GetMapping("/profileUser")
     415    @Transactional
    414416    public String getUserProfile(Model model,HttpServletRequest request)
    415417    {
    416418        Customer customer=customerService.findByUsername(request.getRemoteUser());
    417419        System.out.println(customer.getFirst_name());
     420        List<Event> events=eventService.getEventsForCustomer(customer.getId_user());
    418421        model.addAttribute("customer",customer);
     422        model.addAttribute("events",events);
    419423        model.addAttribute("bodyContent", "profileUser");
    420424        return "master-template";
    421425    }
     426    @PostMapping("/addInterestedEvent/{id}")
     427    public String addInterestedEvent(@PathVariable Long id,HttpServletRequest request, HttpServletResponse respons)
     428    {
     429        Customer customer=customerService.findByUsername(request.getRemoteUser());
     430        customerIsInterestedInEventService.add(customer.getId_user(),Integer.valueOf(id.intValue()));
     431        return "redirect:/profileUser";
     432    }
     433    @PostMapping("/deleteInterestedEvent/{id}")
     434    public String deleteInterestedEvent(@PathVariable Long id,HttpServletRequest request, HttpServletResponse respons)
     435    {
     436        Customer customer=customerService.findByUsername(request.getRemoteUser());
     437        Event event=eventService.getEventById(id).get();
     438        customerIsInterestedInEventService.delete(customer,event);
     439        return "redirect:/profileUser";
     440    }
    422441}
Note: See TracChangeset for help on using the changeset viewer.