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