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