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