UCSBDiningCommonsMenuItemController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import edu.ucsb.cs156.example.entities.UCSBDate;
4
import edu.ucsb.cs156.example.entities.UCSBDiningCommonsMenuItem;
5
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
6
import edu.ucsb.cs156.example.repositories.UCSBDateRepository;
7
import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsMenuItemRepository;
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
29
import java.time.LocalDateTime;
30
31
/**
32
 * This is a REST controller for UCSBDiningCommonsMenuItem
33
 */
34
35
@Tag(name = "UCSBDiningCommonsMenuItem")
36
@RequestMapping("/api/UCSBDiningCommonsMenuItem")
37
@RestController
38
@Slf4j
39
40
public class UCSBDiningCommonsMenuItemController extends ApiController {
41
    @Autowired
42
    UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository;
43
44
    /**
45
     * List all UCSB Dining Common Menu Items
46
     * 
47
     * @return an iterable of UCSBDiningCommonsMenuItem
48
     */
49
    @Operation(summary = "List all UCSB Dining Commons Menu Items")
50
    @PreAuthorize("hasRole('ROLE_USER')")
51
    @GetMapping("/all")
52
    public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItems() {
53
        Iterable<UCSBDiningCommonsMenuItem> ucsbDiningCommonsMenuItems = ucsbDiningCommonsMenuItemRepository.findAll();
54 1 1. allUCSBDiningCommonsMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItems → KILLED
        return ucsbDiningCommonsMenuItems;
55
    }
56
57
    /**
58
     * Create a new UCSB Dining Commons Menu Item
59
     * 
60
     * @param diningCommonsCode dining commons code for which dining common
61
     * @param name              name of menu item
62
     * @param station           station for where in the dining common menu item is
63
     * @return the saved UCSB Dining Common Menu Item
64
     */
65
    @Operation(summary = "Create a new Dining Common Menu Item")
66
    @PreAuthorize("hasRole('ROLE_ADMIN')")
67
    @PostMapping("/post")
68
    public UCSBDiningCommonsMenuItem postUCSBDiningCommonsMenuItem(
69
            @Parameter(name = "diningCommonsCode") @RequestParam String diningCommonsCode,
70
            @Parameter(name = "name") @RequestParam String name,
71
            @Parameter(name = "station") @RequestParam String station)
72
            throws JsonProcessingException {
73
74
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
75
        // See: https://www.baeldung.com/spring-date-parameters
76
77
        UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = new UCSBDiningCommonsMenuItem();
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 = ucsbDiningCommonsMenuItemRepository
83
                .save(ucsbDiningCommonsMenuItem);
84
85 1 1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUCSBDiningCommonsMenuItem → KILLED
        return savedUCSBDiningCommonsMenuItem;
86
    }
87
88
    /**
89
     * Get a single Menu Item by id
90
     * 
91
     * @param id the id of the date
92
     * @return a UCSB Dining Commons Menu Item by ID
93
     */
94
    @Operation(summary = "Get a UCSB Dining Commons Menu Item")
95
    @PreAuthorize("hasRole('ROLE_USER')")
96
    @GetMapping("")
97
    public UCSBDiningCommonsMenuItem getById(
98
            @Parameter(name = "id") @RequestParam Long id) {
99
        UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id)
100 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));
101
102 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED
        return ucsbDiningCommonsMenuItem;
103
    }
104
105
    /**
106
     * Update a single Menu Item
107
     * 
108
     * @param id       id of the Menu Item to update
109
     * @param incoming the new Menu Item
110
     * @return the updated Menu Item object
111
     */
112
    @Operation(summary = "Update a Menu Item")
113
    @PreAuthorize("hasRole('ROLE_ADMIN')")
114
    @PutMapping("")
115
    public UCSBDiningCommonsMenuItem updateUCSBDiningCommonsMenuItem(
116
            @Parameter(name = "id") @RequestParam Long id,
117
            @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) {
118
119
        UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id)
120 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));
121
122 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
        ucsbDiningCommonsMenuItem.setDiningCommonsCode(incoming.getDiningCommonsCode());
123 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
        ucsbDiningCommonsMenuItem.setName(incoming.getName());
124 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
        ucsbDiningCommonsMenuItem.setStation(incoming.getStation());
125
126
        ucsbDiningCommonsMenuItemRepository.save(ucsbDiningCommonsMenuItem);
127
128 1 1. updateUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateUCSBDiningCommonsMenuItem → KILLED
        return ucsbDiningCommonsMenuItem;
129
    }
130
131
    /**
132
     * Delete a Menu Item
133
     * 
134
     * @param id the id of the Menu Item to delete
135
     * @return a message indicating the Menu Item was deleted
136
     */
137
    @Operation(summary = "Delete a UCSB Menu Item")
138
    @PreAuthorize("hasRole('ROLE_ADMIN')")
139
    @DeleteMapping("")
140
    public Object deleteUCSBDiningCommonsMenuItem(
141
            @Parameter(name = "id") @RequestParam Long id) {
142
        UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id)
143 1 1. lambda$deleteUCSBDiningCommonsMenuItem$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteUCSBDiningCommonsMenuItem$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
144
145 1 1. deleteUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED
        ucsbDiningCommonsMenuItemRepository.delete(ucsbDiningCommonsMenuItem);
146 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));
147
    }
148
149
}

Mutations

54

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_ucsbdates()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItems → 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_menuitem()]
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_menuitem()]
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_menuitem()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED

85

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

100

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

102

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

120

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

122

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

123

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

124

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

128

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

143

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

145

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

146

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

Active mutators

Tests examined


Report generated by PIT 1.17.0