UCSBDiningCommonsMenuItemsController.java

1
package edu.ucsb.cs156.example.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import edu.ucsb.cs156.example.entities.UCSBDiningCommonsMenuItems;
5
import edu.ucsb.cs156.example.errors.EntityNotFoundException;
6
import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsMenuItemsRepository;
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import io.swagger.v3.oas.annotations.tags.Tag;
10
import java.time.LocalDateTime;
11
import javax.validation.Valid;
12
import lombok.extern.slf4j.Slf4j;
13
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.format.annotation.DateTimeFormat;
15
import org.springframework.security.access.prepost.PreAuthorize;
16
import org.springframework.web.bind.annotation.DeleteMapping;
17
import org.springframework.web.bind.annotation.GetMapping;
18
import org.springframework.web.bind.annotation.PostMapping;
19
import org.springframework.web.bind.annotation.PutMapping;
20
import org.springframework.web.bind.annotation.RequestBody;
21
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RequestParam;
23
import org.springframework.web.bind.annotation.RestController;
24
25
@Tag(name = "UCSBDiningCommonsMenuItems")
26
@RequestMapping("/api/ucsbdiningcommonsmenuitems")
27
@RestController
28
@Slf4j
29
public class UCSBDiningCommonsMenuItemsController extends ApiController {
30
31
    @Autowired
32
    UCSBDiningCommonsMenuItemsRepository ucsbDiningCommonsMenuItemsRepository;
33
34
    @Operation(summary = "List all ucsb dining commons menu items")
35
    @PreAuthorize("hasRole('ROLE_USER')")
36
    @GetMapping("/all")
37
    public Iterable<
38
        UCSBDiningCommonsMenuItems
39
    > allUCSBDiningCommonsMenuItems() {
40
        Iterable<UCSBDiningCommonsMenuItems> diningCommonsMenuItems =
41
            ucsbDiningCommonsMenuItemsRepository.findAll();
42 1 1. allUCSBDiningCommonsMenuItems : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::allUCSBDiningCommonsMenuItems → KILLED
        return diningCommonsMenuItems;
43
    }
44
45
    @Operation(summary = "Create a new dining commons menu item")
46
    @PreAuthorize("hasRole('ROLE_ADMIN')")
47
    @PostMapping("/post")
48
    public UCSBDiningCommonsMenuItems postUCSBDiningCommonsMenuItem(
49
        @Parameter(
50
            name = "diningCommonsCode"
51
        ) @RequestParam String diningCommonsCode,
52
        @Parameter(name = "name") @RequestParam String name,
53
        @Parameter(name = "station") @RequestParam String station
54
    ) throws JsonProcessingException {
55
        // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
56
        // See: https://www.baeldung.com/spring-date-parameters
57
58
        // log.info("localDateTime={}", localDateTime);
59
60
        UCSBDiningCommonsMenuItems ucsbDiningCommonsMenuItem =
61
            new UCSBDiningCommonsMenuItems();
62 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setDiningCommonsCode → KILLED
        ucsbDiningCommonsMenuItem.setDiningCommonsCode(diningCommonsCode);
63 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setName → KILLED
        ucsbDiningCommonsMenuItem.setName(name);
64 1 1. postUCSBDiningCommonsMenuItem : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setStation → KILLED
        ucsbDiningCommonsMenuItem.setStation(station);
65
66
        UCSBDiningCommonsMenuItems savedUcsbDiningCommonsMenuItem =
67
            ucsbDiningCommonsMenuItemsRepository.save(
68
                ucsbDiningCommonsMenuItem
69
            );
70
71 1 1. postUCSBDiningCommonsMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::postUCSBDiningCommonsMenuItem → KILLED
        return savedUcsbDiningCommonsMenuItem;
72
    }
73
74
    @Operation(summary = "Get a single dining commons menu item")
75
    @PreAuthorize("hasRole('ROLE_USER')")
76
    @GetMapping("")
77
    public UCSBDiningCommonsMenuItems getById(
78
        @Parameter(name = "id") @RequestParam Long id
79
    ) {
80
        UCSBDiningCommonsMenuItems ucsbDiningCommonsMenuItem =
81
            ucsbDiningCommonsMenuItemsRepository
82
                .findById(id)
83
                .orElseThrow(
84
                    () ->
85 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$getById$0 → KILLED
                        new EntityNotFoundException(
86
                            UCSBDiningCommonsMenuItems.class,
87
                            id
88
                        )
89
                );
90
91 1 1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::getById → KILLED
        return ucsbDiningCommonsMenuItem;
92
    }
93
94
    @Operation(summary = "Delete a UCSB Dining Commons Menu Items")
95
    @PreAuthorize("hasRole('ROLE_ADMIN')")
96
    @DeleteMapping("")
97
    public Object deleteUCSBDiningCommonsMenuItems(
98
        @Parameter(name = "id") @RequestParam Long id
99
    ) {
100
        UCSBDiningCommonsMenuItems ucsbDiningCommonsMenuItems =
101
            ucsbDiningCommonsMenuItemsRepository
102
                .findById(id)
103
                .orElseThrow(
104
                    () ->
105 1 1. lambda$deleteUCSBDiningCommonsMenuItems$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$deleteUCSBDiningCommonsMenuItems$1 → KILLED
                        new EntityNotFoundException(
106
                            UCSBDiningCommonsMenuItems.class,
107
                            id
108
                        )
109
                );
110
111 1 1. deleteUCSBDiningCommonsMenuItems : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemsRepository::delete → KILLED
        ucsbDiningCommonsMenuItemsRepository.delete(ucsbDiningCommonsMenuItems);
112 1 1. deleteUCSBDiningCommonsMenuItems : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::deleteUCSBDiningCommonsMenuItems → KILLED
        return genericMessage(
113
            "UCSBDiningCommonsMenuItems with id %s deleted".formatted(id)
114
        );
115
    }
116
117
    @Operation(summary = "Update a single dining commons menu item")
118
    @PreAuthorize("hasRole('ROLE_ADMIN')")
119
    @PutMapping("")
120
    public UCSBDiningCommonsMenuItems updateUCSBDiningCommonsMenuItems(
121
        @Parameter(name = "id") @RequestParam Long id,
122
        @RequestBody @Valid UCSBDiningCommonsMenuItems incoming
123
    ) {
124
        UCSBDiningCommonsMenuItems ucsbDiningCommonsMenuItem =
125
            ucsbDiningCommonsMenuItemsRepository
126
                .findById(id)
127
                .orElseThrow(
128
                    () ->
129 1 1. lambda$updateUCSBDiningCommonsMenuItems$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::lambda$updateUCSBDiningCommonsMenuItems$2 → KILLED
                        new EntityNotFoundException(
130
                            UCSBDiningCommonsMenuItems.class,
131
                            id
132
                        )
133
                );
134
135 1 1. updateUCSBDiningCommonsMenuItems : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setDiningCommonsCode → KILLED
        ucsbDiningCommonsMenuItem.setDiningCommonsCode(
136
            incoming.getDiningCommonsCode()
137
        );
138 1 1. updateUCSBDiningCommonsMenuItems : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setName → KILLED
        ucsbDiningCommonsMenuItem.setName(incoming.getName());
139 1 1. updateUCSBDiningCommonsMenuItems : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setStation → KILLED
        ucsbDiningCommonsMenuItem.setStation(incoming.getStation());
140
141
        ucsbDiningCommonsMenuItemsRepository.save(ucsbDiningCommonsMenuItem);
142
143 1 1. updateUCSBDiningCommonsMenuItems : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::updateUCSBDiningCommonsMenuItems → KILLED
        return ucsbDiningCommonsMenuItem;
144
    }
145
}

