- Timestamp:
- 02/28/24 18:44:19 (15 months ago)
- Branches:
- main
- Children:
- 75f5086
- Parents:
- d24f17c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/rezevirajmasa/demo/web/rest/testController.java
rd24f17c r65b6638 6 6 import com.example.rezevirajmasa.demo.service.RestaurantService; 7 7 import com.example.rezevirajmasa.demo.service.TableService; 8 import jdk.jfr.consumer.RecordingStream; 8 9 import org.apache.coyote.Response; 10 import org.springframework.format.annotation.DateTimeFormat; 9 11 import org.springframework.http.HttpStatus; 10 12 import org.springframework.http.ResponseEntity; … … 12 14 13 15 import java.time.LocalDateTime; 16 import java.time.format.DateTimeFormatter; 14 17 import java.util.List; 18 import java.util.Map; 15 19 16 20 @CrossOrigin(origins = "http://localhost:3000/") … … 34 38 } 35 39 40 //restaurants 41 36 42 @RequestMapping("/api/restaurants") 37 43 public ResponseEntity<List<Restaurant>> getAllRestaurants() { … … 42 48 public ResponseEntity<Restaurant> getRestaurantById(@PathVariable Long restaurantId) { 43 49 return new ResponseEntity<Restaurant>(restaurantService.findById(restaurantId), HttpStatus.OK); 50 } 51 52 @PostMapping("/api/search") 53 public ResponseEntity<List<Restaurant>> searchRestaurants(@RequestBody Map<String, Object> requestData) { 54 String dateTime = (String) requestData.get("dateTime"); 55 Integer partySize = (Integer) requestData.get("partySize"); 56 String search = (String) requestData.get("search"); 57 58 // Now proceed with parsing dateTime and performing the search based on the received parameters 59 60 LocalDateTime parsedDateTime = null; 61 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); 62 if (dateTime != null) { 63 parsedDateTime = LocalDateTime.parse(dateTime, formatter); 64 } 65 66 List<Restaurant> filteredRestaurants = restaurantService.findRestaurantsByDateTimeAndPartySize(parsedDateTime, partySize, search); 67 68 return new ResponseEntity<List<Restaurant>>(filteredRestaurants, HttpStatus.OK); 44 69 } 45 70
Note:
See TracChangeset
for help on using the changeset viewer.