| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.Schools; | |
| 4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.example.repositories.SchoolsRepository; | |
| 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.security.access.prepost.PreAuthorize; | |
| 15 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 16 | import org.springframework.web.bind.annotation.GetMapping; | |
| 17 | import org.springframework.web.bind.annotation.PostMapping; | |
| 18 | import org.springframework.web.bind.annotation.PutMapping; | |
| 19 | import org.springframework.web.bind.annotation.RequestBody; | |
| 20 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 21 | import org.springframework.web.bind.annotation.RequestParam; | |
| 22 | import org.springframework.web.bind.annotation.RestController; | |
| 23 | ||
| 24 | import javax.validation.Valid; | |
| 25 | ||
| 26 | ||
| 27 | @Api(description = "Schools") | |
| 28 | @RequestMapping("/api/schools") | |
| 29 | @RestController | |
| 30 | @Slf4j | |
| 31 | public class SchoolsController extends ApiController { | |
| 32 | ||
| 33 | @Autowired | |
| 34 | SchoolsRepository schoolsRepository; | |
| 35 | ||
| 36 | @ApiOperation(value = "List all schools") | |
| 37 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 38 | @GetMapping("/all") | |
| 39 | public Iterable<Schools> allSchools() { | |
| 40 | Iterable<Schools> schools = schoolsRepository.findAll(); | |
| 41 |
1
1. allSchools : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::allSchools → KILLED |
return schools; |
| 42 | } | |
| 43 | ||
| 44 | @ApiOperation(value = "Get a single school") | |
| 45 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 46 | @GetMapping("") | |
| 47 | public Schools getById( | |
| 48 | @ApiParam("id") @RequestParam Long id) { | |
| 49 | Schools school = schoolsRepository.findById(id) | |
| 50 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Schools.class, id)); |
| 51 | ||
| 52 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::getById → KILLED |
return school; |
| 53 | } | |
| 54 | ||
| 55 | @ApiOperation(value = "Create a new school") | |
| 56 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 57 | @PostMapping("/post") | |
| 58 | public Schools postSchool( | |
| 59 | @ApiParam("name") @RequestParam String name, | |
| 60 | @ApiParam("district") @RequestParam String district, | |
| 61 | @ApiParam("grade range") @RequestParam String gradeRange) | |
| 62 | throws JsonProcessingException { | |
| 63 | ||
| 64 | ||
| 65 | Schools school = new Schools(); | |
| 66 |
1
1. postSchool : removed call to edu/ucsb/cs156/example/entities/Schools::setName → KILLED |
school.setName(name); |
| 67 |
1
1. postSchool : removed call to edu/ucsb/cs156/example/entities/Schools::setDistrict → KILLED |
school.setDistrict(district); |
| 68 |
1
1. postSchool : removed call to edu/ucsb/cs156/example/entities/Schools::setGradeRange → KILLED |
school.setGradeRange(gradeRange); |
| 69 | ||
| 70 | Schools savedSchools = schoolsRepository.save(school); | |
| 71 | ||
| 72 |
1
1. postSchool : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::postSchool → KILLED |
return savedSchools; |
| 73 | } | |
| 74 | ||
| 75 | @ApiOperation(value = "Delete a School") | |
| 76 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 77 | @DeleteMapping("") | |
| 78 | public Object deleteSchool( | |
| 79 | @ApiParam("id") @RequestParam Long id) { | |
| 80 | Schools school = schoolsRepository.findById(id) | |
| 81 |
1
1. lambda$deleteSchool$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::lambda$deleteSchool$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Schools.class, id)); |
| 82 | ||
| 83 |
1
1. deleteSchool : removed call to edu/ucsb/cs156/example/repositories/SchoolsRepository::delete → KILLED |
schoolsRepository.delete(school); |
| 84 |
1
1. deleteSchool : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::deleteSchool → KILLED |
return genericMessage("School with id %s deleted".formatted(id)); |
| 85 | } | |
| 86 | ||
| 87 | @ApiOperation(value = "Update a single school") | |
| 88 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 89 | @PutMapping("") | |
| 90 | public Schools updateSchool( | |
| 91 | @ApiParam("id") @RequestParam Long id, | |
| 92 | @RequestBody @Valid Schools incoming) { | |
| 93 | ||
| 94 | Schools school = schoolsRepository.findById(id) | |
| 95 |
1
1. lambda$updateSchool$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::lambda$updateSchool$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Schools.class, id)); |
| 96 | ||
| 97 |
1
1. updateSchool : removed call to edu/ucsb/cs156/example/entities/Schools::setName → KILLED |
school.setName(incoming.getName()); |
| 98 |
1
1. updateSchool : removed call to edu/ucsb/cs156/example/entities/Schools::setDistrict → KILLED |
school.setDistrict(incoming.getDistrict()); |
| 99 |
1
1. updateSchool : removed call to edu/ucsb/cs156/example/entities/Schools::setGradeRange → KILLED |
school.setGradeRange(incoming.getGradeRange()); |
| 100 | ||
| 101 | schoolsRepository.save(school); | |
| 102 | ||
| 103 |
1
1. updateSchool : replaced return value with null for edu/ucsb/cs156/example/controllers/SchoolsController::updateSchool → KILLED |
return school; |
| 104 | } | |
| 105 | } | |
Mutations | ||
| 41 |
1.1 |
|
| 50 |
1.1 |
|
| 52 |
1.1 |
|
| 66 |
1.1 |
|
| 67 |
1.1 |
|
| 68 |
1.1 |
|
| 72 |
1.1 |
|
| 81 |
1.1 |
|
| 83 |
1.1 |
|
| 84 |
1.1 |
|
| 95 |
1.1 |
|
| 97 |
1.1 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 103 |
1.1 |