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 org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.security.access.prepost.PreAuthorize;
12
import org.springframework.web.bind.annotation.DeleteMapping;
13
import org.springframework.web.bind.annotation.GetMapping;
14
import org.springframework.web.bind.annotation.PostMapping;
15
import org.springframework.web.bind.annotation.PutMapping;
16
import org.springframework.web.bind.annotation.RequestBody;
17
import org.springframework.web.bind.annotation.RequestMapping;
18
import org.springframework.web.bind.annotation.RequestParam;
19
import org.springframework.web.bind.annotation.RestController;
20
21
/** This is a REST controller for Restaurants */
22
@Tag(name = "UCSBDiningCommonsMenuItem")
23
@RequestMapping("/api/ucsbdiningcommonsmenuitem")
24
@RestController
25
public class UCSBDiningCommonsMenuItemController extends ApiController {
26
27
  @Autowired UCSBDiningCommonsMenuItemRepository ucsbdiningcmmonsmenuitemrepository;
28
29
  /**
30
   * This method returns a list of all restaurants.
31
   *
32
   * @return a list of all restaurants
33
   */
34
  @Operation(summary = "List all UCSBDiningCommonsMenuItems")
35
  @PreAuthorize("hasRole('ROLE_USER')")
36
  @GetMapping("/all")
37
  public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItem() {
38
    Iterable<UCSBDiningCommonsMenuItem> ucsbdiningcommonsmenuitem =
39
        ucsbdiningcmmonsmenuitemrepository.findAll();
40 1 1. allUCSBDiningCommonsMenuItem : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItem → KILLED
    return ucsbdiningcommonsmenuitem;
41
  }
42
43
  /**
44
   * This method returns a single restaurant.
45
   *
46
   * @param id id of the restaurant to get
47
   * @return a single restaurant
48
   */
49
  @Operation(summary = "Get a single UCSBDiningCommonsMenuItem")
50
  @PreAuthorize("hasRole('ROLE_USER')")
51
  @GetMapping("")
52
  public UCSBDiningCommonsMenuItem getById(@Parameter(name = "id") @RequestParam Long id) {
53
    UCSBDiningCommonsMenuItem ucsbdiningcommonsmenuitem =
54
        ucsbdiningcmmonsmenuitemrepository
55
            .findById(id)
56 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));
57
58 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED
    return ucsbdiningcommonsmenuitem;
59
  }
60
61
  /**
62
   * This method creates a new restaurant. Accessible only to users with the role "ROLE_ADMIN".
63
   *
64
   * @param diningCommonsCode
65
   * @param name name of the restaurant
66
   * @param station description of the restaurant
67
   * @return the save restaurant (with it's id field set by the database)
68
   */
69
  @Operation(summary = "Create a new UCSBDiningCommonsMenuItem")
70
  @PreAuthorize("hasRole('ROLE_ADMIN')")
71
  @PostMapping("/post")
72
  public UCSBDiningCommonsMenuItem postUCSBDiningCommonsMenuItem(
73
      @Parameter(name = "diningCommonsCode") @RequestParam String diningCommonsCode,
74
      @Parameter(name = "name") @RequestParam String name,
75
      @Parameter(name = "station") @RequestParam String station) {
76
    UCSBDiningCommonsMenuItem ucsbdiningcommonsmenuitem = new UCSBDiningCommonsMenuItem();
77
78 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    ucsbdiningcommonsmenuitem.setDiningCommonsCode(diningCommonsCode);
79 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    ucsbdiningcommonsmenuitem.setName(name);
80 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    ucsbdiningcommonsmenuitem.setStation(station);
81
82
    UCSBDiningCommonsMenuItem saveducsbdiningcommonsmenuitem =
83
        ucsbdiningcmmonsmenuitemrepository.save(ucsbdiningcommonsmenuitem);
84 1 1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUCSBDiningCommonsMenuItem → KILLED
    return saveducsbdiningcommonsmenuitem;
85
  }
86
87
  /**
88
   * Deletes a restaurant. Accessible only to users with the role "ROLE_ADMIN".
89
   *
90
   * @param id id of the restaurant to delete
91
   * @return a message indicating that the restaurant was deleted
92
   */
93
  @Operation(summary = "Delete a UCSBDiningCommonsMenuItem")
94
  @PreAuthorize("hasRole('ROLE_ADMIN')")
95
  @DeleteMapping("")
96
  public Object deleteUCSBDiningCommonsMenuItem(@Parameter(name = "id") @RequestParam Long id) {
97
    UCSBDiningCommonsMenuItem ucsbdiningcommonsmenuitem =
98
        ucsbdiningcmmonsmenuitemrepository
99
            .findById(id)
100 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));
101
102 1 1. deleteUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED
    ucsbdiningcmmonsmenuitemrepository.delete(ucsbdiningcommonsmenuitem);
103 1 1. deleteUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::deleteUCSBDiningCommonsMenuItem → KILLED
    return genericMessage("UCSBDiningCommonsMenuItem with id %s deleted".formatted(id));
104
  }
105
106
  /**
107
   * Update a single restaurant. Accessible only to users with the role "ROLE_ADMIN".
108
   *
109
   * @param id id of the restaurant to update
110
   * @param incoming the new restaurant contents
111
   * @return the updated restaurant object
112
   */
113
  @Operation(summary = "Update a single UCSBDiningCommonsMenuItem")
114
  @PreAuthorize("hasRole('ROLE_ADMIN')")
115
  @PutMapping("")
116
  public UCSBDiningCommonsMenuItem updateUCSBDiningCommonsMenuItem(
117
      @Parameter(name = "id") @RequestParam Long id,
118
      @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) {
119
120
    UCSBDiningCommonsMenuItem ucsbdiningcommonsmenuitem =
121
        ucsbdiningcmmonsmenuitemrepository
122
            .findById(id)
123 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));
124
125 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
    ucsbdiningcommonsmenuitem.setDiningCommonsCode(incoming.getDiningCommonsCode());
126 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
    ucsbdiningcommonsmenuitem.setName(incoming.getName());
127 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
    ucsbdiningcommonsmenuitem.setStation(incoming.getStation());
128
129
    ucsbdiningcmmonsmenuitemrepository.save(ucsbdiningcommonsmenuitem);
130
131 1 1. updateUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateUCSBDiningCommonsMenuItem → KILLED
    return ucsbdiningcommonsmenuitem;
132
  }
133
}

Mutations

40

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

56

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

58

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

78

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

80

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

84

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

100

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

102

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

103

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

123

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

125

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

126

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

127

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

131

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

Active mutators

Tests examined


Report generated by PIT 1.30.0 support