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 net.bytebuddy.implementation.bytecode.Throw; | |
7 | import org.springframework.beans.factory.annotation.Autowired; | |
8 | ||
9 | // import edu.ucsb.cs156.happiercows.entities.User; | |
10 | import edu.ucsb.cs156.happiercows.models.CurrentUser; | |
11 | import edu.ucsb.cs156.happiercows.services.CurrentUserService; | |
12 | import lombok.extern.slf4j.Slf4j; | |
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 | @Slf4j | |
20 | public abstract class ApiController { | |
21 | @Autowired | |
22 | private CurrentUserService currentUserService; | |
23 | ||
24 | protected CurrentUser getCurrentUser() { | |
25 |
1
1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::getCurrentUser → KILLED |
return currentUserService.getCurrentUser(); |
26 | } | |
27 | | |
28 | protected Object genericMessage(String message) { | |
29 |
1
1. genericMessage : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::genericMessage → KILLED |
return Map.of("message", message); |
30 | } | |
31 | ||
32 | @ExceptionHandler({ EntityNotFoundException.class }) | |
33 | @ResponseStatus(HttpStatus.NOT_FOUND) | |
34 | public Object handleGenericException(Throwable e) { | |
35 |
1
1. handleGenericException : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::handleGenericException → KILLED |
return Map.of( |
36 | "type", e.getClass().getSimpleName(), | |
37 | "message", e.getMessage() | |
38 | ); | |
39 | } | |
40 | ||
41 | @ExceptionHandler({ NoCowsException.class, NotEnoughMoneyException.class}) | |
42 | @ResponseStatus(HttpStatus.BAD_REQUEST) | |
43 | public Object handleBadRequest(Throwable e) { | |
44 |
1
1. handleBadRequest : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::handleBadRequest → KILLED |
return Map.of( |
45 | "type", e.getClass().getSimpleName(), | |
46 | "message", e.getMessage() | |
47 | ); | |
48 | } | |
49 | } | |
Mutations | ||
25 |
1.1 |
|
29 |
1.1 |
|
35 |
1.1 |
|
44 |
1.1 |