UCSBDiningCommonsMenuItemController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import edu.ucsb.cs156.example.entities.UCSBDiningCommonsMenuItem;
5
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
6
import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsMenuItemRepository;
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import io.swagger.v3.oas.annotations.tags.Tag;
10
import jakarta.validation.Valid;
11
import lombok.extern.slf4j.Slf4j;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.security.access.prepost.PreAuthorize;
14
import org.springframework.web.bind.annotation.DeleteMapping;
15
import org.springframework.web.bind.annotation.GetMapping;
16
import org.springframework.web.bind.annotation.PostMapping;
17
import org.springframework.web.bind.annotation.PutMapping;
18
import org.springframework.web.bind.annotation.RequestBody;
19
import org.springframework.web.bind.annotation.RequestMapping;
20
import org.springframework.web.bind.annotation.RequestParam;
21
import org.springframework.web.bind.annotation.RestController;
22
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 Menu Items
32
   *
33
   * @return an iterable of UCSBItem
34
   */
35
  @Operation(summary = "List all dining commons items")
36
  @PreAuthorize("hasRole('ROLE_USER')")
37
  @GetMapping("/all")
38
  public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItems() {
39
    Iterable<UCSBDiningCommonsMenuItem> menuItems = UCSBDiningCommonsMenuItemRepository.findAll();
40 1 1. allUCSBDiningCommonsMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItems → KILLED
    return menuItems;
41
  }
42
43
  /**
44
   * Create a new item
45
   *
46
   * @param diningCommonsCode the code for the dining commons
47
   * @param name the name of the item
48
   * @param station the station
49
   * @return the saved item
50
   */
51
  @Operation(summary = "Create a new item")
52
  @PreAuthorize("hasRole('ROLE_ADMIN')")
53
  @PostMapping("/post")
54
  public UCSBDiningCommonsMenuItem postUCSBDiningCommonsMenuItem(
55
      @Parameter(name = "diningCommonsCode") @RequestParam String diningCommonsCode,
56
      @Parameter(name = "name") @RequestParam String name,
57
      @Parameter(name = "station") @RequestParam String station)
58
      throws JsonProcessingException {
59
60
    // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
61
    // See: https://www.baeldung.com/spring-date-parameters
62
63
    UCSBDiningCommonsMenuItem UCSBDiningCommonsMenuItem = new UCSBDiningCommonsMenuItem();
64 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    UCSBDiningCommonsMenuItem.setDiningCommonsCode(diningCommonsCode);
65 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    UCSBDiningCommonsMenuItem.setName(name);
66 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    UCSBDiningCommonsMenuItem.setStation(station);
67
68
    UCSBDiningCommonsMenuItem savedUCSBDiningCommonsMenuItem =
69
        UCSBDiningCommonsMenuItemRepository.save(UCSBDiningCommonsMenuItem);
70
71 1 1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUCSBDiningCommonsMenuItem → KILLED
    return savedUCSBDiningCommonsMenuItem;
72
  }
73
74
  @Operation(summary = "Get a single item by id")
75
  @PreAuthorize("hasRole('ROLE_USER')")
76
  @GetMapping("")
77
  public UCSBDiningCommonsMenuItem getById(@Parameter(name = "id") @RequestParam Long id) {
78
    UCSBDiningCommonsMenuItem menuItem =
79
        UCSBDiningCommonsMenuItemRepository.findById(id)
80 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));
81
82 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED
    return menuItem;
83
  }
84
85
  @Operation(summary = "Update a single item")
86
  @PreAuthorize("hasRole('ROLE_ADMIN')")
87
  @PutMapping("")
88
  public UCSBDiningCommonsMenuItem updateItem(
89
      @Parameter(name = "id") @RequestParam Long id,
90
      @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) {
91
92
    UCSBDiningCommonsMenuItem menuItem =
93
        UCSBDiningCommonsMenuItemRepository.findById(id)
94 1 1. lambda$updateItem$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateItem$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
95
96 1 1. updateItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    menuItem.setDiningCommonsCode(incoming.getDiningCommonsCode());
97 1 1. updateItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    menuItem.setName(incoming.getName());
98 1 1. updateItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    menuItem.setStation(incoming.getStation());
99
    UCSBDiningCommonsMenuItemRepository.save(menuItem);
100 1 1. updateItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateItem → KILLED
    return menuItem;
101
  }
102
103
  @Operation(summary = "Delete a Dining Commons Item")
104
  @PreAuthorize("hasRole('ROLE_ADMIN')")
105
  @DeleteMapping("")
106
  public Object deleteMenuItem(@Parameter(name = "id") @RequestParam Long id) {
107
    UCSBDiningCommonsMenuItem menuItem =
108
        UCSBDiningCommonsMenuItemRepository.findById(id)
109 1 1. lambda$deleteMenuItem$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteMenuItem$2 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
110
111 1 1. deleteMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED
    UCSBDiningCommonsMenuItemRepository.delete(menuItem);
112 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));
113
  }
114
}

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_user_can_get_all_ucsbDiningItems()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItems → KILLED

64

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

65

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

66

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

71

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

80

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: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/UCSBDiningCommonsMenuItemController::lambda$getById$0 → KILLED

82

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[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/UCSBDiningCommonsMenuItemController::getById → KILLED

94

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

96

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

97

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

98

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

100

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

109

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

111

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_a_item()]
removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED

112

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

Active mutators

Tests examined


Report generated by PIT 1.17.0