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