| 1 | package edu.ucsb.cs156.dining.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.dining.entities.MenuItem; | |
| 4 | import edu.ucsb.cs156.dining.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.dining.models.Entree; | |
| 6 | import edu.ucsb.cs156.dining.models.MenuItemSummary; | |
| 7 | import edu.ucsb.cs156.dining.repositories.MenuItemRepository; | |
| 8 | import edu.ucsb.cs156.dining.services.UCSBDiningMenuItemsService; | |
| 9 | import edu.ucsb.cs156.dining.statuses.ModerationStatus; | |
| 10 | import io.swagger.v3.oas.annotations.Operation; | |
| 11 | import io.swagger.v3.oas.annotations.Parameter; | |
| 12 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 13 | import java.util.List; | |
| 14 | import java.util.Optional; | |
| 15 | import lombok.extern.slf4j.Slf4j; | |
| 16 | import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | import org.springframework.http.ResponseEntity; | |
| 18 | import org.springframework.web.bind.annotation.GetMapping; | |
| 19 | import org.springframework.web.bind.annotation.PathVariable; | |
| 20 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 21 | import org.springframework.web.bind.annotation.RequestParam; | |
| 22 | import org.springframework.web.bind.annotation.RestController; | |
| 23 | ||
| 24 | @Tag(name = "UCSBDiningMenuItems") | |
| 25 | @RestController | |
| 26 | @RequestMapping("/api/diningcommons") | |
| 27 | @Slf4j | |
| 28 | public class UCSBDiningMenuItemsController extends ApiController { | |
| 29 | ||
| 30 | @Autowired UCSBDiningMenuItemsService ucsbDiningMenuItemsService; | |
| 31 | ||
| 32 | @Autowired MenuItemRepository menuItemRepository; | |
| 33 | ||
| 34 | @Operation(summary = "Get list of entrees being served at given meal, dining common, and day") | |
| 35 | @GetMapping( | |
| 36 | value = "/{date-time}/{dining-commons-code}/{meal-code}", | |
| 37 | produces = "application/json") | |
| 38 | public ResponseEntity<List<MenuItem>> get_menu_items( | |
| 39 | @Parameter( | |
| 40 | description = | |
| 41 | "date (in iso format, e.g. YYYY-mm-dd) or date-time (in iso format e.g. YYYY-mm-ddTHH:MM:SS)") | |
| 42 | @PathVariable("date-time") | |
| 43 | String datetime, | |
| 44 | @PathVariable("dining-commons-code") String diningCommonsCode, | |
| 45 | @PathVariable("meal-code") String mealCode) | |
| 46 | throws Exception { | |
| 47 | ||
| 48 | List<Entree> body = ucsbDiningMenuItemsService.get(datetime, diningCommonsCode, mealCode); | |
| 49 | ||
| 50 | List<MenuItem> menuItems = | |
| 51 | ucsbDiningMenuItemsService.getOrCreateMenuItems(diningCommonsCode, mealCode, body); | |
| 52 | ||
| 53 |
1
1. get_menu_items : removed call to java/util/List::forEach → KILLED |
menuItems.forEach( |
| 54 | (item) -> { | |
| 55 |
1
1. lambda$get_menu_items$0 : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setReviews → KILLED |
item.setReviews( |
| 56 | item.getReviews().stream() | |
| 57 |
2
1. lambda$get_menu_items$1 : replaced boolean return with true for edu/ucsb/cs156/dining/controllers/UCSBDiningMenuItemsController::lambda$get_menu_items$1 → KILLED 2. lambda$get_menu_items$1 : negated conditional → KILLED |
.filter((review) -> review.getStatus() == ModerationStatus.APPROVED) |
| 58 | .toList()); | |
| 59 | }); | |
| 60 |
1
1. get_menu_items : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningMenuItemsController::get_menu_items → KILLED |
return ResponseEntity.ok().body(menuItems); |
| 61 | } | |
| 62 | ||
| 63 | @Operation(summary = "Get a single menu item by ID (without its reviews)") | |
| 64 | @GetMapping(value = "/menuitem", produces = "application/json") | |
| 65 | public ResponseEntity<MenuItemSummary> get_menu_item_by_id( | |
| 66 | @Parameter(description = "ID of the menu item") @RequestParam long id) throws Exception { | |
| 67 | Optional<MenuItem> menuItem = menuItemRepository.findById(id); | |
| 68 |
1
1. get_menu_item_by_id : negated conditional → KILLED |
if (menuItem.isEmpty()) { |
| 69 | throw new EntityNotFoundException(MenuItem.class, id); | |
| 70 | } | |
| 71 |
1
1. get_menu_item_by_id : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningMenuItemsController::get_menu_item_by_id → KILLED |
return ResponseEntity.ok().body(MenuItemSummary.from(menuItem.get())); |
| 72 | } | |
| 73 | ||
| 74 | @Operation( | |
| 75 | summary = | |
| 76 | "Search menu items by name (case-insensitive substring match); returns at most 20 results") | |
| 77 | @GetMapping(value = "/menuitem/search", produces = "application/json") | |
| 78 | public ResponseEntity<List<MenuItemSummary>> search_menu_items( | |
| 79 | @Parameter(description = "text to search for in menu item names") @RequestParam | |
| 80 | String query) { | |
| 81 | String trimmed = query.trim(); | |
| 82 |
1
1. search_menu_items : negated conditional → KILLED |
if (trimmed.isEmpty()) { |
| 83 |
1
1. search_menu_items : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningMenuItemsController::search_menu_items → KILLED |
return ResponseEntity.ok().body(List.of()); |
| 84 | } | |
| 85 | List<MenuItemSummary> results = | |
| 86 | menuItemRepository | |
| 87 | .findTop20ByNameContainingIgnoreCaseOrderByNameAscDiningCommonsCodeAsc(trimmed) | |
| 88 | .stream() | |
| 89 | .map(MenuItemSummary::from) | |
| 90 | .toList(); | |
| 91 |
1
1. search_menu_items : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningMenuItemsController::search_menu_items → KILLED |
return ResponseEntity.ok().body(results); |
| 92 | } | |
| 93 | } | |
Mutations | ||
| 53 |
1.1 |
|
| 55 |
1.1 |
|
| 57 |
1.1 2.2 |
|
| 60 |
1.1 |
|
| 68 |
1.1 |
|
| 71 |
1.1 |
|
| 82 |
1.1 |
|
| 83 |
1.1 |
|
| 91 |
1.1 |