1
|
|
package edu.ucsb.cs156.example.controllers; |
2
|
|
|
3
|
|
import edu.ucsb.cs156.example.entities.UCSBDiningCommons; |
4
|
|
import edu.ucsb.cs156.example.errors.EntityNotFoundException; |
5
|
|
import edu.ucsb.cs156.example.repositories.UCSBDiningCommonsRepository; |
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 UCSBDiningCommons |
27
|
|
*/ |
28
|
|
|
29
|
|
@Tag(name = "UCSBDiningCommons") |
30
|
|
@RequestMapping("/api/ucsbdiningcommons") |
31
|
|
@RestController |
32
|
|
@Slf4j |
33
|
|
public class UCSBDiningCommonsController extends ApiController { |
34
|
|
|
35
|
|
@Autowired |
36
|
|
UCSBDiningCommonsRepository ucsbDiningCommonsRepository; |
37
|
|
|
38
|
|
/** |
39
|
|
* THis method returns a list of all ucsbdiningcommons. |
40
|
|
* @return a list of all ucsbdiningcommons |
41
|
|
*/ |
42
|
|
@Operation(summary= "List all ucsb dining commons") |
43
|
|
@PreAuthorize("hasRole('ROLE_USER')") |
44
|
|
@GetMapping("/all") |
45
|
|
public Iterable<UCSBDiningCommons> allCommonss() { |
46
|
|
Iterable<UCSBDiningCommons> commons = ucsbDiningCommonsRepository.findAll(); |
47
|
1
1. allCommonss : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::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 commons") |
56
|
|
@PreAuthorize("hasRole('ROLE_USER')") |
57
|
|
@GetMapping("") |
58
|
|
public UCSBDiningCommons getById( |
59
|
|
@Parameter(name="code") @RequestParam String code) { |
60
|
|
UCSBDiningCommons commons = ucsbDiningCommonsRepository.findById(code) |
61
|
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$getById$0 → KILLED
|
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code)); |
62
|
|
|
63
|
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::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 commons") |
78
|
|
@PreAuthorize("hasRole('ROLE_ADMIN')") |
79
|
|
@PostMapping("/post") |
80
|
|
public UCSBDiningCommons 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
|
|
UCSBDiningCommons commons = new UCSBDiningCommons(); |
92
|
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setCode → KILLED
|
commons.setCode(code); |
93
|
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED
|
commons.setName(name); |
94
|
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED
|
commons.setHasSackMeal(hasSackMeal); |
95
|
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED
|
commons.setHasTakeOutMeal(hasTakeOutMeal); |
96
|
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED
|
commons.setHasDiningCam(hasDiningCam); |
97
|
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED
|
commons.setLatitude(latitude); |
98
|
1
1. postCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED
|
commons.setLongitude(longitude); |
99
|
|
|
100
|
|
UCSBDiningCommons savedCommons = ucsbDiningCommonsRepository.save(commons); |
101
|
|
|
102
|
1
1. postCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::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 UCSBDiningCommons") |
111
|
|
@PreAuthorize("hasRole('ROLE_ADMIN')") |
112
|
|
@DeleteMapping("") |
113
|
|
public Object deleteCommons( |
114
|
|
@Parameter(name="code") @RequestParam String code) { |
115
|
|
UCSBDiningCommons commons = ucsbDiningCommonsRepository.findById(code) |
116
|
1
1. lambda$deleteCommons$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$deleteCommons$1 → KILLED
|
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code)); |
117
|
|
|
118
|
1
1. deleteCommons : removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsRepository::delete → KILLED
|
ucsbDiningCommonsRepository.delete(commons); |
119
|
1
1. deleteCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::deleteCommons → KILLED
|
return genericMessage("UCSBDiningCommons 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 commons") |
129
|
|
@PreAuthorize("hasRole('ROLE_ADMIN')") |
130
|
|
@PutMapping("") |
131
|
|
public UCSBDiningCommons updateCommons( |
132
|
|
@Parameter(name="code") @RequestParam String code, |
133
|
|
@RequestBody @Valid UCSBDiningCommons incoming) { |
134
|
|
|
135
|
|
UCSBDiningCommons commons = ucsbDiningCommonsRepository.findById(code) |
136
|
1
1. lambda$updateCommons$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$updateCommons$2 → KILLED
|
.orElseThrow(() -> new EntityNotFoundException(UCSBDiningCommons.class, code)); |
137
|
|
|
138
|
|
|
139
|
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED
|
commons.setName(incoming.getName()); |
140
|
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED
|
commons.setHasSackMeal(incoming.getHasSackMeal()); |
141
|
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED
|
commons.setHasTakeOutMeal(incoming.getHasTakeOutMeal()); |
142
|
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED
|
commons.setHasDiningCam(incoming.getHasDiningCam()); |
143
|
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED
|
commons.setLatitude(incoming.getLatitude()); |
144
|
1
1. updateCommons : removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED
|
commons.setLongitude(incoming.getLongitude()); |
145
|
|
|
146
|
|
ucsbDiningCommonsRepository.save(commons); |
147
|
|
|
148
|
1
1. updateCommons : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::updateCommons → KILLED
|
return commons; |
149
|
|
} |
150
|
|
} |
| | Mutations |
47 |
|
1.1 Location : allCommonss Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:logged_in_user_can_get_all_ucsbdiningcommons()] replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::allCommonss → KILLED
|
61 |
|
1.1 Location : lambda$getById$0 Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[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/UCSBDiningCommonsController::lambda$getById$0 → KILLED
|
63 |
|
1.1 Location : getById Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[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/UCSBDiningCommonsController::getById → KILLED
|
92 |
|
1.1 Location : postCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setCode → KILLED
|
93 |
|
1.1 Location : postCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED
|
94 |
|
1.1 Location : postCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED
|
95 |
|
1.1 Location : postCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED
|
96 |
|
1.1 Location : postCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED
|
97 |
|
1.1 Location : postCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED
|
98 |
|
1.1 Location : postCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED
|
102 |
|
1.1 Location : postCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:an_admin_user_can_post_a_new_commons()] replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::postCommons → KILLED
|
116 |
|
1.1 Location : lambda$deleteCommons$1 Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_tries_to_delete_non_existant_commons_and_gets_right_error_message()] replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$deleteCommons$1 → KILLED
|
118 |
|
1.1 Location : deleteCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_delete_a_date()] removed call to edu/ucsb/cs156/example/repositories/UCSBDiningCommonsRepository::delete → KILLED
|
119 |
|
1.1 Location : deleteCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_delete_a_date()] replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::deleteCommons → KILLED
|
136 |
|
1.1 Location : lambda$updateCommons$2 Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_cannot_edit_commons_that_does_not_exist()] replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::lambda$updateCommons$2 → KILLED
|
139 |
|
1.1 Location : updateCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setName → KILLED
|
140 |
|
1.1 Location : updateCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasSackMeal → KILLED
|
141 |
|
1.1 Location : updateCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasTakeOutMeal → KILLED
|
142 |
|
1.1 Location : updateCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setHasDiningCam → KILLED
|
143 |
|
1.1 Location : updateCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLatitude → KILLED
|
144 |
|
1.1 Location : updateCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()] removed call to edu/ucsb/cs156/example/entities/UCSBDiningCommons::setLongitude → KILLED
|
148 |
|
1.1 Location : updateCommons Killed by : edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBDiningCommonsControllerTests]/[method:admin_can_edit_an_existing_commons()] replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDiningCommonsController::updateCommons → KILLED
|