DiningCommonsController.java

1
package edu.ucsb.cs156.dining.controllers;
2
3
import edu.ucsb.cs156.dining.entities.DiningCommons;
4
import edu.ucsb.cs156.dining.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.dining.repositories.DiningCommonsRepository;
6
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 lombok.extern.slf4j.Slf4j;
11
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.security.access.prepost.PreAuthorize;
14
import org.springframework.web.bind.annotation.DeleteMapping;
15
import org.springframework.web.bind.annotation.GetMapping;
16
import org.springframework.web.bind.annotation.PostMapping;
17
import org.springframework.web.bind.annotation.PutMapping;
18
import org.springframework.web.bind.annotation.RequestBody;
19
import org.springframework.web.bind.annotation.RequestMapping;
20
import org.springframework.web.bind.annotation.RequestParam;
21
import org.springframework.web.bind.annotation.RestController;
22
23
import jakarta.validation.Valid;
24
25
/**
26
 * This is a REST controller for DiningCommons
27
 */
28
29
@Tag(name = "DiningCommons")
30
@RequestMapping("/api/diningcommons")
31
@RestController
32
@Slf4j
33
public class DiningCommonsController extends ApiController {
34
35
    @Autowired
36
    DiningCommonsRepository diningCommonsRepository;
37
38
    /**
39
     * THis method returns a list of all diningcommons.
40
     * @return a list of all diningcommons
41
     */
42
    @Operation(summary= "List all ucsb dining commons")
43
    @PreAuthorize("hasRole('ROLE_USER')")
44
    @GetMapping("/all")
45
    public Iterable<DiningCommons> allCommonss() {
46
        Iterable<DiningCommons> commons = diningCommonsRepository.findAll();
47 1 1. allCommonss : replaced return value with Collections.emptyList for edu/ucsb/cs156/dining/controllers/DiningCommonsController::allCommonss → KILLED
        return commons;
48
    }
49
50
    /**
51
     * This method returns a single diningcommons.
52
     * @param code code of the diningcommons
53
     * @return a single diningcommons
54
     */
55
    @Operation(summary= "Get a single dining commons")
56
    @PreAuthorize("hasRole('ROLE_USER')")
57
    @GetMapping("")
58
    public DiningCommons getById(
59
            @Parameter(name="code") @RequestParam String code) {
60
        DiningCommons commons = diningCommonsRepository.findById(code)
61 1 1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::lambda$getById$0 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(DiningCommons.class, code));
62
63 1 1. getById : replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::getById → KILLED
        return commons;
64
    }
65
66
    /**
67
     * This method creates a new diningcommons. Accessible only to users with the role "ROLE_ADMIN".
68
     * @param code code of the diningcommons
69
     * @param name name of the diningcommons
70
     * @param hasSackMeal whether or not the commons has sack meals
71
     * @param hasTakeOutMeal whether or not the commons has take out meals
72
     * @param hasDiningCam whether or not the commons has a dining cam
73
     * @param latitude latitude of the commons
74
     * @param longitude logitude of the commons
75
     * @return the save diningcommons
76
     */
77
    @Operation(summary= "Create a new dining commons")
78
    @PreAuthorize("hasRole('ROLE_ADMIN')")
79
    @PostMapping("/post")
80
    public DiningCommons postCommons(
81
        @Parameter(name="code") @RequestParam String code,
82
        @Parameter(name="name") @RequestParam String name,
83
        @Parameter(name="hasSackMeal") @RequestParam boolean hasSackMeal,
84
        @Parameter(name="hasTakeOutMeal") @RequestParam boolean hasTakeOutMeal,
85
        @Parameter(name="hasDiningCam") @RequestParam boolean hasDiningCam,
86
        @Parameter(name="latitude") @RequestParam double latitude,
87
        @Parameter(name="longitude") @RequestParam double longitude
88
        )
89
        {
90
91
        DiningCommons commons = new DiningCommons();
92 1 1. postCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setCode → KILLED
        commons.setCode(code);
93 1 1. postCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setName → KILLED
        commons.setName(name);
94 1 1. postCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setHasSackMeal → KILLED
        commons.setHasSackMeal(hasSackMeal);
95 1 1. postCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setHasTakeOutMeal → KILLED
        commons.setHasTakeOutMeal(hasTakeOutMeal);
96 1 1. postCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setHasDiningCam → KILLED
        commons.setHasDiningCam(hasDiningCam);
97 1 1. postCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setLatitude → KILLED
        commons.setLatitude(latitude);
98 1 1. postCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setLongitude → KILLED
        commons.setLongitude(longitude);
99
100
        DiningCommons savedCommons = diningCommonsRepository.save(commons);
101
102 1 1. postCommons : replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::postCommons → KILLED
        return savedCommons;
103
    }
