1 | package edu.ucsb.cs156.organic.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.organic.entities.School; | |
4 | import edu.ucsb.cs156.organic.errors.EntityNotFoundException; | |
5 | import edu.ucsb.cs156.organic.repositories.SchoolRepository; | |
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 com.fasterxml.jackson.core.JsonProcessingException; | |
13 | ||
14 | import org.springframework.beans.factory.annotation.Autowired; | |
15 | import org.springframework.format.annotation.DateTimeFormat; | |
16 | import org.springframework.security.access.prepost.PreAuthorize; | |
17 | import org.springframework.web.bind.annotation.DeleteMapping; | |
18 | import org.springframework.web.bind.annotation.GetMapping; | |
19 | import org.springframework.web.bind.annotation.PostMapping; | |
20 | import org.springframework.web.bind.annotation.PutMapping; | |
21 | import org.springframework.web.bind.annotation.RequestBody; | |
22 | import org.springframework.web.bind.annotation.RequestMapping; | |
23 | import org.springframework.web.bind.annotation.RequestParam; | |
24 | import org.springframework.web.bind.annotation.RestController; | |
25 | ||
26 | import javax.validation.Valid; | |
27 | ||
28 | import java.time.LocalDateTime; | |
29 | ||
30 | @Tag(name = "Schools") | |
31 | @RequestMapping("/api/Schools") | |
32 | @RestController | |
33 | @Slf4j | |
34 | public class SchoolsController extends ApiController { | |
35 | ||
36 | @Autowired | |
37 | SchoolRepository schoolRepository; | |
38 | ||
39 | @Operation(summary= "List all schools") | |
40 | @PreAuthorize("hasRole('ROLE_USER')") | |
41 | @GetMapping("/all") | |
42 | public Iterable<School> allSchools() { | |
43 | Iterable<School> schools = schoolRepository.findAll(); | |
44 |
1
1. allSchools : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::allSchools → KILLED |
return schools; |
45 | } | |
46 | ||
47 | @Operation(summary= "Create a new school") | |
48 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
49 | @PostMapping("/post") | |
50 | public School postSchool( | |
51 | @Parameter(name="abbrev") @RequestParam String abbrev, | |
52 | @Parameter(name="name") @RequestParam String name, | |
53 | @Parameter(name="termRegex") @RequestParam String termRegex, | |
54 | @Parameter(name="termDescription") @RequestParam String termDescription, | |
55 | @Parameter(name="termError") @RequestParam String termError) | |
56 | throws JsonProcessingException { | |
57 | ||
58 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
59 | // See: https://www.baeldung.com/spring-date-parameters | |
60 | ||
61 | // log.info("localDateTime={}", localDateTime); | |
62 | ||
63 | School school = new School(); | |
64 |
1
1. postSchool : removed call to edu/ucsb/cs156/organic/entities/School::setAbbrev → KILLED |
school.setAbbrev(abbrev); |
65 |
1
1. postSchool : removed call to edu/ucsb/cs156/organic/entities/School::setName → KILLED |
school.setName(name); |
66 |
1
1. postSchool : removed call to edu/ucsb/cs156/organic/entities/School::setTermRegex → KILLED |
school.setTermRegex(termRegex); |
67 |
1
1. postSchool : removed call to edu/ucsb/cs156/organic/entities/School::setTermDescription → KILLED |
school.setTermDescription(termDescription); |
68 |
1
1. postSchool : removed call to edu/ucsb/cs156/organic/entities/School::setTermError → KILLED |
school.setTermError(termError); |
69 | ||
70 | School savedSchool = schoolRepository.save(school); | |
71 | ||
72 |
1
1. postSchool : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::postSchool → KILLED |
return savedSchool; |
73 | } | |
74 | ||
75 | @Operation(summary= "Get a single school") | |
76 | @PreAuthorize("hasRole('ROLE_USER')") | |
77 | @GetMapping("") | |
78 | public School getById( | |
79 | @Parameter(name="id") @RequestParam Long id) { | |
80 | School school = schoolRepository.findById(id) | |
81 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(School.class, id)); |
82 | ||
83 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::getById → KILLED |
return school; |
84 | } | |
85 | ||
86 | @Operation(summary= "Delete a school") | |
87 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
88 | @DeleteMapping("") | |
89 | public Object deleteSchool( | |
90 | @Parameter(name="id") @RequestParam Long id) { | |
91 | School school = schoolRepository.findById(id) | |
92 |
1
1. lambda$deleteSchool$1 : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::lambda$deleteSchool$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(School.class, id)); |
93 | ||
94 |
1
1. deleteSchool : removed call to edu/ucsb/cs156/organic/repositories/SchoolRepository::delete → KILLED |
schoolRepository.delete(school); |
95 |
1
1. deleteSchool : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::deleteSchool → KILLED |
return genericMessage("School with id %s deleted".formatted(id)); |
96 | } | |
97 | ||
98 | @Operation(summary= "Update a school") | |
99 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
100 | @PutMapping("") | |
101 | public School updateSchool( | |
102 | @Parameter(name="id") @RequestParam Long id, | |
103 | @RequestBody @Valid School incoming) { | |
104 | ||
105 | School school = schoolRepository.findById(id) | |
106 |
1
1. lambda$updateSchool$2 : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::lambda$updateSchool$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(School.class, id)); |
107 | ||
108 |
1
1. updateSchool : removed call to edu/ucsb/cs156/organic/entities/School::setAbbrev → KILLED |
school.setAbbrev(incoming.getAbbrev()); |
109 |
1
1. updateSchool : removed call to edu/ucsb/cs156/organic/entities/School::setName → KILLED |
school.setName(incoming.getName()); |
110 |
1
1. updateSchool : removed call to edu/ucsb/cs156/organic/entities/School::setTermRegex → KILLED |
school.setTermRegex(incoming.getTermRegex()); |
111 |
1
1. updateSchool : removed call to edu/ucsb/cs156/organic/entities/School::setTermDescription → KILLED |
school.setTermDescription(incoming.getTermDescription()); |
112 |
1
1. updateSchool : removed call to edu/ucsb/cs156/organic/entities/School::setTermError → KILLED |
school.setTermError(incoming.getTermError()); |
113 | ||
114 | schoolRepository.save(school); | |
115 | ||
116 |
1
1. updateSchool : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::updateSchool → KILLED |
return school; |
117 | } | |
118 | ||
119 | } | |
Mutations | ||
44 |
1.1 |
|
64 |
1.1 |
|
65 |
1.1 |
|
66 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 |
|
72 |
1.1 |
|
81 |
1.1 |
|
83 |
1.1 |
|
92 |
1.1 |
|
94 |
1.1 |
|
95 |
1.1 |
|
106 |
1.1 |
|
108 |
1.1 |
|
109 |
1.1 |
|
110 |
1.1 |
|
111 |
1.1 |
|
112 |
1.1 |
|
116 |
1.1 |