UCSBDiningCommonsMenuItemsController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBDiningCommonsMenuItems;
4
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsMenuItemsRepository;
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
// ** This is a REST controller for UCSBDiningCommonsMenuItems */
23
@Tag(name = "UCSBDiningCommonsMenuItems")
24
@RequestMapping("/api/ucsbdiningcommonsmenuitems")
25
@RestController
26
@Slf4j
27
public class UCSBDiningCommonsMenuItemsController extends ApiController {
28
29
  @Autowired UCSBDiningCommonsMenuItemsRepository UCSBDiningCommonsMenuItemsRepository;
30
31
  /**
32
   * List all menu items
33
   *
34
   * @return an iterable of UCSBDiningCommonsMenuItems
35
   */
36
  @Operation(summary = "List all items")
37
  @PreAuthorize("hasRole('ROLE_USER')")
38
  @GetMapping("/all")
39
  public Iterable<UCSBDiningCommonsMenuItems> allItems() {
40
    Iterable<UCSBDiningCommonsMenuItems> items = UCSBDiningCommonsMenuItemsRepository.findAll();
41 1 1. allItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::allItems → KILLED
    return items;
42
  }
43
44
  /**
45
   * Get a single item by id
46
   *
47
   * @param id the id of the item
48
   * @return a item
49
   */
50
  @Operation(summary = "Get a single item")
51
  @PreAuthorize("hasRole('ROLE_USER')")
52
  @GetMapping("")
53
  public UCSBDiningCommonsMenuItems getById(@Parameter(name = "id") @RequestParam Long id) {
54
    UCSBDiningCommonsMenuItems UCSBDiningCommonsMenuItems =
55
        UCSBDiningCommonsMenuItemsRepository.findById(id)
56 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$getById$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItems.class, id));
57
58 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::getById → KILLED
    return UCSBDiningCommonsMenuItems;
59
  }
60
61
  /**
62
   * Create a new menu item
63
   *
64
   * @param diningCommonsCode the dining hall name
65
   * @param name the name of the menu item
66
   * @param station where food is located
67
   * @return the saved menu item
68
   */
69
  @Operation(summary = "Create a new item")
70
  @PreAuthorize("hasRole('ROLE_ADMIN')")
71
  @PostMapping("/post")
72
  public UCSBDiningCommonsMenuItems postItems(
73
      @Parameter(name = "diningCommonsCode") @RequestParam String diningCommonsCode,
74
      @Parameter(name = "name") @RequestParam String name,
75
      @Parameter(name = "station") @RequestParam String station) {
76
77
    UCSBDiningCommonsMenuItems items = new UCSBDiningCommonsMenuItems();
78 1 1. postItems : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setDiningCommonsCode → KILLED
    items.setDiningCommonsCode(diningCommonsCode);
79 1 1. postItems : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setName → KILLED
    items.setName(name);
80 1 1. postItems : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setStation → KILLED
    items.setStation(station);
81
82
    UCSBDiningCommonsMenuItems savedItems = UCSBDiningCommonsMenuItemsRepository.save(items);
83
84 1 1. postItems : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::postItems → KILLED
    return savedItems;
85
  }
86
87
  /**
88
   * Update a single item
89
   *
90
   * @param id id of the item to update
91
   * @param incoming the new item
92
   * @return the updated item
93
   */
94
  @Operation(summary = "Update a single item")
95
  @PreAuthorize("hasRole('ROLE_ADMIN')")
96
  @PutMapping("")
97
  public UCSBDiningCommonsMenuItems updateUCSBDiningCommonsMenuItems(
98
      @Parameter(name = "id") @RequestParam Long id,
99
      @RequestBody @Valid UCSBDiningCommonsMenuItems incoming) {
100
101
    UCSBDiningCommonsMenuItems UCSBDiningCommonsMenuItems =
102
        UCSBDiningCommonsMenuItemsRepository.findById(id)
103 1 1. lambda$updateUCSBDiningCommonsMenuItems$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$updateUCSBDiningCommonsMenuItems$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItems.class, id));
104
105 1 1. updateUCSBDiningCommonsMenuItems : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setDiningCommonsCode → KILLED
    UCSBDiningCommonsMenuItems.setDiningCommonsCode(incoming.getDiningCommonsCode());
