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 org.springframework.web.bind.annotation.RequestParam; | |
27 | ||
28 | import java.util.List; | |
29 | ||
30 | import jakarta.validation.Valid; | |
31 | ||
32 | @Tag(name = "UCSBDiningMenuItems") | |
33 | @RestController | |
34 | @RequestMapping("/api/diningcommons") | |
35 | @Slf4j | |
36 | public class UCSBDiningMenuItemsController extends ApiController { | |
37 | ||
38 | @Autowired UCSBDiningMenuItemsService ucsbDiningMenuItemsService; | |
39 | | |
40 | @Autowired | |
41 | MenuItemRepository menuItemRepository; | |
42 | ||
43 | @Operation(summary = "Get list of entrees being served at given meal, dining common, and day") | |
44 | @GetMapping(value = "/{date-time}/{dining-commons-code}/{meal-code}", produces = "application/json") | |
45 | public ResponseEntity<List<MenuItem>> get_menu_items( | |
46 | @Parameter(description= "date (in iso format, e.g. YYYY-mm-dd) or date-time (in iso format e.g. YYYY-mm-ddTHH:MM:SS)") | |
47 | @PathVariable("date-time") String datetime, | |
48 | @PathVariable("dining-commons-code") String diningcommoncode, | |
49 | @PathVariable("meal-code") String mealcode | |
50 | ) | |
51 | throws Exception { | |
52 | ||
53 | List<Entree> body = ucsbDiningMenuItemsService.get(datetime, diningcommoncode, mealcode); | |
54 | ||
55 | List<MenuItem> menuitems = new ArrayList<>(); | |
56 | ||
57 | for (Entree entree : body) { | |
58 | Optional<MenuItem> exists = menuItemRepository.findByDiningCommonsCodeAndMealCodeAndNameAndStation(diningcommoncode, mealcode, entree.getName(), entree.getStation()); | |
59 | ||
60 | MenuItem newMenuItem = exists.orElse(new MenuItem()); | |
61 | // MenuItem newMenuItem = new MenuItem(); | |
62 |
1
1. get_menu_items : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setDiningCommonsCode → KILLED |
newMenuItem.setDiningCommonsCode(diningcommoncode); |
63 |
1
1. get_menu_items : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setMealCode → KILLED |
newMenuItem.setMealCode(mealcode); |
64 |
1
1. get_menu_items : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setName → KILLED |
newMenuItem.setName(entree.getName()); |
65 |
1
1. get_menu_items : removed call to edu/ucsb/cs156/dining/entities/MenuItem::setStation → KILLED |
newMenuItem.setStation(entree.getStation()); |
66 | ||
67 | menuItemRepository.save(newMenuItem); | |
68 | menuitems.add(newMenuItem); | |
69 | } | |
70 | ||
71 |
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); |
72 | } | |
73 | ||
74 | ||
75 | @Operation(summary = "Get a single menu item by id") | |
76 | @GetMapping(value = "/menuitem", produces = "application/json") | |
77 | public ResponseEntity<MenuItem> get_menu_item( | |
78 | @Parameter(description= "id of the menu item") | |
79 | @RequestParam Long id | |
80 | ) | |
81 | throws Exception { | |
82 | ||
83 | MenuItem menuItem = menuItemRepository.findById(id) | |
84 |
1
1. lambda$get_menu_item$0 : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningMenuItemsController::lambda$get_menu_item$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItem.class, id)); |
85 | ||
86 |
1
1. get_menu_item : replaced return value with null for edu/ucsb/cs156/dining/controllers/UCSBDiningMenuItemsController::get_menu_item → KILLED |
return ResponseEntity.ok().body(menuItem); |
87 | | |
88 | } | |
89 | } | |
Mutations | ||
62 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |
|
65 |
1.1 |
|
71 |
1.1 |
|
84 |
1.1 |
|
86 |
1.1 |