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