Mutations

42

1.1
Location : allUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:logged_in_user_can_get_all_ucsbdiningcommonsmenuitems()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::allUCSBDiningCommonsMenuItems → KILLED

62

1.1
Location : postUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:an_admin_user_can_post_a_new_ucsbdiningcommonsmenuitems()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setDiningCommonsCode → KILLED

63

1.1
Location : postUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:an_admin_user_can_post_a_new_ucsbdiningcommonsmenuitems()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setName → KILLED

64

1.1
Location : postUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:an_admin_user_can_post_a_new_ucsbdiningcommonsmenuitems()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setStation → KILLED

71

1.1
Location : postUCSBDiningCommonsMenuItem
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:an_admin_user_can_post_a_new_ucsbdiningcommonsmenuitems()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::postUCSBDiningCommonsMenuItem → KILLED

85

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

91

1.1
Location : getById
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[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/UCSBDiningCommonsMenuItemsController::getById → KILLED

105

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

111

1.1
Location : deleteUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_can_delete_a_dining_commons_menu_item()]
removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsMenuItemsRepository::delete → KILLED

112

1.1
Location : deleteUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_can_delete_a_dining_commons_menu_item()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::deleteUCSBDiningCommonsMenuItems → KILLED

129

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

135

1.1
Location : updateUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_can_edit_an_existing_ucsbdiningcommonsmenuitem()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setDiningCommonsCode → KILLED

138

1.1
Location : updateUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_can_edit_an_existing_ucsbdiningcommonsmenuitem()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setName → KILLED

139

1.1
Location : updateUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_can_edit_an_existing_ucsbdiningcommonsmenuitem()]
removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommonsMenuItems::setStation → KILLED

143

1.1
Location : updateUCSBDiningCommonsMenuItems
Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsMenuItemsControllerTests]/[method:admin_can_edit_an_existing_ucsbdiningcommonsmenuitem()]
replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsMenuItemsController::updateUCSBDiningCommonsMenuItems → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3