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
/** This is a REST controller for UCSBDiningCommons */
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
  /** List all dining commons menu items */
32
  @Operation(summary = "List all ucsb dining commons menu items")
33
  @PreAuthorize("hasRole('ROLE_USER')")
34
  @GetMapping("/all")
35
  public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItem() {
36 1 1. allUCSBDiningCommonsMenuItem : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItem → KILLED
    return ucsbDiningCommonsMenuItemRepository.findAll();
37
  }
38
39
  /** Create a new dining commons menu item (admin only) */
40
  @Operation(summary = "Create a new commons menu item")
41
  @PreAuthorize("hasRole('ROLE_ADMIN')")
42
  @PostMapping("/post")
43
  public UCSBDiningCommonsMenuItem postMenuItem(
44
      @Parameter(name = "diningCommonsCode") @RequestParam String diningCommonsCode,
45
      @Parameter(name = "name") @RequestParam String name,
46
      @Parameter(name = "station") @RequestParam String station) {
47
48
    UCSBDiningCommonsMenuItem item = new UCSBDiningCommonsMenuItem();
49 1 1. postMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    item.setDiningCommonsCode(diningCommonsCode);
50 1 1. postMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    item.setName(name);
51 1 1. postMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    item.setStation(station);
52
53 1 1. postMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postMenuItem → KILLED
    return ucsbDiningCommonsMenuItemRepository.save(item);
54
  }
55
56
  /** Get a single menu item by id */
57
  @Operation(summary = "Get a single menu item by id")
58
  @PreAuthorize("hasRole('ROLE_USER')")
59
  @GetMapping("")
60
  public UCSBDiningCommonsMenuItem getById(@Parameter(name = "id") @RequestParam Long id) {
61 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED
    return ucsbDiningCommonsMenuItemRepository
62
        .findById(id)
63
        .orElseThrow(
64 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$getById$0 → KILLED
            () -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, String.valueOf(id)));
65
  }
66
67
  /** Update a single menu item (admin only) */
68
  @Operation(summary = "Update a single menu item")
69
  @PreAuthorize("hasRole('ROLE_ADMIN')")
70
  @PutMapping("")
71
  public UCSBDiningCommonsMenuItem updateUCSBDiningCommonsMenuItem(
72
      @Parameter(name = "id") @RequestParam Long id,
73
      @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) {
74
75
    UCSBDiningCommonsMenuItem menuItem =
76
        ucsbDiningCommonsMenuItemRepository
77
            .findById(id)
78 1 1. lambda$updateUCSBDiningCommonsMenuItem$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateUCSBDiningCommonsMenuItem$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
79
80
    // Update fields from incoming object
81 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    menuItem.setDiningCommonsCode(incoming.getDiningCommonsCode());
82 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    menuItem.setName(incoming.getName());
83 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    menuItem.setStation(incoming.getStation());
84
85 1 1. updateUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateUCSBDiningCommonsMenuItem → KILLED
    return ucsbDiningCommonsMenuItemRepository.save(menuItem);
86
  }
87
88
  /**
89
   * Delete a UCSBDiningCommonMenuItem
90
   *
91
   * @param id the id of the menu item to delete
92
   * @return a message indicating the menu item was deleted
93
   */
94
  @Operation(summary = "Delete a UCSBDiningCommonsMenuItem")
95
  @PreAuthorize("hasRole('ROLE_ADMIN')")
96
  @DeleteMapping("")
97
  public Object deleteUCSBDiningCommonMenuItem(@Parameter(name = "id") @RequestParam Long id) {
98
    UCSBDiningCommonsMenuItem menuItem =
99
        ucsbDiningCommonsMenuItemRepository
100
            .findById(id)
101 1 1. lambda$deleteUCSBDiningCommonMenuItem$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteUCSBDiningCommonMenuItem$2 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
102
103 1 1. deleteUCSBDiningCommonMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED
    ucsbDiningCommonsMenuItemRepository.delete(menuItem);
104 1 1. deleteUCSBDiningCommonMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::deleteUCSBDiningCommonMenuItem → KILLED
    return genericMessage("UCSBDiningCommonsMenuItem with id %s deleted".formatted(id));
105
  }
106
}

Mutations

36

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

49

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

50

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

51

1.1
Location : postMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTests]/[method:admin_can_post_a_new_menu_item()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → 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_can_post_a_new_menu_item()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postMenuItem → KILLED

61

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

64

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

78

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

81

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_edit_an_existing_ucsbdiningcommonsmenuitem()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED

82

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_edit_an_existing_ucsbdiningcommonsmenuitem()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED

83

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_edit_an_existing_ucsbdiningcommonsmenuitem()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED

85

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

101

1.1
Location : lambda$deleteUCSBDiningCommonMenuItem$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_ucsbdiningcommonsmenuitem_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteUCSBDiningCommonMenuItem$2 → KILLED

103

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

104

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

Active mutators

Tests examined


Report generated by PIT 1.17.0