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
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 lombok.extern.slf4j.Slf4j;
11
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
import jakarta.validation.Valid;
24
25
/**
26
 * This is a REST controller for UCSBDiningCommonsMenuItem
27
 */
28
29
@Tag(name = "UCSBDiningCommonsMenuItem")
30
@RequestMapping("/api/ucsbdiningcommonsmenuitem")
31
@RestController
32
@Slf4j
33
public class UCSBDiningCommonsMenuItemController extends ApiController {
34
35
    @Autowired
36
    UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository;
37
38
    /**
39
     * List all UCSB Dining Commons Menu Items
40
     * 
41
     * @return an iterable of UCSBDiningCommonsMenuItem
42
     */
43
    @Operation(summary= "List all Dining Commons Menu Items")
44
    @PreAuthorize("hasRole('ROLE_USER')")
45
    @GetMapping("/all")
46
    public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItem() {
47
        Iterable<UCSBDiningCommonsMenuItem> ucsbdiningcommonmenuitem = ucsbDiningCommonsMenuItemRepository.findAll();
48 1 1. allUCSBDiningCommonsMenuItem : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItem → KILLED
        return ucsbdiningcommonmenuitem;
49
    }
50
51
    /**
52
     * Get a menu item by id
53
     * 
54
     * @param id the id of the menu item
55
     * @return a UCSBDiningCommonMenuItem
56
     */
57
    @Operation(summary= "Get a menu item")
58
    @PreAuthorize("hasRole('ROLE_USER')")
59
    @GetMapping("")
60
    public UCSBDiningCommonsMenuItem getById(
61
            @Parameter(name="id") @RequestParam Long id) {
62
                UCSBDiningCommonsMenuItem ucsbdiningcommonmenuitem = ucsbDiningCommonsMenuItemRepository.findById(id)
63 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));
64
65 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED
        return ucsbdiningcommonmenuitem;
66
    }
67
68
    /**
69
     * This method creates a new diningcommons. Accessible only to users with the role "ROLE_ADMIN".
70
     * @param diningCommonsCode code of the diningcommonsmenuitem
71
     * @param name name of the diningcommonsmenuitem
72
     * @param station station of the diningcommonsmenuitem
73
     * @return the saved diningcommonsmenuitem
74
     */
75
    @Operation(summary= "Create a new menu item")
76
    @PreAuthorize("hasRole('ROLE_ADMIN')")
77
    @PostMapping("/post")
78
    public UCSBDiningCommonsMenuItem postItem(
79
        @Parameter(name="diningCommonsCode") @RequestParam String diningCommonsCode,
80
        @Parameter(name="name") @RequestParam String name,
81
        @Parameter(name="station") @RequestParam String station
82
        )
83
        {
84
        UCSBDiningCommonsMenuItem item = new UCSBDiningCommonsMenuItem();
85 1 1. postItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
        item.setDiningCommonsCode(diningCommonsCode);
86 1 1. postItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
        item.setName(name);
87 1 1. postItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
        item.setStation(station);
88
89
        UCSBDiningCommonsMenuItem savedItem = ucsbDiningCommonsMenuItemRepository.save(item);
90
91 1 1. postItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postItem → KILLED
        return savedItem;
92
    }
93
94
95
    /**
96
     * Delete a UCSBDiningCommonsMenuItem
97
     * 
98
     * @param id the id of the item to delete
99
     * @return a message indicating the date was deleted
100
     */
101
    @Operation(summary= "Delete a UCSBDiningCommonsMenuItem")
102
    @PreAuthorize("hasRole('ROLE_ADMIN')")
103
    @DeleteMapping("")
104
    public Object deleteUCSBDiningCommonsMenuItem(
105
            @Parameter(name="id") @RequestParam Long id) {
106
                UCSBDiningCommonsMenuItem ucsbdiningcommonmenuitem = ucsbDiningCommonsMenuItemRepository.findById(id)
107 1 1. lambda$deleteUCSBDiningCommonsMenuItem$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteUCSBDiningCommonsMenuItem$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
108
109 1 1. deleteUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED
                ucsbDiningCommonsMenuItemRepository.delete(ucsbdiningcommonmenuitem);
110 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));
111
    }
112
113
    /**
114
     * Update a single item
115
     * 
116
     * @param id id of the item to update
117
     * @param incoming the new item
118
     * @return the updated item object
119
     */
120
    @Operation(summary= "Update a single item")
121
    @PreAuthorize("hasRole('ROLE_ADMIN')")
122
    @PutMapping("")
123
    public UCSBDiningCommonsMenuItem updateUCSBDiningCommonsMenuItem(
124
            @Parameter(name="id") @RequestParam Long id,
125
            @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) {
126
127
                UCSBDiningCommonsMenuItem ucsbdiningcommonmenuitem = ucsbDiningCommonsMenuItemRepository.findById(id)
128 1 1. lambda$updateUCSBDiningCommonsMenuItem$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateUCSBDiningCommonsMenuItem$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
129
130 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
                ucsbdiningcommonmenuitem.setDiningCommonsCode(incoming.getDiningCommonsCode());
131 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
                ucsbdiningcommonmenuitem.setName(incoming.getName());
132 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
                ucsbdiningcommonmenuitem.setStation(incoming.getStation());
133
134
        ucsbDiningCommonsMenuItemRepository.save(ucsbdiningcommonmenuitem);
135
136 1 1. updateUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateUCSBDiningCommonsMenuItem → KILLED
        return ucsbdiningcommonmenuitem;
137
    }
138
}

Mutations

48

1.1
Location : allUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemControllerTest]/[method:logged_in_user_can_get_all_menu_items()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItem → KILLED

63

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

65

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

85

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

86

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

87

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

91

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

107

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

109

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

110

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

128

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

130

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

131

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

132

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

136

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

Active mutators

Tests examined


Report generated by PIT 1.17.0