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