MenuItemController.java

1
package edu.ucsb.cs156.dining.controllers;
2
3
import edu.ucsb.cs156.dining.dto.MenuItemDTO;
4
import edu.ucsb.cs156.dining.services.MenuItemService;
5
import io.swagger.v3.oas.annotations.Operation;
6
import io.swagger.v3.oas.annotations.tags.Tag;
7
import lombok.extern.slf4j.Slf4j;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.security.access.prepost.PreAuthorize;
10
import org.springframework.web.bind.annotation.GetMapping;
11
import org.springframework.web.bind.annotation.PathVariable;
12
import io.swagger.v3.oas.annotations.Parameter;
13
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RestController;
15
16
import java.time.LocalDateTime;
17
import java.util.List;
18
19
/**
20
 * Controller for MenuItem
21
 */
22
@Tag(name = "MenuItem")
23
@RestController
24
@RequestMapping("/api/diningcommons")
25
@Slf4j
26
public class MenuItemController {
27
28
  @Autowired
29
  private MenuItemService menuItemService;
30
31
  /**
32
   * Endpoint to fetch all menu items for a specific dining commons, meal, and date.
33
   * The endpoint saves each menu item in the database and returns their ids, names, and stations.
34
   *
35
   * @param dateTime          the date as ISO 8601 string (e.g., "2024-11-24T00:00:00")
36
   * @param diningCommonsCode the code for the dining commons
37
   * @param meal              the meal code (e.g., "breakfast", "lunch", "dinner")
38
   * @return a list of MenuItemDTO containing id, name, and station
39
   */
40
  @Operation(summary = "Get menu items for a specific dining commons, meal, and date")
41
  @PreAuthorize("hasRole('ROLE_USER')")
42
  @GetMapping("/{dateTime}/{diningCommonsCode}/{meal}")
43
  public List<MenuItemDTO> getMenuItems(
44
      @Parameter(description = "ISO date and time (e.g., 2024-11-24T00:00:00)")
45
      @PathVariable LocalDateTime dateTime,
46
      @PathVariable String diningCommonsCode,
47
      @PathVariable String meal) {
48
    log.info("Fetching menu items for date: {}, dining commons: {}, meal: {}", dateTime, diningCommonsCode, meal);
49 1 1. getMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/dining/controllers/MenuItemController::getMenuItems → KILLED
    return menuItemService.getMenuItems(dateTime, diningCommonsCode, meal);
50
  }
51
}

Mutations

49

1.1
Location : getMenuItems
Killed by : edu.ucsb.cs156.dining.controllers.MenuItemControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.MenuItemControllerTest]/[method:testGetMenuItems_Success()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/dining/controllers/MenuItemController::getMenuItems → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0