UserProfileController.java

1
package edu.ucsb.cs156.gauchoride.controllers;
2
3
import io.swagger.v3.oas.annotations.tags.Tag;
4
import io.swagger.v3.oas.annotations.Operation;
5
6
import org.springframework.security.access.prepost.PreAuthorize;
7
import org.springframework.web.bind.annotation.GetMapping;
8
import org.springframework.web.bind.annotation.RequestMapping;
9
import org.springframework.web.bind.annotation.RestController;
10
import org.springframework.web.bind.annotation.PutMapping;
11
12
import edu.ucsb.cs156.gauchoride.repositories.UserRepository;
13
import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.web.bind.annotation.RequestParam;
16
import io.swagger.v3.oas.annotations.Parameter;
17
18
import edu.ucsb.cs156.gauchoride.entities.User;
19
import edu.ucsb.cs156.gauchoride.models.CurrentUser;
20
import edu.ucsb.cs156.gauchoride.services.CurrentUserService;
21
22
@Tag(name="Current User Profile")
23
@RequestMapping("/api/userprofile")
24
@RestController
25
public class UserProfileController extends ApiController {
26
  @Autowired
27
  UserRepository userRepository;
28
  @Operation(summary = "Update user cell phone number")
29
  @PreAuthorize("hasRole('ROLE_USER')")
30
  @PutMapping("")
31
  public User updateUsersCellPhone(
32
    @Parameter(name="cellPhone") @RequestParam String cellPhone) {
33
        Long id = super.getCurrentUser().getUser().getId();
34
        User user = userRepository.findById(id)
35 1 1. lambda$updateUsersCellPhone$0 : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/UserProfileController::lambda$updateUsersCellPhone$0 → KILLED
                 .orElseThrow(() -> new EntityNotFoundException(User.class, id));
36 1 1. updateUsersCellPhone : removed call to edu/ucsb/cs156/gauchoride/entities/User::setCellPhone → KILLED
        user.setCellPhone(cellPhone);
37
        userRepository.save(user);
38 1 1. updateUsersCellPhone : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/UserProfileController::updateUsersCellPhone → KILLED
        return user;        
39
    }
40
}

Mutations

35

1.1
Location : lambda$updateUsersCellPhone$0
Killed by : edu.ucsb.cs156.gauchoride.controllers.UserProfileControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.UserProfileControllerTests]/[method:logged_in_users_cannot_edit_profile_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/UserProfileController::lambda$updateUsersCellPhone$0 → KILLED

36

1.1
Location : updateUsersCellPhone
Killed by : edu.ucsb.cs156.gauchoride.controllers.UserProfileControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.UserProfileControllerTests]/[method:currentUser__logged_in_can_edit_profile()]
removed call to edu/ucsb/cs156/gauchoride/entities/User::setCellPhone → KILLED

38

1.1
Location : updateUsersCellPhone
Killed by : edu.ucsb.cs156.gauchoride.controllers.UserProfileControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.gauchoride.controllers.UserProfileControllerTests]/[method:currentUser__logged_in_can_edit_profile()]
replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/UserProfileController::updateUsersCellPhone → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3