CurrentUserController.java

1
package edu.ucsb.cs156.dining.controllers;
2
3
import edu.ucsb.cs156.dining.entities.CurrentUser;
4
import edu.ucsb.cs156.dining.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.dining.repositories.CurrentUserRepository;
6
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import io.swagger.v3.oas.annotations.tags.Tag;
10
import lombok.extern.slf4j.Slf4j;
11
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.security.access.prepost.PreAuthorize;
14
import org.springframework.web.bind.annotation.DeleteMapping;
15
import org.springframework.web.bind.annotation.GetMapping;
16
import org.springframework.web.bind.annotation.PostMapping;
17
import org.springframework.web.bind.annotation.PutMapping;
18
import org.springframework.web.bind.annotation.RequestBody;
19
import org.springframework.web.bind.annotation.RequestMapping;
20
import org.springframework.web.bind.annotation.RequestParam;
21
import org.springframework.web.bind.annotation.RestController;
22
23
import jakarta.validation.Valid;
24
25
/**
26
 * This is a REST controller for CurrentUser
27
 */
28
29
@Tag(name = "CurrentUser")
30
@RequestMapping("/api/currentUser")
31
@RestController
32
@Slf4j
33
public class CurrentUserController extends ApiController {
34
35
    @Autowired
36
    CurrentUserRepository currentUserRepository;
37
38
    /**
39
     * This method creates a new user. Accessible only to user with the role "ROLE_USER".
40
     * @param alias alias of the user
41
     * @return the save user
42
     */
43
    @Operation(summary= "Modify alias")
44
    @PreAuthorize("hasRole('ROLE_USER')")
45
    @PostMapping("/updateAlias")
46
    public CurrentUser postUser(
47
        @Parameter(name="alias") @RequestParam String alias
48
        )
49
        {   
50
51
        CurrentUser users = new CurrentUser();
52 1 1. postUser : removed call to edu/ucsb/cs156/dining/entities/CurrentUser::setAlias → NO_COVERAGE
        users.setAlias(alias);
53
54
        CurrentUser savedCurrentUsers = currentUserRepository.save(users);
55
56 1 1. postUser : replaced return value with null for edu/ucsb/cs156/dining/controllers/CurrentUserController::postUser → NO_COVERAGE
        return savedCurrentUsers;
57
    }
58
59
    /**
60
     * Update a single users. Accessible only to users with the role "ROLE_ADMIN".
61
     * @param modValue alias moderation value of the users
62
     * @param incoming the new users contents
63
     * @return the updated users object
64
     */
65
    @Operation(summary= "Update alias moderation value")
66
    @PreAuthorize("hasRole('ROLE_ADMIN')")
67
    @PutMapping("/updateModValue")
68
    public CurrentUser updateModValue(
69
            @Parameter(name="modValue") @RequestParam long modValue,
70
            @RequestBody @Valid CurrentUser incoming) {
71
72
        CurrentUser users = currentUserRepository.findById(modValue)
73 1 1. lambda$updateModValue$0 : replaced return value with null for edu/ucsb/cs156/dining/controllers/CurrentUserController::lambda$updateModValue$0 → NO_COVERAGE
                .orElseThrow(() -> new EntityNotFoundException(CurrentUser.class, modValue));
74
75
76 1 1. updateModValue : removed call to edu/ucsb/cs156/dining/entities/CurrentUser::setModValue → NO_COVERAGE
        users.setModValue(incoming.getModValue());  
77
78
        currentUserRepository.save(users);
79
80 1 1. updateModValue : replaced return value with null for edu/ucsb/cs156/dining/controllers/CurrentUserController::updateModValue → NO_COVERAGE
        return users;
81
    }
82
}

Mutations

52

1.1
Location : postUser
Killed by : none
removed call to edu/ucsb/cs156/dining/entities/CurrentUser::setAlias → NO_COVERAGE

56

1.1
Location : postUser
Killed by : none
replaced return value with null for edu/ucsb/cs156/dining/controllers/CurrentUserController::postUser → NO_COVERAGE

73

1.1
Location : lambda$updateModValue$0
Killed by : none
replaced return value with null for edu/ucsb/cs156/dining/controllers/CurrentUserController::lambda$updateModValue$0 → NO_COVERAGE

76

1.1
Location : updateModValue
Killed by : none
removed call to edu/ucsb/cs156/dining/entities/CurrentUser::setModValue → NO_COVERAGE

80

1.1
Location : updateModValue
Killed by : none
replaced return value with null for edu/ucsb/cs156/dining/controllers/CurrentUserController::updateModValue → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.17.0