| 1 | package edu.ucsb.cs156.gauchoride.controllers; | |
| 2 | ||
| 3 | import net.bytebuddy.implementation.bytecode.Throw; | |
| 4 | import org.springframework.beans.factory.annotation.Autowired; | |
| 5 | ||
| 6 | import lombok.extern.slf4j.Slf4j; | |
| 7 | import org.springframework.http.HttpStatus; | |
| 8 | import org.springframework.web.bind.annotation.ExceptionHandler; | |
| 9 | import org.springframework.web.bind.annotation.ResponseStatus; | |
| 10 | ||
| 11 | import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException; | |
| 12 | import edu.ucsb.cs156.gauchoride.models.CurrentUser; | |
| 13 | import edu.ucsb.cs156.gauchoride.services.CurrentUserService; | |
| 14 | ||
| 15 | import java.util.Map; | |
| 16 | ||
| 17 | /** | |
| 18 |  * Base class for all API controllers. | |
| 19 |  *  | |
| 20 |  * Provides a method to get the current user as well as common methods for | |
| 21 |  * error handling. | |
| 22 |  */ | |
| 23 | ||
| 24 | @Slf4j | |
| 25 | public abstract class ApiController { | |
| 26 |   @Autowired | |
| 27 |   private CurrentUserService currentUserService; | |
| 28 | ||
| 29 |   /** | |
| 30 |    * Get the current user | |
| 31 |    * @return the current user | |
| 32 |    */ | |
| 33 | ||
| 34 |   protected CurrentUser getCurrentUser() { | |
| 35 | 
1
1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ApiController::getCurrentUser → KILLED | 
    return currentUserService.getCurrentUser(); | 
| 36 |   } | |
| 37 | ||
| 38 | ||
| 39 |   /** | |
| 40 |    * This creates a plain old java object that can be returned as a JSON response | |
| 41 |    * @return a Map object with a single key/value pair: "message" => message | |
| 42 |    */ | |
| 43 | ||
| 44 |   protected Object genericMessage(String message) { | |
| 45 | 
1
1. genericMessage : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ApiController::genericMessage → KILLED | 
    return Map.of("message", message); | 
| 46 |   } | |
| 47 | ||
| 48 |    /** | |
| 49 |    * This catches any EntityNotFoundExceptions and returns a 404 (NOT_FOUND) response | |
| 50 |    * @return a Map object that can be returned as a JSON response | |
| 51 |    */ | |
| 52 |   @ExceptionHandler({ EntityNotFoundException.class }) | |
| 53 |   @ResponseStatus(HttpStatus.NOT_FOUND) | |
| 54 |   public Object handleGenericException(Throwable e) { | |
| 55 | 
1
1. handleGenericException : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ApiController::handleGenericException → KILLED | 
    return Map.of( | 
| 56 |       "type", e.getClass().getSimpleName(), | |
| 57 |       "message", e.getMessage() | |
| 58 |     ); | |
| 59 |   } | |
| 60 | } | |
Mutations | ||
| 35 | 
 
 1.1  | 
|
| 45 | 
 
 1.1  | 
|
| 55 | 
 
 1.1  |