106 1 1. updateUCSBDiningCommonsMenuItems : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setName → KILLED
    UCSBDiningCommonsMenuItems.setName(incoming.getName());
107 1 1. updateUCSBDiningCommonsMenuItems : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setStation → KILLED
    UCSBDiningCommonsMenuItems.setStation(incoming.getStation());
108
109
    UCSBDiningCommonsMenuItemsRepository.save(UCSBDiningCommonsMenuItems);
110
111 1 1. updateUCSBDiningCommonsMenuItems : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::updateUCSBDiningCommonsMenuItems → KILLED
    return UCSBDiningCommonsMenuItems;
112
  }
113
114
  /**
115
   * Delete a UCSBDate
116
   *
117
   * @param id the id of the date to delete
118
   * @return a message indicating the date was deleted
119
   */
120
  @Operation(summary = "Delete a UCSBDiningCommonsMenuItems")
121
  @PreAuthorize("hasRole('ROLE_ADMIN')")
122
  @DeleteMapping("")
123
  public Object deleteUCSBDiningCommonsMenuItems(@Parameter(name = "id") @RequestParam Long id) {
124
    UCSBDiningCommonsMenuItems UCSBDiningCommonsMenuItems =
125
        UCSBDiningCommonsMenuItemsRepository.findById(id)
126 1 1. lambda$deleteUCSBDiningCommonsMenuItems$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$deleteUCSBDiningCommonsMenuItems$2 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItems.class, id));
127
128 1 1. deleteUCSBDiningCommonsMenuItems : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemsRepository::delete → KILLED
    UCSBDiningCommonsMenuItemsRepository.delete(UCSBDiningCommonsMenuItems);
129 1 1. deleteUCSBDiningCommonsMenuItems : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::deleteUCSBDiningCommonsMenuItems → KILLED
    return genericMessage("UCSBDiningCommonsMenuItems with id %s deleted".formatted(id));
130
  }
131
}

Mutations

41

1.1
Location : allItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:logged_in_user_can_get_all_UCSBDiningCommonsMenuItemss()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::allItems → KILLED

56

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

58

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

78

1.1
Location : postItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:an_admin_user_can_post_a_new_UCSBDiningCommonsMenuItems()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setDiningCommonsCode → KILLED

79

1.1
Location : postItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:an_admin_user_can_post_a_new_UCSBDiningCommonsMenuItems()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setName → KILLED

80

1.1
Location : postItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:an_admin_user_can_post_a_new_UCSBDiningCommonsMenuItems()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setStation → KILLED

84

1.1
Location : postItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:an_admin_user_can_post_a_new_UCSBDiningCommonsMenuItems()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::postItems → KILLED

103

1.1
Location : lambda$updateUCSBDiningCommonsMenuItems$1
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_cannot_edit_UCSBDiningCommonsMenuItems_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$updateUCSBDiningCommonsMenuItems$1 → KILLED

105

1.1
Location : updateUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_can_edit_an_existing_UCSBDiningCommonsMenuItems()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setDiningCommonsCode → KILLED

106

1.1
Location : updateUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_can_edit_an_existing_UCSBDiningCommonsMenuItems()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setName → KILLED

107

1.1
Location : updateUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_can_edit_an_existing_UCSBDiningCommonsMenuItems()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setStation → KILLED

111

1.1
Location : updateUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_can_edit_an_existing_UCSBDiningCommonsMenuItems()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::updateUCSBDiningCommonsMenuItems → KILLED

126

1.1
Location : lambda$deleteUCSBDiningCommonsMenuItems$2
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_tries_to_delete_non_existant_MenuItems_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$deleteUCSBDiningCommonsMenuItems$2 → KILLED

128

1.1
Location : deleteUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_can_delete_a_item()]
removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemsRepository::delete → KILLED

129

1.1
Location : deleteUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_can_delete_a_item()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::deleteUCSBDiningCommonsMenuItems → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0