| 1 | package edu.ucsb.cs156.organic.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.organic.entities.Course; | |
| 4 | import edu.ucsb.cs156.organic.entities.User; | |
| 5 | import edu.ucsb.cs156.organic.entities.UserEmail; | |
| 6 | import edu.ucsb.cs156.organic.models.CurrentUser; | |
| 7 | import edu.ucsb.cs156.organic.repositories.UserRepository; | |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import lombok.extern.slf4j.Slf4j; | |
| 10 | import io.swagger.v3.oas.annotations.Operation; | |
| 11 | ||
| 12 | import java.time.Instant; | |
| 13 | ||
| 14 | import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | import org.springframework.http.ResponseEntity; | |
| 16 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 19 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 20 | import org.springframework.web.bind.annotation.RestController; | |
| 21 | ||
| 22 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 23 | ||
| 24 | @Slf4j | |
| 25 | @Tag(name = "Current User Information") | |
| 26 | @RequestMapping("/api/currentUser") | |
| 27 | @RestController | |
| 28 | public class UserInfoController extends ApiController { | |
| 29 | @Autowired | |
| 30 | private UserRepository userRepository; | |
| 31 | ||
| 32 | @Operation(summary = "Get information about current user") | |
| 33 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 34 | @GetMapping("") | |
| 35 | public ResponseEntity<String> getCurrentUserAsJson() throws JsonProcessingException { | |
| 36 | CurrentUser cu = super.getCurrentUser(); | |
| 37 | String cuAsJson = getMapper().writeValueAsString(cu); | |
| 38 |
1
1. getCurrentUserAsJson : replaced return value with null for edu/ucsb/cs156/organic/controllers/UserInfoController::getCurrentUserAsJson → KILLED |
return ResponseEntity.ok().body(cuAsJson); |
| 39 | } | |
| 40 | ||
| 41 | @Operation(summary = "Update user's last online time") | |
| 42 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 43 | @PostMapping("/last-online") | |
| 44 | public ResponseEntity<Instant> updateLastOnline() { | |
| 45 | User user = super.getCurrentUser().getUser(); | |
| 46 | Instant timeNow = Instant.now(); | |
| 47 |
1
1. updateLastOnline : removed call to edu/ucsb/cs156/organic/entities/User::setLastOnline → KILLED |
user.setLastOnline(timeNow); |
| 48 | userRepository.save(user); | |
| 49 |
1
1. updateLastOnline : replaced return value with null for edu/ucsb/cs156/organic/controllers/UserInfoController::updateLastOnline → KILLED |
return ResponseEntity.ok().body(timeNow); |
| 50 | } | |
| 51 | ||
| 52 | @Operation(summary = "Get current users emails") | |
| 53 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 54 | @GetMapping("/emails") | |
| 55 | public Iterable<UserEmail> getUsersEmails() { | |
| 56 | User user = super.getCurrentUser().getUser(); | |
| 57 |
1
1. getUsersEmails : replaced return value with null for edu/ucsb/cs156/organic/controllers/UserInfoController::getUsersEmails → KILLED |
return user.getEmails(); |
| 58 | } | |
| 59 | ||
| 60 | | |
| 61 | @Operation(summary = "Get courses for which current user is on the staff") | |
| 62 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 63 | @GetMapping("/staffedCourses") | |
| 64 | public Iterable<Course> getStaffedCourses() { | |
| 65 | User user = super.getCurrentUser().getUser(); | |
| 66 |
1
1. getStaffedCourses : replaced return value with null for edu/ucsb/cs156/organic/controllers/UserInfoController::getStaffedCourses → KILLED |
return userRepository.findCoursesStaffedByUser(user.getGithubId()); |
| 67 | } | |
| 68 | ||
| 69 | } | |
Mutations | ||
| 38 |
1.1 |
|
| 47 |
1.1 |
|
| 49 |
1.1 |
|
| 57 |
1.1 |
|
| 66 |
1.1 |