UCSBDiningCommonsMenuItemsController.java

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

Mutations

42

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

58

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

60

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

81

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

82

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

83

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

87

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

107

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

109

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

110

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

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

115

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

131

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_ucsbdiningcommonsmenuitems_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$deleteUCSBDiningCommonsMenuItems$2 → KILLED

133

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

134

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_diningcommonsmenuitems()]
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