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
29
  @Autowired UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository;
30
31
  /**
32
   * List all UCSB dining commons menu items.
33
   *
34
   * @return all menu items
35
   */
36
  @Operation(summary = "List all UCSB dining commons menu items")
37
  @PreAuthorize("hasRole('ROLE_USER')")
38
  @GetMapping("/all")
39
  public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItems() {
40 1 1. allUCSBDiningCommonsMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItems → KILLED
    return ucsbDiningCommonsMenuItemRepository.findAll();
41
  }
42
43
  /**
44
   * Get a single UCSB dining commons menu item by id.
45
   *
46
   * @param id the id of the menu item
47
   * @return the matching menu item
48
   */
49
  @Operation(summary = "Get a single UCSB dining commons menu item by id")
50
  @PreAuthorize("hasRole('ROLE_USER')")
51
  @GetMapping("")
52
  public UCSBDiningCommonsMenuItem getById(@Parameter(name = "id") @RequestParam Long id) {
53 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED
    return ucsbDiningCommonsMenuItemRepository
54
        .findById(id)
55 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));
56
  }
57
58
  /**
59
   * Create a new UCSB dining commons menu item.
60
   *
61
   * @param diningCommonsCode the dining commons code
62
   * @param name the name of the menu item
63
   * @param station the station serving the item
64
   * @return the saved menu item
65
   */
66
  @Operation(summary = "Create a new UCSB dining commons menu item")
67
  @PreAuthorize("hasRole('ROLE_ADMIN')")
68
  @PostMapping("/post")
69
  public UCSBDiningCommonsMenuItem postUCSBDiningCommonsMenuItem(
70
      @Parameter(name = "diningCommonsCode") @RequestParam String diningCommonsCode,
71
      @Parameter(name = "name") @RequestParam String name,
72
      @Parameter(name = "station") @RequestParam String station) {
73
74
    UCSBDiningCommonsMenuItem menuItem = new UCSBDiningCommonsMenuItem();
75 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    menuItem.setDiningCommonsCode(diningCommonsCode);
76 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    menuItem.setName(name);
77 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    menuItem.setStation(station);
78
79 1 1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUCSBDiningCommonsMenuItem → KILLED
    return ucsbDiningCommonsMenuItemRepository.save(menuItem);
80
  }
81
82
  /**
83
   * Update a UCSB dining commons menu item by id.
84
   *
85
   * @param id the id of the menu item to update
86
   * @param incoming the updated menu item data
87
   * @return the updated menu item
88
   */
89
  @Operation(summary = "Update a single UCSB dining commons menu item")
90
  @PreAuthorize("hasRole('ROLE_ADMIN')")
91
  @PutMapping("")
92
  public UCSBDiningCommonsMenuItem updateUCSBDiningCommonsMenuItem(
93
      @Parameter(name = "id") @RequestParam Long id,
94
      @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) {
95
96
    UCSBDiningCommonsMenuItem menuItem =
97
        ucsbDiningCommonsMenuItemRepository
98
            .findById(id)
99 1 1. lambda$updateUCSBDiningCommonsMenuItem$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateUCSBDiningCommonsMenuItem$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
100
101 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    menuItem.setDiningCommonsCode(incoming.getDiningCommonsCode());
102 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    menuItem.setName(incoming.getName());
103 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    menuItem.setStation(incoming.getStation());
104
105
    ucsbDiningCommonsMenuItemRepository.save(menuItem);
106
107 1 1. updateUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateUCSBDiningCommonsMenuItem → KILLED
    return menuItem;
108
  }
109
110
  /**
111
   * Delete a UCSB dining commons menu item by id.
112
   *
113
   * @param id the id of the menu item to delete
114
   * @return a message confirming deletion
115
   */
116
  @Operation(summary = "Delete a UCSB dining commons menu item by id")
117
  @PreAuthorize("hasRole('ROLE_ADMIN')")
118
  @DeleteMapping("")
119
  public Object deleteUCSBDiningCommonsMenuItem(@Parameter(name = "id") @RequestParam Long id) {
120
121
    UCSBDiningCommonsMenuItem menuItem =
122
        ucsbDiningCommonsMenuItemRepository
123
            .findById(id)
124 1 1. lambda$deleteUCSBDiningCommonsMenuItem$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteUCSBDiningCommonsMenuItem$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
125
126 1 1. deleteUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED
    ucsbDiningCommonsMenuItemRepository.delete(menuItem);
127
128 1 1. deleteUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::deleteUCSBDiningCommonsMenuItem → KILLED
    return genericMessage("record %s deleted".formatted(id));
129
  }
130
}

Mutations

40

1.1
Location : allUCSBDiningCommonsMenuItems
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::allUCSBDiningCommonsMenuItems → KILLED

53

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_it_exists()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED

55

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_gets_404_when_id_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$getById$0 → KILLED

75

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

76

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

77

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

79

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

99

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

101

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

102

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

103

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

107

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

124

1.1
Location : lambda$deleteUCSBDiningCommonsMenuItem$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$deleteUCSBDiningCommonsMenuItem$0 → KILLED

126

1.1
Location : deleteUCSBDiningCommonsMenuItem
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

128

1.1
Location : deleteUCSBDiningCommonsMenuItem
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::deleteUCSBDiningCommonsMenuItem → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support