| 1 | package edu.ucsb.cs156.dining.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.dining.services.UCSBDiningMenuItemsService; | |
| 4 | import edu.ucsb.cs156.dining.models.Entree; | |
| 5 | import edu.ucsb.cs156.dining.entities.MenuItem; | |
| 6 | import edu.ucsb.cs156.dining.repositories.MenuItemRepository; | |
| 7 | import java.util.Optional; | |
| 8 | import java.util.ArrayList; | |
| 9 | ||
| 10 | import edu.ucsb.cs156.dining.errors.EntityNotFoundException; | |
| 11 | ||
| 12 | import io.swagger.v3.oas.annotations.Operation; | |
| 13 | import io.swagger.v3.oas.annotations.Parameter; | |
| 14 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 15 | import lombok.extern.slf4j.Slf4j; | |
| 16 | ||
| 17 | import org.springframework.beans.factory.annotation.Autowired; | |
| 18 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 19 | import org.springframework.web.bind.annotation.GetMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestBody; | |
| 21 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestParam; | |
| 23 | import org.springframework.web.bind.annotation.RestController; | |
| 24 | import org.springframework.web.bind.annotation.PathVariable; | |
| 25 | import org.springframework.http.ResponseEntity; | |
| 26 | ||
| 27 | import java.util.List; | |
| 28 | ||
| 29 | import jakarta.validation.Valid; | |
| 30 | ||
| 31 | @Tag(name = "UCSBDiningMenuItems") | |
| 32 | @RestController | |
| 33 | @RequestMapping("/api/diningcommons") | |
| 34 | @Slf4j | |
| 35 | public class UCSBDiningMenuItemsController extends ApiController { | |
| 36 | ||
| 37 |   @Autowired UCSBDiningMenuItemsService ucsbDiningMenuItemsService; | |
| 38 |    | |
| 39 |   @Autowired | |
| 40 |   MenuItemRepository menuItemRepository; | |
| 41 | ||
| 42 |   @Operation(summary = "Get list of entrees being served at given meal, dining common, and day") | |
| 43 |   @GetMapping(value = "/{date-time}/{dining-commons-code}/{meal-code}", produces = "application/json") | |
| 44 |   public ResponseEntity<List<MenuItem>> get_menu_items( | |
| 45 |       @Parameter(description= "date (in iso format, e.g. YYYY-mm-dd) or date-time (in iso format e.g. YYYY-mm-ddTHH:MM:SS)")  | |
| 46 |       @PathVariable("date-time") String datetime, | |
| 47 |       @PathVariable("dining-commons-code") String diningcommoncode, | |
| 48 |       @PathVariable("meal-code") String mealcode | |
| 49 |   ) | |
| 50 |     throws Exception { | |
| 51 | ||
| 52 |     List<Entree> body = ucsbDiningMenuItemsService.get(datetime, diningcommoncode, mealcode); | |
| 53 | ||
| 54 |     List<MenuItem> menuitems = new ArrayList<>(); | |
| 55 | ||
| 56 |     for (Entree entree : body) { | |
| 57 |         Optional<MenuItem> exists = menuItemRepository.findByDiningCommonsCodeAndMealCodeAndNameAndStation(diningcommoncode, mealcode, entree.getName(), entree.getStation()); | |
| 58 | ||
| 59 |         MenuItem newMenuItem = exists.orElse(new MenuItem()); | |
| 60 | 
1
1. get_menu_items : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setDiningCommonsCode → KILLED | 
          newMenuItem.setDiningCommonsCode(diningcommoncode); | 
| 61 | 
1
1. get_menu_items : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setMealCode → KILLED | 
          newMenuItem.setMealCode(mealcode); | 
| 62 | 
1
1. get_menu_items : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setName → KILLED | 
          newMenuItem.setName(entree.getName()); | 
| 63 | 
1
1. get_menu_items : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setStation → KILLED | 
          newMenuItem.setStation(entree.getStation()); | 
| 64 | ||
| 65 |           menuItemRepository.save(newMenuItem); | |
| 66 |           menuitems.add(newMenuItem); | |
| 67 |     } | |
| 68 | ||
| 69 | 
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); | 
| 70 |   } | |
| 71 |   @Operation(summary = "Get a single specific menu item by id") | |
| 72 |   @GetMapping(value = "/menuitem", produces = "application/json") | |
| 73 |   public ResponseEntity<MenuItem> getMenuItemById( | |
| 74 |       @Parameter(description = "ID of the menu item") @RequestParam Long id | |
| 75 |   ) { | |
| 76 |     MenuItem menuItem = menuItemRepository.findById(id) | |
| 77 | 
1
1. lambda$getMenuItemById$0 : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningMenuItemsController::lambda$getMenuItemById$0 → KILLED | 
        .orElseThrow(() -> new EntityNotFoundException(MenuItem.class, id)); | 
| 78 | ||
| 79 | 
1
1. getMenuItemById : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningMenuItemsController::getMenuItemById → KILLED | 
    return ResponseEntity.ok().body(menuItem); | 
| 80 |   } | |
| 81 | } | |
Mutations | ||
| 60 | 
 
 1.1  | 
|
| 61 | 
 
 1.1  | 
|
| 62 | 
 
 1.1  | 
|
| 63 | 
 
 1.1  | 
|
| 69 | 
 
 1.1  | 
|
| 77 | 
 
 1.1  | 
|
| 79 | 
 
 1.1  |