| 1 | package edu.ucsb.cs156.courses.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.courses.errors.BadEnrollCdException; | |
| 4 | import edu.ucsb.cs156.courses.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.courses.models.CurrentUser; | |
| 6 | import edu.ucsb.cs156.courses.services.CurrentUserService; | |
| 7 | import java.util.Map; | |
| 8 | import lombok.extern.slf4j.Slf4j; | |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | import org.springframework.http.HttpStatus; | |
| 11 | import org.springframework.web.bind.annotation.ExceptionHandler; | |
| 12 | import org.springframework.web.bind.annotation.ResponseStatus; | |
| 13 | ||
| 14 | @Slf4j | |
| 15 | public abstract class ApiController { | |
| 16 | @Autowired private CurrentUserService currentUserService; | |
| 17 | ||
| 18 | protected CurrentUser getCurrentUser() { | |
| 19 |
1
1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::getCurrentUser → KILLED |
return currentUserService.getCurrentUser(); |
| 20 | } | |
| 21 | ||
| 22 | protected Object genericMessage(String message) { | |
| 23 |
1
1. genericMessage : replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::genericMessage → KILLED |
return Map.of("message", message); |
| 24 | } | |
| 25 | ||
| 26 | @ExceptionHandler({EntityNotFoundException.class, BadEnrollCdException.class}) | |
| 27 | @ResponseStatus(HttpStatus.NOT_FOUND) | |
| 28 | public Object handleGenericException(Throwable e) { | |
| 29 |
1
1. handleGenericException : replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::handleGenericException → KILLED |
return Map.of( |
| 30 | "type", e.getClass().getSimpleName(), | |
| 31 | "message", e.getMessage()); | |
| 32 | } | |
| 33 | ||
| 34 | @ExceptionHandler({IllegalArgumentException.class}) | |
| 35 | @ResponseStatus(HttpStatus.BAD_REQUEST) | |
| 36 | public Object handleIllegalArgumentException(Throwable e) { | |
| 37 |
1
1. handleIllegalArgumentException : replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::handleIllegalArgumentException → KILLED |
return Map.of( |
| 38 | "type", e.getClass().getSimpleName(), | |
| 39 | "message", e.getMessage()); | |
| 40 | } | |
| 41 | } | |
Mutations | ||
| 19 |
1.1 |
|
| 23 |
1.1 |
|
| 29 |
1.1 |
|
| 37 |
1.1 |