1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.MenuItemReview; | |
4 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
6 | import edu.ucsb.cs156.example.repositories.MenuItemReviewRepository; | |
7 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
8 | ||
9 | import io.swagger.v3.oas.annotations.Operation; | |
10 | import io.swagger.v3.oas.annotations.Parameter; | |
11 | import io.swagger.v3.oas.annotations.tags.Tag; | |
12 | import lombok.extern.slf4j.Slf4j; | |
13 | ||
14 | import com.fasterxml.jackson.core.JsonProcessingException; | |
15 | ||
16 | import org.springframework.beans.factory.annotation.Autowired; | |
17 | import org.springframework.format.annotation.DateTimeFormat; | |
18 | import org.springframework.security.access.prepost.PreAuthorize; | |
19 | import org.springframework.web.bind.annotation.DeleteMapping; | |
20 | import org.springframework.web.bind.annotation.GetMapping; | |
21 | import org.springframework.web.bind.annotation.PostMapping; | |
22 | import org.springframework.web.bind.annotation.PutMapping; | |
23 | import org.springframework.web.bind.annotation.RequestBody; | |
24 | import org.springframework.web.bind.annotation.RequestMapping; | |
25 | import org.springframework.web.bind.annotation.RequestParam; | |
26 | import org.springframework.web.bind.annotation.RestController; | |
27 | ||
28 | import jakarta.validation.Valid; | |
29 | ||
30 | import java.time.LocalDateTime; | |
31 | ||
32 | /** | |
33 | * This is a REST controller for UCSBDates | |
34 | */ | |
35 | ||
36 | @Tag(name = "UCSBDates") | |
37 | @RequestMapping("/api/ucsbdates") | |
38 | @RestController | |
39 | @Slf4j | |
40 | public class UCSBDatesController extends ApiController { | |
41 | ||
42 | @Autowired | |
43 | UCSBDateRepository ucsbDateRepository; | |
44 | ||
45 | /** | |
46 | * List all UCSB dates | |
47 | * | |
48 | * @return an iterable of UCSBDate | |
49 | */ | |
50 | @Operation(summary= "List all ucsb dates") | |
51 | @PreAuthorize("hasRole('ROLE_USER')") | |
52 | @GetMapping("/all") | |
53 | public Iterable<UCSBDate> allUCSBDates() { | |
54 | Iterable<UCSBDate> dates = ucsbDateRepository.findAll(); | |
55 |
1
1. allUCSBDates : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/UCSBDatesController::allUCSBDates → KILLED |
return dates; |
56 | } | |
57 | ||
58 | /** | |
59 | * Get a single date by id | |
60 | * | |
61 | * @param id the id of the date | |
62 | * @return a UCSBDate | |
63 | */ | |
64 | @Operation(summary= "Get a single date") | |
65 | @PreAuthorize("hasRole('ROLE_USER')") | |
66 | @GetMapping("") | |
67 | public UCSBDate getById( | |
68 | @Parameter(name="id") @RequestParam Long id) { | |
69 | UCSBDate ucsbDate = ucsbDateRepository.findById(id) | |
70 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDate.class, id)); |
71 | ||
72 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::getById → KILLED |
return ucsbDate; |
73 | } | |
74 | ||
75 | /** | |
76 | * Create a new date | |
77 | * | |
78 | * @param quarterYYYYQ the quarter in the format YYYYQ | |
79 | * @param name the name of the date | |
80 | * @param localDateTime the date | |
81 | * @return the saved ucsbdate | |
82 | */ | |
83 | @Operation(summary= "Create a new date") | |
84 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
85 | @PostMapping("/post") | |
86 | public UCSBDate postUCSBDate( | |
87 | @Parameter(name="quarterYYYYQ") @RequestParam String quarterYYYYQ, | |
88 | @Parameter(name="name") @RequestParam String name, | |
89 | @Parameter(name="localDateTime", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("localDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime localDateTime) | |
90 | throws JsonProcessingException { | |
91 | ||
92 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
93 | // See: https://www.baeldung.com/spring-date-parameters | |
94 | ||
95 | log.info("localDateTime={}", localDateTime); | |
96 | ||
97 | UCSBDate ucsbDate = new UCSBDate(); | |
98 |
1
1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setQuarterYYYYQ → KILLED |
ucsbDate.setQuarterYYYYQ(quarterYYYYQ); |
99 |
1
1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setName → KILLED |
ucsbDate.setName(name); |
100 |
1
1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setLocalDateTime → KILLED |
ucsbDate.setLocalDateTime(localDateTime); |
101 | ||
102 | UCSBDate savedUcsbDate = ucsbDateRepository.save(ucsbDate); | |
103 | ||
104 |
1
1. postUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::postUCSBDate → KILLED |
return savedUcsbDate; |
105 | } | |
106 | ||
107 | /** | |
108 | * Delete a UCSBDate | |
109 | * | |
110 | * @param id the id of the date to delete | |
111 | * @return a message indicating the date was deleted | |
112 | */ | |
113 | @Operation(summary= "Delete a UCSBDate") | |
114 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
115 | @DeleteMapping("") | |
116 | public Object deleteUCSBDate( | |
117 | @Parameter(name="id") @RequestParam Long id) { | |
118 | UCSBDate ucsbDate = ucsbDateRepository.findById(id) | |
119 |
1
1. lambda$deleteUCSBDate$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::lambda$deleteUCSBDate$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDate.class, id)); |
120 | ||
121 |
1
1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/UCSBDateRepository::delete → KILLED |
ucsbDateRepository.delete(ucsbDate); |
122 |
1
1. deleteUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::deleteUCSBDate → KILLED |
return genericMessage("UCSBDate with id %s deleted".formatted(id)); |
123 | } | |
124 | ||
125 | /** | |
126 | * Update a single date | |
127 | * | |
128 | * @param id id of the date to update | |
129 | * @param incoming the new date | |
130 | * @return the updated date object | |
131 | */ | |
132 | @Operation(summary= "Update a single date") | |
133 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
134 | @PutMapping("") | |
135 | public UCSBDate updateUCSBDate( | |
136 | @Parameter(name="id") @RequestParam Long id, | |
137 | @RequestBody @Valid UCSBDate incoming) { | |
138 | ||
139 | UCSBDate ucsbDate = ucsbDateRepository.findById(id) | |
140 |
1
1. lambda$updateUCSBDate$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::lambda$updateUCSBDate$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDate.class, id)); |
141 | ||
142 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setQuarterYYYYQ → KILLED |
ucsbDate.setQuarterYYYYQ(incoming.getQuarterYYYYQ()); |
143 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setName → KILLED |
ucsbDate.setName(incoming.getName()); |
144 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setLocalDateTime → KILLED |
ucsbDate.setLocalDateTime(incoming.getLocalDateTime()); |
145 | ||
146 | ucsbDateRepository.save(ucsbDate); | |
147 | ||
148 |
1
1. updateUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::updateUCSBDate → KILLED |
return ucsbDate; |
149 | } | |
150 | } | |
Mutations | ||
55 |
1.1 |
|
70 |
1.1 |
|
72 |
1.1 |
|
98 |
1.1 |
|
99 |
1.1 |
|
100 |
1.1 |
|
104 |
1.1 |
|
119 |
1.1 |
|
121 |
1.1 |
|
122 |
1.1 |
|
140 |
1.1 |
|
142 |
1.1 |
|
143 |
1.1 |
|
144 |
1.1 |
|
148 |
1.1 |