Ignore:
Timestamp:
01/19/25 23:18:37 (4 months ago)
Author:
Aleksandar Panovski <apano77@…>
Branches:
main
Children:
f5b256e
Parents:
db39d9e
Message:

Done with stupid timeslots

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/rezevirajmasa/demo/service/impl/ReservationImpl.java

    rdb39d9e r8ca35dc  
    11package com.example.rezevirajmasa.demo.service.impl;
    22
    3 import com.example.rezevirajmasa.demo.model.Customer;
    4 import com.example.rezevirajmasa.demo.model.Reservation;
    5 import com.example.rezevirajmasa.demo.model.Restaurant;
    6 import com.example.rezevirajmasa.demo.model.TableEntity;
     3import com.example.rezevirajmasa.demo.dto.UserDto;
     4import com.example.rezevirajmasa.demo.mappers.UserMapper;
     5import com.example.rezevirajmasa.demo.model.*;
    76import com.example.rezevirajmasa.demo.model.exceptions.InvalidReservationException;
    87import com.example.rezevirajmasa.demo.model.exceptions.InvalidReservationIdException;
     
    1110import com.example.rezevirajmasa.demo.repository.RestaurantRepository;
    1211import com.example.rezevirajmasa.demo.repository.TableRepository;
     12import com.example.rezevirajmasa.demo.service.ReservationHistoryService;
    1313import com.example.rezevirajmasa.demo.service.ReservationService;
     14import com.example.rezevirajmasa.demo.service.UserService;
    1415import org.springframework.beans.factory.annotation.Autowired;
     16import org.springframework.cglib.core.Local;
     17import org.springframework.security.core.Authentication;
     18import org.springframework.security.core.annotation.AuthenticationPrincipal;
     19import org.springframework.security.core.context.SecurityContextHolder;
     20import org.springframework.security.core.userdetails.UserDetails;
    1521import org.springframework.stereotype.Service;
     22import org.springframework.web.bind.annotation.RequestBody;
    1623
    1724import javax.swing.text.html.Option;
     
    2734    private TableRepository tableRepository;
    2835    @Autowired
    29     private RestaurantRepository restaurantRepository;
     36    private ReservationHistoryService reservationHistoryService;
     37    private final UserMapper userMapper;
    3038    @Autowired
    31     private CustomerRepository customerRepository;
     39    private UserService userService;
    3240    @Autowired
    3341    private ReservationRepository reservationRepository;
     42
     43    public ReservationImpl(UserMapper userMapper) {
     44        this.userMapper = userMapper;
     45    }
    3446
    3547    @Override
     
    3951
    4052    @Override
    41     public void makeReservation(Customer customer, TableEntity table, Restaurant restaurant, LocalDateTime localDateTime, LocalDateTime checkInTime, int partySize, String specialRequests) {
     53    public void makeReservation(User user, TableEntity table, Restaurant restaurant, LocalDateTime localDateTime, LocalDateTime checkInTime, int partySize, String specialRequests) {
    4254        if (!table.isAvailable(checkInTime)) {
    4355            // Handle unavailability (throw an exception, return a specific response, etc.)
     
    4658
    4759        Reservation reservation =
    48                 new Reservation(customer, table, restaurant, LocalDateTime.now(), partySize, specialRequests, "Reserved", checkInTime, checkInTime.plusHours(2), null);
     60                new Reservation(user, table, restaurant, LocalDateTime.now(), partySize, specialRequests, "Reserved", checkInTime, checkInTime.plusHours(2), null);
    4961
    5062//        // Update table status or perform additional logic if needed
     
    5668
    5769    @Override
    58     public Reservation makeReservationRest(Reservation reservation) {
     70    public Reservation makeReservationRest(Reservation reservation, User user) {
    5971        Optional<TableEntity> optionalTable = tableRepository.findById(reservation.getTable().getId());
    60         if(optionalTable.isPresent()) {
     72        if (optionalTable.isPresent()) {
    6173            TableEntity table = optionalTable.get();
     74
     75            reservation.setUser(user);
    6276
    6377            LocalDateTime startTime = reservation.getCheckInTime().minusHours(2);
     
    6781                    x -> x.isAfter(startTime) && x.isBefore(endTime)
    6882            );
    69 
     83            reservation.setReservationDateTime(LocalDateTime.now());
    7084            return reservationRepository.save(reservation);
    7185        } else {
    72             throw new InvalidReservationException("Unsuccessful reservation -> time slot not avalaible");
     86            throw new InvalidReservationException("Unsuccessful reservation -> time slot not available");
    7387        }
    7488    }
     89
    7590
    7691    @Override
     
    109124                from = from.plusMinutes(15);
    110125            }
     126            reservationHistoryService.moveReservationToHistory(reservation, "Canceled", "Canceled by user");
    111127            reservationRepository.delete(reservation);
    112             return true; // Return true indicating successful cancellation
     128            return true;
    113129        } else {
    114             return false; // Return false indicating reservation with the given ID not found
     130            return false;
    115131        }
    116132    }
     
    118134
    119135    @Override
    120     public List<Reservation> findReservationByCustomer(Customer customer) {
    121         return reservationRepository.findAllByCustomer(customer);
     136    public List<Reservation> findReservationByUser(User user) {
     137        LocalDateTime now = LocalDateTime.now();
     138        return reservationRepository.findALlByUserAndCheckInTimeAfter(user, now);
     139    }
     140
     141    @Override
     142    public List<Reservation> findReservationsByUserPast(User user) {
     143        LocalDateTime now = LocalDateTime.now();
     144        return reservationRepository.findALlByUserAndCheckInTimeBefore(user, now);
    122145    }
    123146
Note: See TracChangeset for help on using the changeset viewer.