- Timestamp:
- 05/06/25 00:44:02 (12 days ago)
- Branches:
- main
- Children:
- e48199a
- Parents:
- 142c0f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.