- Timestamp:
- 05/06/25 00:44:02 (12 days ago)
- Branches:
- main
- Children:
- e48199a
- Parents:
- 142c0f8
- Location:
- src
- Files:
-
- 5 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/rezevirajmasa/demo/config/ModelMapperConfig.java
r142c0f8 rb67dfd3 17 17 ModelMapper modelMapper = new ModelMapper(); 18 18 19 // Map Restaurant to RestaurantDTO20 19 modelMapper.typeMap(Restaurant.class, RestaurantDTO.class).addMappings(mapper -> { 21 20 mapper.map(Restaurant::getTablesList, RestaurantDTO::setTablesList); 22 21 }); 23 22 24 // Map TableEntity to TableDTO25 23 modelMapper.typeMap(TableEntity.class, TableDTO.class).addMappings(mapper -> { 26 24 mapper.map(TableEntity::getReservations, TableDTO::setReservations); 27 25 }); 28 26 29 // Map Reservation to ReservationDTO 30 modelMapper.typeMap(Reservation.class, ReservationDTO.class); 27 modelMapper.typeMap(Reservation.class, ReservationDTO.class).addMappings(mapper -> { 28 mapper.map(Reservation::getReservationStatus, ReservationDTO::setReservationStatus); 29 mapper.map(Reservation::getPaymentStatus, ReservationDTO::setPaymentStatus); 30 }); 31 31 32 32 return modelMapper; -
src/main/java/com/example/rezevirajmasa/demo/dto/ReservationDTO.java
r142c0f8 rb67dfd3 18 18 private Long restaurantId; 19 19 private int partySize; 20 private String status;20 private String reservationStatus; 21 21 private String specialRequests; 22 22 private String paymentStatus; … … 26 26 } 27 27 28 public ReservationDTO(Long reservationID, String userEmail, BigDecimal rating, Long tableNumber, LocalDateTime reservationDateTime, LocalDateTime checkInTime, Long restaurantId, int partySize, String status, String specialRequests, String paymentStatus, List<PreorderedItem> preOrderedItems) { 28 public ReservationDTO(Long reservationID, String userEmail, BigDecimal rating, Long tableNumber, 29 LocalDateTime reservationDateTime, LocalDateTime checkInTime, Long restaurantId, 30 int partySize, String reservationStatus, String specialRequests, 31 String paymentStatus, List<PreorderedItem> preOrderedItems) { 29 32 this.reservationID = reservationID; 30 33 this.userEmail = userEmail; … … 33 36 this.reservationDateTime = reservationDateTime; 34 37 this.checkInTime = checkInTime; 35 this.res ervationID= restaurantId;38 this.restaurantId = restaurantId; 36 39 this.partySize = partySize; 37 this. status = status;40 this.reservationStatus = reservationStatus; 38 41 this.specialRequests = specialRequests; 39 42 this.paymentStatus = paymentStatus; … … 50 53 this.restaurantId = reservation.getRestaurant().getRestaurantId(); 51 54 this.partySize = reservation.getPartySize(); 52 this. status = reservation.getStatus();55 this.reservationStatus = reservation.getReservationStatus(); 53 56 this.specialRequests = reservation.getSpecialRequests(); 54 57 this.paymentStatus = reservation.getPaymentStatus(); … … 121 124 122 125 public String getStatus() { 123 return status;126 return reservationStatus; 124 127 } 125 128 126 public void set Status(String status) {127 this. status = status;129 public void setReservationStatus(String reservationStatus) { 130 this.reservationStatus = reservationStatus; 128 131 } 129 132 -
src/main/java/com/example/rezevirajmasa/demo/dto/TableDTO.java
r142c0f8 rb67dfd3 23 23 } 24 24 25 // Getters and setters26 25 public Long getId() { 27 26 return id; -
src/main/java/com/example/rezevirajmasa/demo/mappers/UserMapperImpl.java
r142c0f8 rb67dfd3 19 19 20 20 UserDto userDto = new UserDto(); 21 userDto.setId(user.get Id());21 userDto.setId(user.getUserId()); 22 22 userDto.setFirstName(user.getFirstName()); 23 23 userDto.setLastName(user.getLastName()); … … 37 37 user.setFirstName(userDto.getFirstName()); 38 38 user.setLastName(userDto.getLastName()); 39 user.setPassword(Arrays.toString(userDto.getPassword())); // Assuming password is a char[] or string array.39 user.setPassword(Arrays.toString(userDto.getPassword())); 40 40 41 41 return user; … … 53 53 signUpDto.setLastName(userDto.getLastName()); 54 54 55 // Since SignUpDto has password field, you may set it if needed. 56 // Assuming a default value or handling empty password as required. 57 signUpDto.setPassword(new char[0]); // Empty password for now or assign actual value if required. 55 signUpDto.setPassword(new char[0]); 58 56 59 57 return signUpDto; … … 73 71 user.setAddress(userDto.getAddress()); 74 72 user.setEmail(userDto.getEmail()); 75 user.set Id(userDto.getId());73 user.setUserId(userDto.getId()); 76 74 77 75 return user; -
src/main/java/com/example/rezevirajmasa/demo/model/Menu.java
r142c0f8 rb67dfd3 26 26 private String itemName; 27 27 28 @Column(name = " category", length = 50)29 private String category;28 @Column(name = "menuCategory", length = 50) 29 private String menuCategory; 30 30 31 31 @Column(name = "price", precision = 8, scale = 2) … … 45 45 this.restaurant = restaurant; 46 46 this.itemName = itemName; 47 this. category = category;47 this.menuCategory = category; 48 48 this.price = price; 49 49 this.description = description; -
src/main/java/com/example/rezevirajmasa/demo/model/MenuTag.java
r142c0f8 rb67dfd3 11 11 @Id 12 12 @GeneratedValue(strategy = GenerationType.IDENTITY) 13 private Long id;13 private Long menuTagId; 14 14 15 15 @ManyToOne(fetch = FetchType.LAZY) -
src/main/java/com/example/rezevirajmasa/demo/model/PreorderedItem.java
r142c0f8 rb67dfd3 20 20 @Id 21 21 @GeneratedValue(strategy = GenerationType.IDENTITY) 22 private Long id;22 private Long preorderedItemId; 23 23 24 private String name;24 private String preorderedItemName; 25 25 26 26 private Integer quantity; -
src/main/java/com/example/rezevirajmasa/demo/model/Reservation.java
r142c0f8 rb67dfd3 48 48 49 49 @Column(name = "Status", length = 20, nullable = false) 50 private String status;50 private String reservationStatus; 51 51 52 52 @Column(name = "CheckInTime") … … 57 57 private LocalDateTime checkOutTime; 58 58 59 // @ElementCollection 60 // @CollectionTable(name = "reservation_preordered_items", joinColumns = @JoinColumn(name = "reservation_id")) 61 // @Column(name = "item") 62 // private List<String> preOrderedItems = new ArrayList<>(); 63 @OneToMany(mappedBy = "reservation", cascade = CascadeType.ALL, orphanRemoval = true) 59 @OneToMany(mappedBy = "reservation", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) 64 60 private List<PreorderedItem> preOrderedItems = new ArrayList<>(); 65 61 … … 73 69 @PrePersist 74 70 private void prePersist() { 75 if ( status == null) {76 status = "Pending";71 if (reservationStatus == null) { 72 reservationStatus = "Pending"; 77 73 } 78 74 if (paymentStatus == null) { … … 88 84 this.partySize = partySize; 89 85 this.specialRequests = specialRequests; 90 this. status = status;86 this.reservationStatus = status; 91 87 this.checkInTime = checkInTime; 92 88 this.checkOutTime = checkOutTime; … … 105 101 ", partySize=" + partySize + 106 102 ", specialRequests='" + specialRequests + '\'' + 107 ", status='" + status + '\'' +103 ", status='" + reservationStatus + '\'' + 108 104 ", checkInTime=" + checkInTime + 109 105 ", checkOutTime=" + checkOutTime + -
src/main/java/com/example/rezevirajmasa/demo/model/Restaurant.java
r142c0f8 rb67dfd3 146 146 @Id 147 147 @GeneratedValue(strategy = GenerationType.IDENTITY) 148 private Long id;148 private Long reservationHistoryId; 149 149 150 150 @ManyToOne … … 170 170 171 171 @Column(name = "status") 172 private String status;172 private String reservationStatus; 173 173 174 174 @Column(name = "cancellation_reason") … … 185 185 this.partySize = partySize; 186 186 this.specialRequests = specialRequests; 187 this. status = status;187 this.reservationStatus = status; 188 188 this.cancellationReason = cancellationReason; 189 189 this.checkInDate = checkInDate; … … 194 194 195 195 public Long getId() { 196 return id;196 return reservationHistoryId; 197 197 } 198 198 199 199 public void setId(Long id) { 200 this. id = id;200 this.reservationHistoryId = id; 201 201 } 202 202 … … 242 242 243 243 public String getStatus() { 244 return status;244 return reservationStatus; 245 245 } 246 246 247 247 public void setStatus(String status) { 248 this. status = status;248 this.reservationStatus = status; 249 249 } 250 250 … … 276 276 public String toString() { 277 277 return "ReservationHistory{" + 278 "id=" + id +278 "id=" + reservationHistoryId + 279 279 ", user=" + user + 280 280 ", table=" + table + … … 283 283 ", partySize=" + partySize + 284 284 ", specialRequests='" + specialRequests + '\'' + 285 ", status='" + status + '\'' +285 ", status='" + reservationStatus + '\'' + 286 286 ", cancellationReason='" + cancellationReason + '\'' + 287 287 ", checkInDate=" + checkInDate + -
src/main/java/com/example/rezevirajmasa/demo/model/TableEntity.java
r142c0f8 rb67dfd3 36 36 private int capacity; 37 37 38 @Column(name = " Location")39 private String location;38 @Column(name = "tableLocation") 39 private String tableLocation; 40 40 41 41 @Column(name = "IsSmokingArea") … … 95 95 this.restaurant = restaurant; 96 96 this.capacity = capacity; 97 this. location = location;97 this.tableLocation = location; 98 98 this.isSmokingArea = isSmokingArea; 99 99 this.description = description; -
src/main/java/com/example/rezevirajmasa/demo/model/User.java
r142c0f8 rb67dfd3 21 21 @Id 22 22 @GeneratedValue(strategy = GenerationType.IDENTITY) 23 private Long id;23 private Long userId; 24 24 25 25 @Column(name = "first_name") -
src/main/java/com/example/rezevirajmasa/demo/repository/ReservationHistoryRepository.java
r142c0f8 rb67dfd3 1 1 package com.example.rezevirajmasa.demo.repository; 2 2 3 import com.example.rezevirajmasa.demo.model.Customer;4 import com.example.rezevirajmasa.demo.model.Reservation;5 3 import com.example.rezevirajmasa.demo.model.Restaurant; 6 4 import com.example.rezevirajmasa.demo.model.User; 7 import org.springframework.cglib.core.Local;8 5 import org.springframework.data.jpa.repository.JpaRepository; 9 6 … … 13 10 public interface ReservationHistoryRepository extends JpaRepository<Restaurant.ReservationHistory, Long> { 14 11 List<Restaurant.ReservationHistory> findALlByUser(User user); 15 List<Restaurant.ReservationHistory> findByCheckInDateBeforeAndStatus(LocalDateTime currentTime, String scheduled);16 12 List<Restaurant.ReservationHistory> findAllByCheckInDateBefore(LocalDateTime currentTime); 17 13 } -
src/main/java/com/example/rezevirajmasa/demo/service/ReservationHistoryService.java
r142c0f8 rb67dfd3 1 1 package com.example.rezevirajmasa.demo.service; 2 2 3 import com.example.rezevirajmasa.demo.model.Customer;4 3 import com.example.rezevirajmasa.demo.model.Reservation; 5 4 import com.example.rezevirajmasa.demo.model.Restaurant; -
src/main/java/com/example/rezevirajmasa/demo/service/impl/ReservationHistoryServiceImpl.java
r142c0f8 rb67dfd3 1 1 package com.example.rezevirajmasa.demo.service.impl; 2 2 3 import com.example.rezevirajmasa.demo.model.Customer;4 3 import com.example.rezevirajmasa.demo.model.Reservation; 5 4 import com.example.rezevirajmasa.demo.model.Restaurant; -
src/main/java/com/example/rezevirajmasa/demo/service/impl/ReservationImpl.java
r142c0f8 rb67dfd3 2 2 3 3 import com.example.rezevirajmasa.demo.dto.ReservationDTO; 4 import com.example.rezevirajmasa.demo.dto.RestaurantDTO;5 import com.example.rezevirajmasa.demo.dto.UserDto;6 4 import com.example.rezevirajmasa.demo.mappers.UserMapper; 7 5 import com.example.rezevirajmasa.demo.model.*; 8 6 import com.example.rezevirajmasa.demo.model.exceptions.InvalidReservationException; 9 7 import com.example.rezevirajmasa.demo.model.exceptions.InvalidReservationIdException; 10 import com.example.rezevirajmasa.demo.repository.CustomerRepository;11 8 import com.example.rezevirajmasa.demo.repository.ReservationRepository; 12 import com.example.rezevirajmasa.demo.repository.RestaurantRepository;13 9 import com.example.rezevirajmasa.demo.repository.TableRepository; 14 10 import com.example.rezevirajmasa.demo.service.ReservationHistoryService; 15 11 import com.example.rezevirajmasa.demo.service.ReservationService; 16 import com.example.rezevirajmasa.demo.service.RestaurantService;17 12 import com.example.rezevirajmasa.demo.service.UserService; 18 13 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.cglib.core.Local;20 import org.springframework.security.core.Authentication;21 import org.springframework.security.core.annotation.AuthenticationPrincipal;22 import org.springframework.security.core.context.SecurityContextHolder;23 import org.springframework.security.core.userdetails.UserDetails;24 14 import org.springframework.stereotype.Service; 25 import org.springframework.web.bind.annotation.RequestBody; 26 27 import javax.swing.text.html.Option; 28 import java.math.BigDecimal; 15 29 16 import java.time.LocalDateTime; 30 import java.time.LocalTime;31 import java.time.format.DateTimeFormatter;32 17 import java.util.ArrayList; 33 18 import java.util.List; … … 91 76 reservation.setSpecialRequests(reservationDTO.getSpecialRequests()); 92 77 reservation.setPartySize(reservationDTO.getPartySize()); 93 reservation.set Status(reservationDTO.getStatus() != null ? reservationDTO.getStatus() : "Pending");78 reservation.setReservationStatus(reservationDTO.getStatus() != null ? reservationDTO.getStatus() : "Pending"); 94 79 reservation.setPaymentStatus(reservationDTO.getPaymentStatus() != null ? reservationDTO.getPaymentStatus() : "Unpaid"); 95 80 reservation.setUser(user); … … 99 84 for (PreorderedItem dtoItem : reservationDTO.getPreOrderedItems()) { 100 85 PreorderedItem item = new PreorderedItem(); 101 item.set Name(dtoItem.getName());86 item.setPreorderedItemName(dtoItem.getPreorderedItemName()); 102 87 item.setQuantity(dtoItem.getQuantity()); 103 88 item.setPrice(dtoItem.getPrice()); … … 144 129 existingReservation.setPartySize(reservationDTO.getPartySize()); 145 130 existingReservation.setSpecialRequests(reservationDTO.getSpecialRequests()); 146 existingReservation.set Status(reservationDTO.getStatus() != null ? reservationDTO.getStatus() : existingReservation.getStatus());131 existingReservation.setReservationStatus(reservationDTO.getStatus() != null ? reservationDTO.getStatus() : existingReservation.getReservationStatus()); 147 132 existingReservation.setPaymentStatus(reservationDTO.getPaymentStatus() != null ? reservationDTO.getPaymentStatus() : existingReservation.getPaymentStatus()); 148 133 -
src/main/java/com/example/rezevirajmasa/demo/service/impl/RestaurantServiceImpl.java
r142c0f8 rb67dfd3 104 104 TableEntity table = new TableEntity(); 105 105 table.setCapacity(tableCapacities.get(i)); 106 table.set Location(tableLocations.get(i));106 table.setTableLocation(tableLocations.get(i)); 107 107 table.setSmokingArea(tableSmokingAreas.get(i).equalsIgnoreCase("on")); 108 108 table.setDescription(tableDescriptions.get(i)); -
src/main/java/com/example/rezevirajmasa/demo/service/impl/TableServiceImpl.java
r142c0f8 rb67dfd3 76 76 TableEntity table = new TableEntity(); 77 77 table.setCapacity(tableCapacities.get(i)); 78 table.set Location(tableLocations.get(i));78 table.setTableLocation(tableLocations.get(i)); 79 79 table.setSmokingArea(Boolean.valueOf(tableSmokingAreas.get(i))); 80 80 table.setDescription(tableDescriptions.get(i)); -
src/main/java/com/example/rezevirajmasa/demo/service/impl/UserServiceImpl.java
r142c0f8 rb67dfd3 16 16 import org.openqa.selenium.InvalidArgumentException; 17 17 import org.springframework.http.HttpStatus; 18 import org.springframework.security.core.userdetails.UserDetails; 19 import org.springframework.security.core.userdetails.UserDetailsService; 20 import org.springframework.security.core.userdetails.UsernameNotFoundException; 18 21 import org.springframework.security.crypto.password.PasswordEncoder; 19 22 import org.springframework.stereotype.Service; … … 25 28 @RequiredArgsConstructor 26 29 @Service 27 public class UserServiceImpl implements UserService {30 public class UserServiceImpl implements UserService, UserDetailsService { 28 31 private final UserRepository userRepository; 29 32 private final UserMapperImpl userMapper; … … 78 81 return userRepository.findById(userId).orElseThrow(()->new InvalidArgumentException("Invalid user Id")); 79 82 } 83 84 @Override 85 public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { 86 User user = userRepository.findByEmail(email) 87 .orElseThrow(()-> new UsernameNotFoundException("User not found")); 88 return org.springframework.security.core.userdetails.User 89 .withUsername(user.getEmail()) 90 .password(user.getPassword()) 91 .authorities(user.getRole().name()) // adjust if needed 92 .build(); 93 } 80 94 } -
src/main/java/com/example/rezevirajmasa/demo/web/controller/ReservationHistoryController.java
r142c0f8 rb67dfd3 4 4 import com.example.rezevirajmasa.demo.dto.UserDto; 5 5 import com.example.rezevirajmasa.demo.mappers.UserMapper; 6 import com.example.rezevirajmasa.demo.model.Customer;7 6 import com.example.rezevirajmasa.demo.model.Restaurant; 8 import com.example.rezevirajmasa.demo.model.Role;9 7 import com.example.rezevirajmasa.demo.model.User; 10 import com.example.rezevirajmasa.demo.service.CustomerService;11 8 import com.example.rezevirajmasa.demo.service.ReservationHistoryService; 12 9 import com.example.rezevirajmasa.demo.service.UserService; -
src/main/java/com/example/rezevirajmasa/demo/web/rest/AuthController.java
r142c0f8 rb67dfd3 5 5 import com.example.rezevirajmasa.demo.dto.SignUpDto; 6 6 import com.example.rezevirajmasa.demo.dto.UserDto; 7 import com.example.rezevirajmasa.demo.model.Customer;8 import com.example.rezevirajmasa.demo.service.CustomerService;9 7 import com.example.rezevirajmasa.demo.service.UserService; 10 8 import lombok.RequiredArgsConstructor; 11 import org.apache.coyote.Response;12 import org.springframework.beans.factory.annotation.Autowired;13 import org.springframework.http.HttpStatus;14 9 import org.springframework.http.ResponseEntity; 15 import org.springframework.security.authentication.AuthenticationManager;16 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;17 import org.springframework.security.core.Authentication;18 import org.springframework.security.crypto.password.PasswordEncoder;19 import org.springframework.web.bind.annotation.CrossOrigin;20 10 import org.springframework.web.bind.annotation.PostMapping; 21 11 import org.springframework.web.bind.annotation.RequestBody; -
src/main/java/com/example/rezevirajmasa/demo/web/rest/testController.java
r142c0f8 rb67dfd3 32 32 public class testController { 33 33 private final RestaurantService restaurantService; 34 private final CustomerService customerService;35 34 private final UserService userService; 36 35 private final ReservationService reservationService; … … 40 39 private final UserMapper userMapper; 41 40 private final TokenService tokenService; 42 public testController(RestaurantService restaurantService, CustomerService customerService,UserService userService, ReservationService reservationService, ReservationHistoryService reservationHistoryService, TableService tableService, MenuService menuService, UserMapper userMapper, TokenService tokenService) {41 public testController(RestaurantService restaurantService, UserService userService, ReservationService reservationService, ReservationHistoryService reservationHistoryService, TableService tableService, MenuService menuService, UserMapper userMapper, TokenService tokenService) { 43 42 this.restaurantService = restaurantService; 44 this.customerService = customerService;45 43 this.userService = userService; 46 44 this.reservationService = reservationService; … … 115 113 } 116 114 117 // Customer CALLS118 119 @GetMapping("/api/customers")120 public ResponseEntity<List<CustomerDTO>> getAllCustomers() {121 List<Customer> customers = customerService.listAll();122 List<CustomerDTO> dtos = new ArrayList<>();123 for(Customer customer : customers) {124 CustomerDTO dto = customerService.mapCustomerToDTO(customer);125 dtos.add(dto);126 }127 return new ResponseEntity<List<CustomerDTO>>(dtos, HttpStatus.OK);128 }129 130 @GetMapping("/api/customers/{id}")131 public ResponseEntity<Customer> getCustomerById(@PathVariable Long id) {132 return new ResponseEntity<Customer>(customerService.findById(id), HttpStatus.OK);133 }134 @PutMapping("/api/customers/edit/{id}")135 public ResponseEntity<Customer> editCustomerById(@PathVariable Long id, @RequestBody Customer customer) {136 return new ResponseEntity<Customer>(137 customerService.updateCustomer(id, customer.getFirstName(), customer.getLastName(), customer.getEmail(), customer.getPassword(), customer.getPhone(), customer.getAddress(), customer.getMembershipLevel()),138 HttpStatus.OK139 );140 }141 142 @PostMapping("/api/customers")143 public ResponseEntity<Customer> saveCustomer(@RequestBody Customer customer) {144 // Ensure that the role is set to ROLE_USER by default145 customer.setRole(Role.ROLE_USER);146 return new ResponseEntity<Customer>(147 customerService.registration(customer),148 HttpStatus.OK149 );150 }151 152 @DeleteMapping("/api/customers/delete/{customerId}")153 public ResponseEntity<Response> deleteCustomer(@PathVariable Long customerId) {154 boolean deleted = customerService.deleteById(customerId);155 if(deleted) {156 return ResponseEntity.ok().build();157 } else {158 return ResponseEntity.notFound().build();159 }160 }161 162 115 // Reservation Calls 163 116 -
src/test/java/com/example/rezevirajmasa/demo/CustomerRepositoryTests.java
r142c0f8 rb67dfd3 1 1 package com.example.rezevirajmasa.demo; 2 2 3 import com.example.rezevirajmasa.demo.model.Customer;4 3 import com.example.rezevirajmasa.demo.model.MembershipLevel; 5 4 import com.example.rezevirajmasa.demo.model.exceptions.InvalidCustomerIdException; 6 import com.example.rezevirajmasa.demo.repository.CustomerRepository;7 5 8 6 import org.assertj.core.api.Assertions; -
src/test/java/com/example/rezevirajmasa/demo/TableRepositoryTests.java
r142c0f8 rb67dfd3 22 22 tableEntity.setDescription("Romantic spot"); 23 23 tableEntity.setSmokingArea(true); 24 tableEntity.set Location("Big blue");24 tableEntity.setTableLocation("Big blue"); 25 25 26 26 TableEntity savedTable = tableRepository.save(tableEntity);
Note:
See TracChangeset
for help on using the changeset viewer.