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

Mutations

51

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

75

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

76

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

77

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

81

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

95

1.1
Location : lambda$getById$0
Killed by : edu.ucsb.cs156.example.controllers.ItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.ItemsControllerTests]/[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

97

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

115

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

117

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

118

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

119

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

123

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

138

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

140

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

141

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

Active mutators

Tests examined


Report generated by PIT 1.17.0