Passed
Pull Request — dev (#321)
by
unknown
05:18
created

isAdmin()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
1
package easytests.api.v1.controllers;
2
3
import easytests.api.v1.exceptions.*;
4
import easytests.api.v1.mappers.UsersMapper;
5
import easytests.api.v1.models.User;
6
import easytests.core.models.UserModelInterface;
7
import easytests.core.options.builder.UsersOptionsBuilderInterface;
8
import easytests.core.services.UsersServiceInterface;
9
import easytests.auth.services.SessionServiceInterface;
10
import java.util.List;
11
import java.util.stream.Collectors;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.beans.factory.annotation.Qualifier;
14
import org.springframework.web.bind.annotation.*;
15
16
17
/**
18
 * @author SvetlanaTselikova
19
 */
20
@RestController("UsersControllerV1")
21
@SuppressWarnings("checkstyle:MultipleStringLiterals")
22
@RequestMapping("/v1/users")
23
public class UsersController extends AbstractController {
24
25
    @Autowired
26
    protected UsersServiceInterface usersService;
27
28
    @Autowired
29
    private UsersOptionsBuilderInterface usersOptionsBuilder;
30
31
    @Autowired
32
    private SessionServiceInterface sessionService;
33
34
    @Autowired
35
    @Qualifier("UsersMapperV1")
36
    private UsersMapper usersMapper;
37
38
    private Boolean isAdmin() {
39
        return this.sessionService.getUserModel().getIsAdmin();
40
    }
41
42
    @GetMapping("")
43
    public List<User> list() throws ForbiddenException {
44
        if (!this.isAdmin()) {
45
            throw new ForbiddenException();
46
        }
47
        final List<UserModelInterface> usersModels = this.usersService.findAll();
48
49
        return usersModels
50
                .stream()
51
                .map(model -> this.usersMapper.map(model, User.class))
52
                .collect(Collectors.toList());
53
    }
54
    /**
55
     * create
56
     */
57
    /**
58
     * update
59
     */
60
    /**
61
     * show(userId)
62
     */
63
    /**
64
     * delete(userId)
65
     */
66
    /**
67
     * showMe
68
     */
69
}
70