1 | package edu.ucsb.cs156.courses.controllers; | |
2 | ||
3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
4 | import com.fasterxml.jackson.databind.ObjectMapper; | |
5 | import edu.ucsb.cs156.courses.entities.User; | |
6 | import edu.ucsb.cs156.courses.repositories.UserRepository; | |
7 | import io.swagger.v3.oas.annotations.Operation; | |
8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
9 | import org.springframework.beans.factory.annotation.Autowired; | |
10 | import org.springframework.http.ResponseEntity; | |
11 | import org.springframework.security.access.prepost.PreAuthorize; | |
12 | import org.springframework.web.bind.annotation.GetMapping; | |
13 | import org.springframework.web.bind.annotation.RequestMapping; | |
14 | import org.springframework.web.bind.annotation.RestController; | |
15 | ||
16 | @Tag(name = "User information (admin only)") | |
17 | @RequestMapping("/api/admin/users") | |
18 | @RestController | |
19 | public class UsersController extends ApiController { | |
20 | @Autowired UserRepository userRepository; | |
21 | ||
22 | @Autowired ObjectMapper mapper; | |
23 | ||
24 | @Operation(summary = "Get a list of all users") | |
25 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
26 | @GetMapping("") | |
27 | public ResponseEntity<String> users() throws JsonProcessingException { | |
28 | Iterable<User> users = userRepository.findAll(); | |
29 | String body = mapper.writeValueAsString(users); | |
30 |
1
1. users : replaced return value with null for edu/ucsb/cs156/courses/controllers/UsersController::users → KILLED |
return ResponseEntity.ok().body(body); |
31 | } | |
32 | } | |
Mutations | ||
30 |
1.1 |