1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
5 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
6 | import io.swagger.annotations.Api; | |
7 | import io.swagger.annotations.ApiOperation; | |
8 | import io.swagger.annotations.ApiParam; | |
9 | import lombok.extern.slf4j.Slf4j; | |
10 | ||
11 | import com.fasterxml.jackson.core.JsonProcessingException; | |
12 | ||
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 | import javax.validation.Valid; | |
26 | ||
27 | import java.time.LocalDateTime; | |
28 | ||
29 | @Api(description = "UCSBDates") | |
30 | @RequestMapping("/api/ucsbdates") | |
31 | @RestController | |
32 | @Slf4j | |
33 | public class UCSBDatesController extends ApiController { | |
34 | ||
35 | @Autowired | |
36 | UCSBDateRepository ucsbDateRepository; | |
37 | ||
38 | @ApiOperation(value = "List all ucsb dates") | |
39 | @PreAuthorize("hasRole('ROLE_USER')") | |
40 | @GetMapping("/all") | |
41 | public Iterable<UCSBDate> allUCSBDates() { | |
42 | Iterable<UCSBDate> dates = ucsbDateRepository.findAll(); | |
43 |
1
1. allUCSBDates : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::allUCSBDates → KILLED |
return dates; |
44 | } | |
45 | ||
46 | @ApiOperation(value = "Get a single date") | |
47 | @PreAuthorize("hasRole('ROLE_USER')") | |
48 | @GetMapping("") | |
49 | public UCSBDate getById( | |
50 | @ApiParam("id") @RequestParam Long id) { | |
51 | UCSBDate ucsbDate = ucsbDateRepository.findById(id) | |
52 |
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)); |
53 | ||
54 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::getById → KILLED |
return ucsbDate; |
55 | } | |
56 | ||
57 | @ApiOperation(value = "Create a new date") | |
58 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
59 | @PostMapping("/post") | |
60 | public UCSBDate postUCSBDate( | |
61 | @ApiParam("quarterYYYYQ") @RequestParam String quarterYYYYQ, | |
62 | @ApiParam("name") @RequestParam String name, | |
63 | @ApiParam("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) | |
64 | throws JsonProcessingException { | |
65 | ||
66 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
67 | // See: https://www.baeldung.com/spring-date-parameters | |
68 | ||
69 | log.info("localDateTime={}", localDateTime); | |
70 | ||
71 | UCSBDate ucsbDate = new UCSBDate(); | |
72 |
1
1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setQuarterYYYYQ → KILLED |
ucsbDate.setQuarterYYYYQ(quarterYYYYQ); |
73 |
1
1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setName → KILLED |
ucsbDate.setName(name); |
74 |
1
1. postUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setLocalDateTime → KILLED |
ucsbDate.setLocalDateTime(localDateTime); |
75 | ||
76 | UCSBDate savedUcsbDate = ucsbDateRepository.save(ucsbDate); | |
77 | ||
78 |
1
1. postUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::postUCSBDate → KILLED |
return savedUcsbDate; |
79 | } | |
80 | ||
81 | @ApiOperation(value = "Delete a UCSBDate") | |
82 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
83 | @DeleteMapping("") | |
84 | public Object deleteUCSBDate( | |
85 | @ApiParam("id") @RequestParam Long id) { | |
86 | UCSBDate ucsbDate = ucsbDateRepository.findById(id) | |
87 |
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)); |
88 | ||
89 |
1
1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/UCSBDateRepository::delete → KILLED |
ucsbDateRepository.delete(ucsbDate); |
90 |
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)); |
91 | } | |
92 | ||
93 | @ApiOperation(value = "Update a single date") | |
94 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
95 | @PutMapping("") | |
96 | public UCSBDate updateUCSBDate( | |
97 | @ApiParam("id") @RequestParam Long id, | |
98 | @RequestBody @Valid UCSBDate incoming) { | |
99 | ||
100 | UCSBDate ucsbDate = ucsbDateRepository.findById(id) | |
101 |
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)); |
102 | ||
103 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setQuarterYYYYQ → KILLED |
ucsbDate.setQuarterYYYYQ(incoming.getQuarterYYYYQ()); |
104 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setName → KILLED |
ucsbDate.setName(incoming.getName()); |
105 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/UCSBDate::setLocalDateTime → KILLED |
ucsbDate.setLocalDateTime(incoming.getLocalDateTime()); |
106 | ||
107 | ucsbDateRepository.save(ucsbDate); | |
108 | ||
109 |
1
1. updateUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/UCSBDatesController::updateUCSBDate → KILLED |
return ucsbDate; |
110 | } | |
111 | } | |
Mutations | ||
43 |
1.1 |
|
52 |
1.1 |
|
54 |
1.1 |
|
72 |
1.1 |
|
73 |
1.1 |
|
74 |
1.1 |
|
78 |
1.1 |
|
87 |
1.1 |
|
89 |
1.1 |
|
90 |
1.1 |
|
101 |
1.1 |
|
103 |
1.1 |
|
104 |
1.1 |
|
105 |
1.1 |
|
109 |
1.1 |