| 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 | import com.fasterxml.jackson.databind.ObjectMapper; | |
| 14 | ||
| 15 | import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | import org.springframework.http.ResponseEntity; | |
| 17 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 18 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 19 | import org.springframework.web.bind.annotation.GetMapping; | |
| 20 | import org.springframework.web.bind.annotation.PostMapping; | |
| 21 | import org.springframework.web.bind.annotation.PutMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestBody; | |
| 23 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 24 | import org.springframework.web.bind.annotation.RequestParam; | |
| 25 | import org.springframework.web.bind.annotation.RestController; | |
| 26 | ||
| 27 | import javax.validation.Valid; | |
| 28 | ||
| 29 | @Tag(name = "Schools") | |
| 30 | @RequestMapping("/api/schools") | |
| 31 | @RestController | |
| 32 | @Slf4j | |
| 33 | public class SchoolsController extends ApiController { | |
| 34 | ||
| 35 | @Autowired | |
| 36 | SchoolRepository schoolRepository; | |
| 37 | ||
| 38 | @Autowired | |
| 39 | ObjectMapper mapper; | |
| 40 | ||
| 41 | @Operation(summary = "List all schools") | |
| 42 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 43 | @GetMapping("/all") | |
| 44 | public Iterable<School> schools() { | |
| 45 | log.info("REACHED HERE!!!"); | |
| 46 | Iterable<School> schools = schoolRepository.findAll(); | |
| 47 | log.info("schools={}", schools); | |
| 48 |
1
1. schools : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::schools → KILLED |
return schools; |
| 49 | } | |
| 50 | ||
| 51 | @Operation(summary = "Get a single school") | |
| 52 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 53 | @GetMapping("") | |
| 54 | public School getByAbbrev( | |
| 55 | @Parameter(name = "abbrev") @RequestParam String abbrev) { | |
| 56 | School school = schoolRepository.findByAbbrev(abbrev) | |
| 57 |
1
1. lambda$getByAbbrev$0 : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::lambda$getByAbbrev$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(School.class, abbrev)); |
| 58 | ||
| 59 |
1
1. getByAbbrev : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::getByAbbrev → KILLED |
return school; |
| 60 | } | |
| 61 | ||
| 62 | @Operation(summary = "Create a new school") | |
| 63 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 64 | @PostMapping("/post") | |
| 65 | public School postSchool( | |
| 66 | @Parameter(name = "abbrev", description ="school abbrevation, e.g. ucsb" ) @RequestParam String abbrev, | |
| 67 | @Parameter(name = "name", description ="school name e.g. UC Santa Barbara" ) @RequestParam String name, | |
| 68 | @Parameter(name = "termRegex", description = "term regex, e.g. [WSMF]\\d\\d") @RequestParam String termRegex, | |
| 69 | @Parameter(name = "termDescription", description = "Enter quarter, e.g. F23, W24, S24, M24") @RequestParam String termDescription, | |
| 70 | @Parameter(name = "termError", description = "term error, e.g. Quarter must be entered in the correct format") @RequestParam String termError) | |
| 71 | throws JsonProcessingException { | |
| 72 | ||
| 73 | School school = School.builder() | |
| 74 | .abbrev(abbrev) | |
| 75 | .name(name) | |
| 76 | .termRegex(termRegex) | |
| 77 | .termDescription(termDescription) | |
| 78 | .termError(termError) | |
| 79 | .build(); | |
| 80 | ||
| 81 | School savedSchool = schoolRepository.save(school); | |
| 82 | ||
| 83 |
1
1. postSchool : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::postSchool → KILLED |
return savedSchool; |
| 84 | } | |
| 85 | ||
| 86 | @Operation(summary = "Update a school") | |
| 87 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 88 | @PutMapping("/update") | |
| 89 | public School updateSchool( | |
| 90 | @Parameter(name = "abbrev", description ="school abbrevation, e.g. ucsb" ) | |
| 91 | @RequestParam String abbrev, | |
| 92 | @RequestBody @Valid School incoming) { | |
| 93 | ||
| 94 | School school = schoolRepository.findByAbbrev(abbrev) | |
| 95 |
1
1. lambda$updateSchool$1 : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::lambda$updateSchool$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(School.class, abbrev)); |
| 96 | | |
| 97 |
1
1. updateSchool : removed call to edu/ucsb/cs156/organic/entities/School::setName → KILLED |
school.setName(incoming.getName()); |
| 98 |
1
1. updateSchool : removed call to edu/ucsb/cs156/organic/entities/School::setTermRegex → KILLED |
school.setTermRegex(incoming.getTermRegex()); |
| 99 |
1
1. updateSchool : removed call to edu/ucsb/cs156/organic/entities/School::setTermDescription → KILLED |
school.setTermDescription(incoming.getTermDescription()); |
| 100 |
1
1. updateSchool : removed call to edu/ucsb/cs156/organic/entities/School::setTermError → KILLED |
school.setTermError(incoming.getTermError()); |
| 101 | ||
| 102 | schoolRepository.save(school); | |
| 103 | ||
| 104 |
1
1. updateSchool : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::updateSchool → KILLED |
return school; |
| 105 | } | |
| 106 | ||
| 107 | @Operation(summary = "Delete a school") | |
| 108 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 109 | @DeleteMapping("/delete") | |
| 110 | public Object deleteSchool( | |
| 111 | @Parameter(name = "abbrev", description ="school abbrevation, e.g. ucsb" ) | |
| 112 | @RequestParam String abbrev) | |
| 113 | throws JsonProcessingException { | |
| 114 | ||
| 115 | School school = schoolRepository.findByAbbrev(abbrev) | |
| 116 |
1
1. lambda$deleteSchool$2 : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::lambda$deleteSchool$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(School.class, abbrev)); |
| 117 | | |
| 118 |
1
1. deleteSchool : removed call to edu/ucsb/cs156/organic/repositories/SchoolRepository::delete → KILLED |
schoolRepository.delete(school); |
| 119 | ||
| 120 |
1
1. deleteSchool : replaced return value with null for edu/ucsb/cs156/organic/controllers/SchoolsController::deleteSchool → KILLED |
return genericMessage("School with abbrev %s deleted.".formatted(abbrev)); |
| 121 | } | |
| 122 | ||
| 123 | } | |
Mutations | ||
| 48 |
1.1 |
|
| 57 |
1.1 |
|
| 59 |
1.1 |
|
| 83 |
1.1 |
|
| 95 |
1.1 |
|
| 97 |
1.1 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 100 |
1.1 |
|
| 104 |
1.1 |
|
| 116 |
1.1 |
|
| 118 |
1.1 |
|
| 120 |
1.1 |