104
105
    /**
106
     * Delete a diningcommons. Accessible only to users with the role "ROLE_ADMIN".
107
     * @param code code of the commons
108
     * @return a message indiciating the commons was deleted
109
     */
110
    @Operation(summary= "Delete a DiningCommons")
111
    @PreAuthorize("hasRole('ROLE_ADMIN')")
112
    @DeleteMapping("")
113
    public Object deleteCommons(
114
            @Parameter(name="code") @RequestParam String code) {
115
        DiningCommons commons = diningCommonsRepository.findById(code)
116 1 1. lambda$deleteCommons$1 : replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::lambda$deleteCommons$1 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(DiningCommons.class, code));
117
118 1 1. deleteCommons : removed call to edu/ucsb/cs156/dining/repositories/DiningCommonsRepository::delete → KILLED
        diningCommonsRepository.delete(commons);
119 1 1. deleteCommons : replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::deleteCommons → KILLED
        return genericMessage("DiningCommons with id %s deleted".formatted(code));
120
    }
121
122
    /**
123
     * Update a single diningcommons. Accessible only to users with the role "ROLE_ADMIN".
124
     * @param code code of the diningcommons
125
     * @param incoming the new commons contents
126
     * @return the updated commons object
127
     */
128
    @Operation(summary= "Update a single dining commons")
129
    @PreAuthorize("hasRole('ROLE_ADMIN')")
130
    @PutMapping("")
131
    public DiningCommons updateCommons(
132
            @Parameter(name="code") @RequestParam String code,
133
            @RequestBody @Valid DiningCommons incoming) {
134
135
        DiningCommons commons = diningCommonsRepository.findById(code)
136 1 1. lambda$updateCommons$2 : replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::lambda$updateCommons$2 → KILLED
                .orElseThrow(() -> new EntityNotFoundException(DiningCommons.class, code));
137
138
139 1 1. updateCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setName → KILLED
        commons.setName(incoming.getName());  
140 1 1. updateCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setHasSackMeal → KILLED
        commons.setHasSackMeal(incoming.getHasSackMeal());
141 1 1. updateCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setHasTakeOutMeal → KILLED
        commons.setHasTakeOutMeal(incoming.getHasTakeOutMeal());
142 1 1. updateCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setHasDiningCam → KILLED
        commons.setHasDiningCam(incoming.getHasDiningCam());
143 1 1. updateCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setLatitude → KILLED
        commons.setLatitude(incoming.getLatitude());
144 1 1. updateCommons : removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setLongitude → KILLED
        commons.setLongitude(incoming.getLongitude());
145
146
        diningCommonsRepository.save(commons);
147
148 1 1. updateCommons : replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::updateCommons → KILLED
        return commons;
149
    }
150
}

Mutations

47

1.1
Location : allCommonss
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:logged_in_user_can_get_all_diningcommons()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/dining/controllers/DiningCommonsController::allCommonss → KILLED

61

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

63

1.1
Location : getById
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:test_that_logged_in_user_can_get_by_id_when_the_id_exists()]
replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::getById → KILLED

92

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setCode → KILLED

93

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setName → KILLED

94

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setHasSackMeal → KILLED

95

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setHasTakeOutMeal → KILLED

96

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setHasDiningCam → KILLED

97

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setLatitude → KILLED

98

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setLongitude → KILLED

102

1.1
Location : postCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()]
replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::postCommons → KILLED

116

1.1
Location : lambda$deleteCommons$1
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:admin_tries_to_delete_non_existant_commons_and_gets_right_error_message()]
replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::lambda$deleteCommons$1 → KILLED

118

1.1
Location : deleteCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:admin_can_delete_a_date()]
removed call to edu/ucsb/cs156/dining/repositories/DiningCommonsRepository::delete → KILLED

119

1.1
Location : deleteCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:admin_can_delete_a_date()]
replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::deleteCommons → KILLED

136

1.1
Location : lambda$updateCommons$2
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:admin_cannot_edit_commons_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::lambda$updateCommons$2 → KILLED

139

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setName → KILLED

140

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setHasSackMeal → KILLED

141

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setHasTakeOutMeal → KILLED

142

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setHasDiningCam → KILLED

143

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setLatitude → KILLED

144

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
removed call to edu/ucsb/cs156/dining/entities/DiningCommons::setLongitude → KILLED

148

1.1
Location : updateCommons
Killed by : edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.DiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()]
replaced return value with null for edu/ucsb/cs156/dining/controllers/DiningCommonsController::updateCommons → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0