| 1 | package edu.ucsb.cs156.happiercows.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.happiercows.errors.EntityNotFoundException; | |
| 4 | import edu.ucsb.cs156.happiercows.errors.NegativeBuyNumberException; | |
| 5 | import edu.ucsb.cs156.happiercows.errors.NoCowsException; | |
| 6 | import edu.ucsb.cs156.happiercows.errors.NotEnoughMoneyException; | |
| 7 | import edu.ucsb.cs156.happiercows.errors.NegativeSellNumberException; | |
| 8 | import edu.ucsb.cs156.happiercows.errors.NegativeBuyNumberException; | |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | ||
| 11 | import edu.ucsb.cs156.happiercows.models.CurrentUser; | |
| 12 | import edu.ucsb.cs156.happiercows.services.CurrentUserService; | |
| 13 | import org.springframework.http.HttpStatus; | |
| 14 | import org.springframework.web.bind.annotation.ExceptionHandler; | |
| 15 | import org.springframework.web.bind.annotation.ResponseStatus; | |
| 16 | ||
| 17 | import java.util.Map; | |
| 18 | ||
| 19 | public abstract class ApiController { | |
| 20 |   @Autowired | |
| 21 |   private CurrentUserService currentUserService; | |
| 22 | ||
| 23 |   protected CurrentUser getCurrentUser() { | |
| 24 | 
1
1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::getCurrentUser → KILLED | 
    return currentUserService.getCurrentUser(); | 
| 25 |   } | |
| 26 |    | |
| 27 |   protected Object genericMessage(String message) { | |
| 28 | 
1
1. genericMessage : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::genericMessage → KILLED | 
    return Map.of("message", message); | 
| 29 |   } | |
| 30 | ||
| 31 |   @ExceptionHandler({ EntityNotFoundException.class }) | |
| 32 |   @ResponseStatus(HttpStatus.NOT_FOUND) | |
| 33 |   public Object handleGenericException(Throwable e) { | |
| 34 | 
1
1. handleGenericException : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::handleGenericException → KILLED | 
    return Map.of( | 
| 35 |       "type", e.getClass().getSimpleName(), | |
| 36 |       "message", e.getMessage() | |
| 37 |     ); | |
| 38 |   } | |
| 39 | ||
| 40 |   @ExceptionHandler({ NoCowsException.class, NotEnoughMoneyException.class}) | |
| 41 |   @ResponseStatus(HttpStatus.BAD_REQUEST) | |
| 42 |   public Object handleBadRequest(Throwable e) { | |
| 43 | 
1
1. handleBadRequest : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::handleBadRequest → KILLED | 
    return Map.of( | 
| 44 |       "type", e.getClass().getSimpleName(), | |
| 45 |       "message", e.getMessage() | |
| 46 |     ); | |
| 47 |   } | |
| 48 | ||
| 49 |   @ExceptionHandler({ NegativeSellNumberException.class }) | |
| 50 |   @ResponseStatus(HttpStatus.BAD_REQUEST) | |
| 51 |   public Object handleNegativeSellNumberException(Throwable e) { | |
| 52 | 
1
1. handleNegativeSellNumberException : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::handleNegativeSellNumberException → KILLED | 
    return Map.of( | 
| 53 |       "type", e.getClass().getSimpleName(), | |
| 54 |       "message", e.getMessage() | |
| 55 |     ); | |
| 56 |   } | |
| 57 | ||
| 58 |   @ExceptionHandler({ NegativeBuyNumberException.class }) | |
| 59 |   @ResponseStatus(HttpStatus.BAD_REQUEST) | |
| 60 |   public Object handleNegativeBuyNumberException(Throwable e) { | |
| 61 | 
1
1. handleNegativeBuyNumberException : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::handleNegativeBuyNumberException → KILLED | 
    return Map.of( | 
| 62 |       "type", e.getClass().getSimpleName(), | |
| 63 |       "message", e.getMessage() | |
| 64 |     ); | |
| 65 |   } | |
| 66 | } | |
Mutations | ||
| 24 | 
 
 1.1  | 
|
| 28 | 
 
 1.1  | 
|
| 34 | 
 
 1.1  | 
|
| 43 | 
 
 1.1  | 
|
| 52 | 
 
 1.1  | 
|
| 61 | 
 
 1.1  |