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.UCSBDiningCommonMenuItem;
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
@Tag(name = "UCSBDiningCommonsMenuItem")
32
@RequestMapping("/api/ucsbdiningcommonsmenuitem")
33
@RestController
34
@Slf4j
35
36
public class UCSBDiningCommonsMenuItemController extends ApiController {
37
    @Autowired
38
    UCSBDiningCommonsMenuItemRepository ucsbDiningCommonsMenuItemRepository;
39
40
    @Operation(summary= "List all menu items")
41
    @PreAuthorize("hasRole('ROLE_USER')")
42
    @GetMapping("/all")
43
    public Iterable<UCSBDiningCommonMenuItem> allUCSBDiningCommonsMenuItems() {
44
        Iterable<UCSBDiningCommonMenuItem> menuItem = ucsbDiningCommonsMenuItemRepository.findAll();
45 1 1. allUCSBDiningCommonsMenuItems : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::allUCSBDiningCommonsMenuItems → KILLED
        return menuItem;
46
    }
47
48
    @Operation(summary= "Get a single menu item")
49
    @PreAuthorize("hasRole('ROLE_USER')")
50
    @GetMapping("")
51
    public UCSBDiningCommonMenuItem getById(
52
            @Parameter(name="id") @RequestParam Long id) {
53
        UCSBDiningCommonMenuItem ucsbDiningCommonMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id)
54 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonMenuItem.class, id));
55
56 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::getById → KILLED
        return ucsbDiningCommonMenuItem;
57
    }
58
59
    @Operation(summary= "Create a new menu item")
60
    @PreAuthorize("hasRole('ROLE_ADMIN')")
61
    @PostMapping("/post")
62
    public UCSBDiningCommonMenuItem postUCSBDiningCommonsMenuItem(
63
        @Parameter(name="diningCommonsCode") @RequestParam String diningCommonsCode,
64
        @Parameter(name="name") @RequestParam String name,
65
        @Parameter(name="station") @RequestParam String station)
66
        throws JsonProcessingException {
67
68
    // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
69
    // See: https://www.baeldung.com/spring-date-parameters
70
71
    //log.info("localDateTime={}", localDateTime);
72
73
    UCSBDiningCommonMenuItem ucsbDiningCommonMenuItem = new UCSBDiningCommonMenuItem();
74 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonMenuItem::setDiningCommonsCode → KILLED
    ucsbDiningCommonMenuItem.setDiningCommonsCode(diningCommonsCode);
75 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonMenuItem::setName → KILLED
    ucsbDiningCommonMenuItem.setName(name);
76 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonMenuItem::setStation → KILLED
    ucsbDiningCommonMenuItem.setStation(station);
77
78
    UCSBDiningCommonMenuItem savedUcsbDiningCommonMenuItem = ucsbDiningCommonsMenuItemRepository.save(ucsbDiningCommonMenuItem);
79
80 1 1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUCSBDiningCommonsMenuItem → KILLED
    return savedUcsbDiningCommonMenuItem;
81
}
82
83
    @Operation(summary= "Delete a menu item")
84
    @PreAuthorize("hasRole('ROLE_ADMIN')")
85
    @DeleteMapping("")
86
    public Object deleteUCSBDiningCommonMenuItem(
87
            @Parameter(name="id") @RequestParam Long id) {
88
        UCSBDiningCommonMenuItem ucsbDiningCommonMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id)
89 1 1. lambda$deleteUCSBDiningCommonMenuItem$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$deleteUCSBDiningCommonMenuItem$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonMenuItem.class, id));
90
91 1 1. deleteUCSBDiningCommonMenuItem : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemRepository::delete → KILLED
        ucsbDiningCommonsMenuItemRepository.delete(ucsbDiningCommonMenuItem);
92 1 1. deleteUCSBDiningCommonMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::deleteUCSBDiningCommonMenuItem → KILLED
        return genericMessage("UCSBDiningCommonMenuItem with id %s deleted".formatted(id));
93
    }
94
95
    @Operation(summary= "Update a single menu item")
96
    @PreAuthorize("hasRole('ROLE_ADMIN')")
97
    @PutMapping("")
98
    public UCSBDiningCommonMenuItem updateUCSBDiningCommonMenuItem(
99
            @Parameter(name="id") @RequestParam Long id,
100
            @RequestBody @Valid UCSBDiningCommonMenuItem incoming) {
101
102
        UCSBDiningCommonMenuItem ucsbDiningCommonMenuItem = ucsbDiningCommonsMenuItemRepository.findById(id)
103 1 1. lambda$updateUCSBDiningCommonMenuItem$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::lambda$updateUCSBDiningCommonMenuItem$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommonMenuItem.class, id));
104
105 1 1. updateUCSBDiningCommonMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonMenuItem::setDiningCommonsCode → KILLED
        ucsbDiningCommonMenuItem.setDiningCommonsCode(incoming.getDiningCommonsCode());
106 1 1. updateUCSBDiningCommonMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonMenuItem::setName → KILLED
        ucsbDiningCommonMenuItem.setName(incoming.getName());
107 1 1. updateUCSBDiningCommonMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonMenuItem::setStation → KILLED
        ucsbDiningCommonMenuItem.setStation(incoming.getStation());
108
109
        ucsbDiningCommonsMenuItemRepository.save(ucsbDiningCommonMenuItem);
110
111 1 1. updateUCSBDiningCommonMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::updateUCSBDiningCommonMenuItem → KILLED
        return ucsbDiningCommonMenuItem;
112
    }
113
114
}

Mutations

45

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

54

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

56

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

74

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

75

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

76

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_UCSBDiningCommonsMenuItem()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonMenuItem::setStation → 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_UCSBDiningCommonsMenuItem()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemController::postUCSBDiningCommonsMenuItem → KILLED

89

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

91

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

92

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

103

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

105

1.1
Location : updateUCSBDiningCommonMenuItem
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/UCSBDiningCommonMenuItem::setDiningCommonsCode → KILLED

106

1.1
Location : updateUCSBDiningCommonMenuItem
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/UCSBDiningCommonMenuItem::setName → KILLED

107

1.1
Location : updateUCSBDiningCommonMenuItem
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/UCSBDiningCommonMenuItem::setStation → KILLED

111

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

Active mutators

Tests examined


Report generated by PIT 1.17.0