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