UCSBDiningCommonsMenuItemController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBDiningCommons;
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
8
import io.swagger.v3.oas.annotations.Operation;
9
import io.swagger.v3.oas.annotations.Parameter;
10
import io.swagger.v3.oas.annotations.tags.Tag;
11
import lombok.extern.slf4j.Slf4j;
12
13
import com.fasterxml.jackson.core.JsonProcessingException;
14
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.format.annotation.DateTimeFormat;
17
import org.springframework.security.access.prepost.PreAuthorize;
18
import org.springframework.web.bind.annotation.DeleteMapping;
19
import org.springframework.web.bind.annotation.GetMapping;
20
import org.springframework.web.bind.annotation.PostMapping;
21
import org.springframework.web.bind.annotation.PutMapping;
22
import org.springframework.web.bind.annotation.RequestBody;
23
import org.springframework.web.bind.annotation.RequestMapping;
24
import org.springframework.web.bind.annotation.RequestParam;
25
import org.springframework.web.bind.annotation.RestController;
26
27
import jakarta.validation.Valid;
28
import java.time.LocalDateTime;
29
30
/**
31
 * This is a REST controller for UCSBDiningCommonsMenuItem
32
 */
33
34
@Tag(name = "UCSBDiningCommonsMenuItems")
35
@RequestMapping("/api/ucsbdiningcommonsmenuitems")
36
@RestController
37
@Slf4j
38
public class UCSBDiningCommonsMenuItemController extends ApiController {
39
40
    @Autowired
41
    UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository;
42
43
    /**
44
     * List all UCSBDiningCommonsMenuItem
45
     * 
46
     * @return an iterable of UCSBDiningCommonsMenuItem
47
     */
48
    @Operation(summary= "List all ucsb dining items")
49
    @PreAuthorize("hasRole('ROLE_USER')")
50
    @GetMapping("/all")
51
    public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItems() {
52
        Iterable<UCSBDiningCommonsMenuItem> ucsbDiningCommonsMenuItems = ucsbDiningCommonsMenuItemRepository.findAll();
53 1 1. allUCSBDiningCommonsMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItems → KILLED
        return ucsbDiningCommonsMenuItems;
54
    }
55
    
56
    /**
57
     * Get a single date by id
58
     * 
59
     * @param id the id of the date
60
     * @return a UCSBDate
61
     */
62
    @Operation(summary= "Get a single Dining Commons MenuItem by id")
63
    @PreAuthorize("hasRole('ROLE_USER')")
64
    @GetMapping("")
65
    public UCSBDiningCommonsMenuItem getById(
66
            @Parameter(name="id") @RequestParam Long id) {
67
            UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id)
68 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));
69
70 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED
        return ucsbDiningCommonsMenuItem;
71
    }
72
73
    /**
74
     * Create a new item
75
     * 
76
     * @param diningCommonsCode the diningCommonsCode
77
     * @param name the name of the item
78
     * @param station the station
79
     * @return the saved UCSBDiningCommonsMenuItem
80
     */
81
    @Operation(summary= "Create a new UCSBDiningCommonsMenuItem")
82
    @PreAuthorize("hasRole('ROLE_ADMIN')")
83
    @PostMapping("/post")
84
    public UCSBDiningCommonsMenuItem postUCSBDiningCommonsMenuItem(
85
            @Parameter(name="diningCommonsCode") @RequestParam String diningCommonsCode,
86
            @Parameter(name="name") @RequestParam String name,
87
            @Parameter(name="station") @RequestParam String station)
88
            throws JsonProcessingException{
89
90
91
92
93
94
95
        UCSBDiningCommonsMenuItem DiningCommonsMenuItem = new UCSBDiningCommonsMenuItem();
96 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
        DiningCommonsMenuItem.setDiningCommonsCode(diningCommonsCode);
97 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
        DiningCommonsMenuItem.setName(name);
98 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
        DiningCommonsMenuItem.setStation(station);
99
100
        UCSBDiningCommonsMenuItem savedUcsbItems = ucsbDiningCommonsMenuItemRepository.save(DiningCommonsMenuItem);
101
102 1 1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUCSBDiningCommonsMenuItem → KILLED
        return savedUcsbItems;
103
    }
104
105
    /**
106
     * Delete a UCSBDiningCommonsMenuItem
107
     * 
108
     * @param id the id of the item to delete
109
     * @return a message indicating the item was deleted
110
     */
111
    @Operation(summary= "Delete a UCSBDiningCommonsMenuItem")
112
    @PreAuthorize("hasRole('ROLE_ADMIN')")
113
    @DeleteMapping("")
114
    public Object deleteUCSBDiningCommonsMenuItem(
115
            @Parameter(name="id") @RequestParam Long id) {
116
            UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id)
117 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));
118
119 1 1. deleteUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED
        ucsbDiningCommonsMenuItemRepository.delete(ucsbDiningCommonsMenuItem);
120 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));
121
    }
122
123
    /**
124
     * Update a single date
125
     * 
126
     * @param id       id of the item to update
127
     * @param incoming the new item
128
     * @return the updated item object
129
     */
130
    @Operation(summary= "Update a single menu item")
131
    @PreAuthorize("hasRole('ROLE_ADMIN')")
132
    @PutMapping("")
133
    public UCSBDiningCommonsMenuItem updaDiningCommonsMenuItem(
134
            @Parameter(name="id") @RequestParam Long id,
135
            @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) {
136
137
            UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id)
138 1 1. lambda$updaDiningCommonsMenuItem$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updaDiningCommonsMenuItem$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
139
140 1 1. updaDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
            ucsbDiningCommonsMenuItem.setDiningCommonsCode(incoming.getDiningCommonsCode());
141 1 1. updaDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
            ucsbDiningCommonsMenuItem.setName(incoming.getName());
142 1 1. updaDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
            ucsbDiningCommonsMenuItem.setStation(incoming.getStation());
143
144
            ucsbDiningCommonsMenuItemRepository.save(ucsbDiningCommonsMenuItem);
145
146 1 1. updaDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updaDiningCommonsMenuItem → KILLED
        return ucsbDiningCommonsMenuItem;
147
    }
148
}

Mutations

53

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

68

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

70

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

96

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

97

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

98

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

102

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

117

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

119

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

120

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

138

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

140

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

141

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

142

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

146

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

Active mutators

Tests examined


Report generated by PIT 1.17.0