| 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.RestController; | |
| 23 | import org.springframework.web.bind.annotation.PathVariable; | |
| 24 | import org.springframework.http.ResponseEntity; | |
| 25 | ||
| 26 | import java.util.List; | |
| 27 | ||
| 28 | import jakarta.validation.Valid; | |
| 29 | ||
| 30 | @Tag(name = "UCSBDiningMenuItems") | |
| 31 | @RestController | |
| 32 | @RequestMapping("/api/diningcommons") | |
| 33 | @Slf4j | |
| 34 | public class UCSBDiningMenuItemsController extends ApiController { | |
| 35 | ||
| 36 | @Autowired UCSBDiningMenuItemsService ucsbDiningMenuItemsService; | |
| 37 | | |
| 38 | @Autowired | |
| 39 | MenuItemRepository menuItemRepository; | |
| 40 | ||
| 41 | @Operation(summary = "Get list of entrees being served at given meal, dining common, and day") | |
| 42 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 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 | // MenuItem newMenuItem = new MenuItem(); | |
| 61 |
1
1. get_menu_items : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setDiningCommonsCode → KILLED |
newMenuItem.setDiningCommonsCode(diningcommoncode); |
| 62 |
1
1. get_menu_items : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setMealCode → KILLED |
newMenuItem.setMealCode(mealcode); |
| 63 |
1
1. get_menu_items : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setName → KILLED |
newMenuItem.setName(entree.getName()); |
| 64 |
1
1. get_menu_items : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setStation → KILLED |
newMenuItem.setStation(entree.getStation()); |
| 65 | ||
| 66 | menuItemRepository.save(newMenuItem); | |
| 67 | menuitems.add(newMenuItem); | |
| 68 | } | |
| 69 | ||
| 70 |
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); |
| 71 | } | |
| 72 | } | |
Mutations | ||
| 61 |
1.1 |
|
| 62 |
1.1 |
|
| 63 |
1.1 |
|
| 64 |
1.1 |
|
| 70 |
1.1 |