UCSBDiningCommonsMenuItemController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBDiningCommonsMenuItem;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsMenuItemRepository;
6
import io.swagger.v3.oas.annotations.Operation;
7
import io.swagger.v3.oas.annotations.Parameter;
8
import io.swagger.v3.oas.annotations.tags.Tag;
9
import jakarta.validation.Valid;
10
import lombok.extern.slf4j.Slf4j;
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.security.access.prepost.PreAuthorize;
13
import org.springframework.web.bind.annotation.DeleteMapping;
14
import org.springframework.web.bind.annotation.GetMapping;
15
import org.springframework.web.bind.annotation.PostMapping;
16
import org.springframework.web.bind.annotation.PutMapping;
17
import org.springframework.web.bind.annotation.RequestBody;
18
import org.springframework.web.bind.annotation.RequestMapping;
19
import org.springframework.web.bind.annotation.RequestParam;
20
import org.springframework.web.bind.annotation.RestController;
21
22
/** REST controller for UCSB Dining Commons menu items. */
23
@Tag(name = "UCSBDiningCommonsMenuItem")
24
@RequestMapping("/api/UCSBDiningCommonsMenuItem")
25
@RestController
26
@Slf4j
27
public class UCSBDiningCommonsMenuItemController extends ApiController {
28
  @Autowired UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository;
29
30
  /**
31
   * List all UCSB Dining Commons menu items.
32
   *
33
   * @return an iterable of UCSBDiningCommonsMenuItem
34
   */
35
  @Operation(summary = "List all UCSB Dining Commons menu items")
36
  @PreAuthorize("hasRole('ROLE_USER')")
37
  @GetMapping("/all")
38
  public Iterable<UCSBDiningCommonsMenuItem> allMenuItems() {
39
    Iterable<UCSBDiningCommonsMenuItem> items = ucsbDiningCommonsMenuItemRepository.findAll();
40 1 1. allMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allMenuItems → KILLED
    return items;
41
  }
42
43
  /** Create a new UCSB Dining Commons menu item. */
44
  @Operation(summary = "Create a new UCSB Dining Commons menu item")
45
  @PreAuthorize("hasRole('ROLE_ADMIN')")
46
  @PostMapping("/post")
47
  public UCSBDiningCommonsMenuItem postMenuItem(
48
      @Parameter(name = "diningCommonsCode") @RequestParam String diningCommonsCode,
49
      @Parameter(name = "name") @RequestParam String name,
50
      @Parameter(name = "station") @RequestParam String station) {
51
    log.info("Creating menu item: {}", name);
52
    UCSBDiningCommonsMenuItem item = new UCSBDiningCommonsMenuItem();
53 1 1. postMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    item.setDiningCommonsCode(diningCommonsCode);
54 1 1. postMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    item.setName(name);
55 1 1. postMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    item.setStation(station);
56
57
    UCSBDiningCommonsMenuItem savedItem = ucsbDiningCommonsMenuItemRepository.save(item);
58
59 1 1. postMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postMenuItem → KILLED
    return savedItem;
60
  }
61
62
  /**
63
   * Get a single UCSB Dining Commons menu item by ID.
64
   *
65
   * @param id the ID of the menu item
66
   * @return the menu item with the specified ID
67
   */
68
  @Operation(summary = "Get a single UCSB Dining Commons menu item by ID")
69
  @PreAuthorize("hasRole('ROLE_USER')")
70
  @GetMapping("")
71
  public UCSBDiningCommonsMenuItem getById(
72
      @Parameter(name = "id", description = "ID of the menu item to retrieve") @RequestParam
73
          Long id) {
74
    UCSBDiningCommonsMenuItem item =
75
        ucsbDiningCommonsMenuItemRepository
76
            .findById(id)
77 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$getById$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
78 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED
    return item;
79
  }
80
81
  /**
82
   * Update a single UCSB Dining Commons menu item.
83
   *
84
   * @param id the ID of the item to update
85
   * @param incoming the new values for the item
86
   * @return the updated menu item
87
   */
88
  @Operation(summary = "Update a single UCSB Dining Commons menu item")
89
  @PreAuthorize("hasRole('ROLE_ADMIN')")
90
  @PutMapping("")
91
  public UCSBDiningCommonsMenuItem updateMenuItem(
92
      @Parameter(name = "id") @RequestParam Long id,
93
      @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) {
94
95
    UCSBDiningCommonsMenuItem item =
96
        ucsbDiningCommonsMenuItemRepository
97
            .findById(id)
98 1 1. lambda$updateMenuItem$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateMenuItem$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
99
100 1 1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    item.setDiningCommonsCode(incoming.getDiningCommonsCode());
101 1 1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    item.setName(incoming.getName());
102 1 1. updateMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    item.setStation(incoming.getStation());
103
104
    ucsbDiningCommonsMenuItemRepository.save(item);
105
106 1 1. updateMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateMenuItem → KILLED
    return item;
107
  }
108
109
  /**
110
   * Delete a UCSB Dining Commons menu item.
111
   *
112
   * @param id the ID of the menu item to delete
113
   * @return a message indicating the item was deleted
114
   */
115
  @Operation(summary = "Delete a UCSB Dining Commons menu item")
116
  @PreAuthorize("hasRole('ROLE_ADMIN')")
117
  @DeleteMapping("")
118
  public Object deleteMenuItem(@Parameter(name = "id") @RequestParam Long id) {
119
120
    UCSBDiningCommonsMenuItem item =
121
        ucsbDiningCommonsMenuItemRepository
122
            .findById(id)
123 1 1. lambda$deleteMenuItem$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteMenuItem$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
124
125 1 1. deleteMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED
    ucsbDiningCommonsMenuItemRepository.delete(item);
126
127 1 1. deleteMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::deleteMenuItem → KILLED
    return genericMessage("UCSBDiningCommonsMenuItem with id %s deleted".formatted(id));
128
  }
129
}

Mutations

40

1.1
Location : allMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:logged_in_users_can_get_all()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allMenuItems → KILLED

53

1.1
Location : postMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_users_can_post()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED

54

1.1
Location : postMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_users_can_post()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED

55

1.1
Location : postMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_users_can_post()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED

59

1.1
Location : postMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_users_can_post()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postMenuItem → KILLED

77

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:logged_in_user_cannot_get_by_id_when_id_missing()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$getById$0 → KILLED

78

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:logged_in_user_can_get_by_id_when_id_exists()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED

98

1.1
Location : lambda$updateMenuItem$0
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_cannot_put_nonexistent_item()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateMenuItem$0 → KILLED

100

1.1
Location : updateMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_users_can_put_existing_item()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED

101

1.1
Location : updateMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_users_can_put_existing_item()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED

102

1.1
Location : updateMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_users_can_put_existing_item()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED

106

1.1
Location : updateMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_users_can_put_existing_item()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateMenuItem → KILLED

123

1.1
Location : lambda$deleteMenuItem$0
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_cannot_delete_nonexistent_menu_item()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteMenuItem$0 → KILLED

125

1.1
Location : deleteMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_can_delete_existing_menu_item()]
removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED

127

1.1
Location : deleteMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_can_delete_existing_menu_item()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::deleteMenuItem → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support