| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 4 | import edu.ucsb.cs156.example.models.CurrentUser; | |
| 5 | import edu.ucsb.cs156.example.services.CurrentUserService; | |
| 6 | import java.util.Map; | |
| 7 | import lombok.extern.slf4j.Slf4j; | |
| 8 | import org.springframework.beans.factory.annotation.Autowired; | |
| 9 | import org.springframework.http.HttpStatus; | |
| 10 | import org.springframework.web.bind.annotation.ExceptionHandler; | |
| 11 | import org.springframework.web.bind.annotation.ResponseStatus; | |
| 12 | ||
| 13 | /** This is an abstract class that provides common functionality for all API controllers. */ | |
| 14 | @Slf4j | |
| 15 | public abstract class ApiController { | |
| 16 | @Autowired private CurrentUserService currentUserService; | |
| 17 | ||
| 18 | /** | |
| 19 | * This method returns the current user. | |
| 20 | * | |
| 21 | * @return the current user | |
| 22 | */ | |
| 23 | protected CurrentUser getCurrentUser() { | |
| 24 |
1
1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/example/controllers/ApiController::getCurrentUser → KILLED |
return currentUserService.getCurrentUser(); |
| 25 | } | |
| 26 | ||
| 27 | /** | |
| 28 | * This method returns a generic message. | |
| 29 | * | |
| 30 | * @param message the message | |
| 31 | * @return a map with the message | |
| 32 | */ | |
| 33 | protected Object genericMessage(String message) { | |
| 34 |
1
1. genericMessage : replaced return value with null for edu/ucsb/cs156/example/controllers/ApiController::genericMessage → KILLED |
return Map.of("message", message); |
| 35 | } | |
| 36 | ||
| 37 | /** | |
| 38 | * This method handles the EntityNotFoundException. | |
| 39 | * | |
| 40 | * @param e the exception | |
| 41 | * @return a map with the type and message of the exception | |
| 42 | */ | |
| 43 | @ExceptionHandler({EntityNotFoundException.class}) | |
| 44 | @ResponseStatus(HttpStatus.NOT_FOUND) | |
| 45 | public Object handleGenericException(Throwable e) { | |
| 46 |
1
1. handleGenericException : replaced return value with null for edu/ucsb/cs156/example/controllers/ApiController::handleGenericException → KILLED |
return Map.of( |
| 47 | "type", e.getClass().getSimpleName(), | |
| 48 | "message", e.getMessage()); | |
| 49 | } | |
| 50 | } | |
Mutations | ||
| 24 |
1.1 |
|
| 34 |
1.1 |
|
| 46 |
1.1 |