UserInfoController.java

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

Mutations

43

1.1
Location : getCurrentUserAsJson
Killed by : edu.ucsb.cs156.organic.controllers.UserInfoControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.UserInfoControllerTests]/[method:currentUser__logged_in()]
replaced return value with null for edu/ucsb/cs156/organic/controllers/UserInfoController::getCurrentUserAsJson → KILLED

52

1.1
Location : updateLastOnline
Killed by : edu.ucsb.cs156.organic.controllers.UserInfoControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.UserInfoControllerTests]/[method:currentUser__update_last_online()]
removed call to edu/ucsb/cs156/organic/entities/User::setLastOnline → KILLED

54

1.1
Location : updateLastOnline
Killed by : edu.ucsb.cs156.organic.controllers.UserInfoControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.UserInfoControllerTests]/[method:currentUser__update_last_online()]
replaced return value with null for edu/ucsb/cs156/organic/controllers/UserInfoController::updateLastOnline → KILLED

62

1.1
Location : getUsersEmails
Killed by : edu.ucsb.cs156.organic.controllers.UserInfoControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.UserInfoControllerTests]/[method:currentUser__get_emails()]
replaced return value with null for edu/ucsb/cs156/organic/controllers/UserInfoController::getUsersEmails → KILLED

70

1.1
Location : getStaffedCourses
Killed by : edu.ucsb.cs156.organic.controllers.UserInfoControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.UserInfoControllerTests]/[method:currentUser__get_staffed_courses()]
replaced return value with null for edu/ucsb/cs156/organic/controllers/UserInfoController::getStaffedCourses → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3