1 | package edu.ucsb.cs156.happiercows.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.happiercows.entities.User; | |
4 | import edu.ucsb.cs156.happiercows.models.CurrentUser; | |
5 | import edu.ucsb.cs156.happiercows.repositories.UserRepository; | |
6 | import io.swagger.annotations.Api; | |
7 | import io.swagger.annotations.ApiOperation; | |
8 | ||
9 | import java.time.Instant; | |
10 | ||
11 | import org.springframework.beans.factory.annotation.Autowired; | |
12 | import org.springframework.http.ResponseEntity; | |
13 | import org.springframework.security.access.prepost.PreAuthorize; | |
14 | import org.springframework.web.bind.annotation.GetMapping; | |
15 | import org.springframework.web.bind.annotation.PostMapping; | |
16 | import org.springframework.web.bind.annotation.RequestMapping; | |
17 | import org.springframework.web.bind.annotation.RestController; | |
18 | ||
19 | @Api(description="Current User Information") | |
20 | @RequestMapping("/api/currentUser") | |
21 | @RestController | |
22 | public class UserInfoController extends ApiController { | |
23 | @Autowired | |
24 | private UserRepository userRepository; | |
25 | | |
26 | @ApiOperation(value = "Get information about current user") | |
27 | @PreAuthorize("hasRole('ROLE_USER')") | |
28 | @GetMapping("") | |
29 | public CurrentUser getCurrentUser() { | |
30 |
1
1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/UserInfoController::getCurrentUser → KILLED |
return super.getCurrentUser(); |
31 | } | |
32 | ||
33 | @ApiOperation(value = "Update user's last online time") | |
34 | @PreAuthorize("hasRole('ROLE_USER')") | |
35 | @PostMapping("/last-online") | |
36 | public ResponseEntity<Instant> updateLastOnline() { | |
37 | User user = super.getCurrentUser().getUser(); | |
38 | Instant timeNow = Instant.now(); | |
39 |
1
1. updateLastOnline : removed call to edu/ucsb/cs156/happiercows/entities/User::setLastOnline → KILLED |
user.setLastOnline(timeNow); |
40 | userRepository.save(user); | |
41 |
1
1. updateLastOnline : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/UserInfoController::updateLastOnline → KILLED |
return ResponseEntity.ok().body(timeNow); |
42 | } | |
43 | } | |
44 | ||
Mutations | ||
30 |
1.1 |
|
39 |
1.1 |
|
41 |
1.1 |