Changeset 8a18cf5


Ignore:
Timestamp:
03/06/23 19:58:20 (21 months ago)
Author:
DenicaKj <dkorvezir@…>
Branches:
master
Children:
40935d3
Parents:
7215773
Message:

fixes

Location:
src/main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/moviezone/service/Impl/SeatServiceImpl.java

    r7215773 r8a18cf5  
    44import com.example.moviezone.model.Projection_Room;
    55import com.example.moviezone.model.Seat;
     6import com.example.moviezone.model.Ticket;
     7import com.example.moviezone.model.manytomany.ProjectionIsPlayedInRoom;
     8import com.example.moviezone.repository.ProjectionIsPlayedInRoomRepository;
     9import com.example.moviezone.repository.Projection_RoomRepository;
    610import com.example.moviezone.repository.SeatRepository;
    711import com.example.moviezone.service.SeatService;
    812import org.springframework.stereotype.Service;
    913
     14import java.util.ArrayList;
    1015import java.util.List;
    1116import java.util.Optional;
     
    1621
    1722    private final SeatRepository seatRepository;
     23    private final TicketServiceImpl ticketService;
     24    private final ProjectionIsPlayedInRoomRepository projectionIsPlayedInRoomRepository;
     25    private final Projection_RoomRepository projection_roomRepository;
    1826
    19     public SeatServiceImpl(SeatRepository seatRepository) {
     27    public SeatServiceImpl(SeatRepository seatRepository, TicketServiceImpl ticketService, ProjectionIsPlayedInRoomRepository projectionIsPlayedInRoomRepository, Projection_RoomRepository projection_roomRepository) {
    2028        this.seatRepository = seatRepository;
     29        this.ticketService = ticketService;
     30        this.projectionIsPlayedInRoomRepository = projectionIsPlayedInRoomRepository;
     31        this.projection_roomRepository = projection_roomRepository;
    2132    }
    2233
     
    3344    @Override
    3445    public List<Seat> findAllByRoomAndCategory(Projection_Room projectionRoom, Category category) {
    35         return seatRepository.findAllByCategoryAndProjection(category,projectionRoom);
     46        List<Ticket> tickets=ticketService.findAllTickets();
     47        List<Seat> seats=seatRepository.findAllByCategoryAndProjection(category,projectionRoom);
     48        List<Seat> s=new ArrayList<>();
     49        List<Projection_Room> projection_rooms=new ArrayList<>();
     50        for (int i = 0; i < tickets.size(); i++) {
     51            List<ProjectionIsPlayedInRoom> projectionIsPlayedInRooms= projectionIsPlayedInRoomRepository.findAllByProjectionId(tickets.get(i).getProjection().getId_projection());
     52            for (int j = 0; j < projectionIsPlayedInRooms.size(); j++) {
     53                projection_rooms.add(projection_roomRepository.getById(projectionIsPlayedInRooms.get(j).getIdroom()));
     54            }
     55        }
     56        int f=0;
     57        for (int i = 0; i < seats.size(); i++) {
     58            for (int j = 0; j < tickets.size(); j++) {
     59                if(seats.get(i).getId_seat().equals(tickets.get(j).getSeat().getId_seat())){
     60                    for (int k = 0; k < projection_rooms.size(); k++) {
     61                        if(seats.get(i).getProjection().getId_room().equals(projection_rooms.get(k).getId_room()))
     62                            f=1;
     63                    }
     64                }
     65
     66            }
     67
     68            if(f==0){
     69                s.add(seats.get(i));
     70            }
     71            f=0;
     72        }
     73        return s;
    3674    }
    3775
  • src/main/java/com/example/moviezone/web/HomeController.java

    r7215773 r8a18cf5  
    199199            response.sendRedirect("/login");
    200200        }
    201        
     201
    202202    }
    203203    @GetMapping("/registerWorker")
     
    396396        Customer customer=customerService.findByUsername(request.getRemoteUser());
    397397        Projection projection1=projectionService.findById(projection.intValue());
    398         if(projection1.getDiscount().equals(discount)){
     398        if(projection1.getDiscount()!=null && projection1.getDiscount().getCode().equals(discount)){
    399399            t=ticketService.saveWithDiscount(LocalDate.now(),customer,projection1,projection1.getDiscount(),seatService.getSeatById(id_seat.intValue()).get());
     400            Integer price=ticketService.priceForTicket(t.getId_ticket());
     401            price+=seatService.getSeatById(id_seat.intValue()).get().getCategory().getExtra_amount();
     402            price-=(price*projection1.getDiscount().getPercent())/100;
     403            t.setPrice(price);
    400404        }else{
    401405            t=ticketService.saveWithout(LocalDate.now(),customer,projection1,seatService.getSeatById(id_seat.intValue()).get());
    402         }
    403         Integer price=ticketService.priceForTicket(t.getId_ticket());
    404         t.setPrice(price);
     406            Integer price=ticketService.priceForTicket(t.getId_ticket());
     407            price+=seatService.getSeatById(id_seat.intValue()).get().getCategory().getExtra_amount();
     408            t.setPrice(price);
     409        }
     410
    405411        return "redirect:/myTickets";
    406412    }
  • src/main/resources/templates/film.html

    r7215773 r8a18cf5  
    6262                <span>/5</span>
    6363            </h4>
     64            <th:block sec:authorize="hasAuthority('ROLE_USER')" th:if="${#request.getRemoteUser() != null}">
    6465            <form th:action="@{'/home/addRating/{id}' (id=${film.id_film})}"
    6566                  th:method="POST">
     
    7071                <button class="button" type="submit">Додади Оцена</button>
    7172            </form>
     73            </th:block>
    7274        </div>
    7375    <div class="slika">
Note: See TracChangeset for help on using the changeset viewer.