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
@Tag(name = "UCSBDiningCommonsMenuItem")
33
@RequestMapping("/api/ucsbdiningcommonsmenuitem")
34
@RestController
35
@Slf4j
36
public class UCSBDiningCommonsMenuItemController extends ApiController{
37
    @Autowired
38
    UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository;
39
40
    /**
41
     * Get all records in the table and return as a JSON array
42
     * 
43
     * @return an iterable of UCSBDiningCommonsMenuItem
44
     */
45
    @Operation(summary= "Get all records in the table and return as a JSON array")
46
    @PreAuthorize("hasRole('ROLE_USER')")
47
    @GetMapping("/all")
48
    public Iterable<UCSBDiningCommonsMenuItem> allUCSBDiningCommonsMenuItem() {
49
        Iterable<UCSBDiningCommonsMenuItem> records = ucsbDiningCommonsMenuItemRepository.findAll();
50 1 1. allUCSBDiningCommonsMenuItem : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItem → KILLED
        return records;
51
    }
52
53
    /**
54
     * Use the data in the input parameters to create a new row in the table and return the data as JSON
55
     */
56
    @Operation(summary= "Create a new row in the table")
57
    @PreAuthorize("hasRole('ROLE_ADMIN')")
58
    @PostMapping("/post")
59
    public UCSBDiningCommonsMenuItem postUcsbDiningCommonsMenuItem(
60
            @Parameter(name="diningCommonsCode") @RequestParam String diningCommonsCode,
61
            @Parameter(name="name") @RequestParam String name,
62
            @Parameter(name="station") @RequestParam String station) 
63
            throws JsonProcessingException {
64
65
        UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = new UCSBDiningCommonsMenuItem();
66 1 1. postUcsbDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
        ucsbDiningCommonsMenuItem.setDiningCommonsCode(diningCommonsCode);
67 1 1. postUcsbDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
        ucsbDiningCommonsMenuItem.setName(name);
68 1 1. postUcsbDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
        ucsbDiningCommonsMenuItem.setStation(station);
69
70
        UCSBDiningCommonsMenuItem savedUCSBDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.save(ucsbDiningCommonsMenuItem);
71
72 1 1. postUcsbDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUcsbDiningCommonsMenuItem → KILLED
        return savedUCSBDiningCommonsMenuItem;
73
    }
74
75
    /**
76
     * Delete a single record from the table; use the value passed in as a @RequestParam to do a lookup by id. If a matching row is not found, throw an EntityNotFoundException.
77
     */
78
    @Operation(summary= "Delete a UCSBDiningCommonsMenuItem by id")
79
    @PreAuthorize("hasRole('ROLE_ADMIN')")
80
    @DeleteMapping("")
81
    public Object deleteUCSBDate(
82
            @Parameter(name="id") @RequestParam Long id) {
83
        UCSBDiningCommonsMenuItem ucsbDiningCommonsMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id)
84 1 1. lambda$deleteUCSBDate$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteUCSBDate$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
85
86 1 1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED
        ucsbDiningCommonsMenuItemRepository.delete(ucsbDiningCommonsMenuItem);
87 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));
88
    }
89
90
    /**
91
     * Get a single record from the table; use the value passed in 
92
     * as a @RequestParam to do a lookup by id. 
93
     * If a matching row is found, update that row 
94
     * with the values passed in as a JSON object. 
95
     * If a matching row is not found, throw an EntityNotFoundException.
96
     */
97
    @Operation(summary= "Update a Dining Commons Menu Item")
98
    @PreAuthorize("hasRole('ROLE_ADMIN')")
99
    @PutMapping("")
100
    public UCSBDiningCommonsMenuItem updateUCSBDiningCommonsMenuItem(
101
            @Parameter(name="id") @RequestParam Long id,
102
            @RequestBody @Valid UCSBDiningCommonsMenuItem incoming) {
103
104
        UCSBDiningCommonsMenuItem ucsbDCMI = ucsbDiningCommonsMenuItemRepository.findById(id)
105 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));
106
107 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setDiningCommonsCode → KILLED
        ucsbDCMI.setDiningCommonsCode((incoming.getDiningCommonsCode()));
108 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setName → KILLED
        ucsbDCMI.setName(incoming.getName());
109 1 1. updateUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItem::setStation → KILLED
        ucsbDCMI.setStation(incoming.getStation());  
110
111
        ucsbDiningCommonsMenuItemRepository.save(ucsbDCMI);
112
113 1 1. updateUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateUCSBDiningCommonsMenuItem → KILLED
        return ucsbDCMI;
114
    }
115
116
    /**
117
     * Get a single record from the table; use the value passed in
118
     *  as a @RequestParam to do a lookup by id. 
119
     * If a matching row is found, return the row as a JSON object, 
120
     * otherwise throw an EntityNotFoundException.
121
     */
122
    @Operation(summary= "Get a single UCSBDiningCommonsMenuItem by id")
123
    @PreAuthorize("hasRole('ROLE_USER')")
124
    @GetMapping("")
125
    public UCSBDiningCommonsMenuItem getById(
126
            @Parameter(name="id") @RequestParam Long id) {
127
        UCSBDiningCommonsMenuItem ucsbDCMI = ucsbDiningCommonsMenuItemRepository.findById(id)
128 1 1. lambda$getById$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$getById$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonsMenuItem.class, id));
129
130 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED
        return ucsbDCMI;
131
    }
132
}

Mutations

50

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

66

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

67

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

68

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

72

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

84

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

86

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

87

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

105

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

107

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

108

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

109

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

113

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

128

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

130

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

Active mutators

Tests examined


Report generated by PIT 1.17.0