Completed
Pull Request — dev (#265)
by Konstantin
05:51
created

easytests.api.v1.controllers.UsersController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 31
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
getUserModel 0 6 ?
A getUserModel(Integer,UsersOptionsInterface) 0 6 2
A getUserModel(Integer) 0 2 1
A view(Integer) 0 4 1
1
package easytests.api.v1.controllers;
2
3
import easytests.api.v1.mappers.UsersMapper;
4
import easytests.api.v1.models.User;
5
import easytests.common.exceptions.NotFoundException;
6
import easytests.core.models.UserModelInterface;
7
import easytests.core.options.UsersOptionsInterface;
8
import easytests.core.options.builder.UsersOptionsBuilder;
9
import easytests.core.services.UsersService;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.beans.factory.annotation.Qualifier;
12
import org.springframework.web.bind.annotation.*;
13
14
15
/**
16
 * @author malinink
17
 */
18
@RestController("UsersControllerV1")
19
@SuppressWarnings("checkstyle:MultipleStringLiterals")
20
@RequestMapping("/v1/users/")
21
public class UsersController {
22
23
    @Autowired
24
    protected UsersService usersService;
25
26
    @Autowired
27
    private UsersOptionsBuilder usersOptionsBuilder;
28
29
    @Autowired
30
    @Qualifier("UsersMapperV1")
31
    private UsersMapper usersMapper;
32
33
    @GetMapping("{userId}/")
34
    public User view(@PathVariable Integer userId) {
35
        final UserModelInterface userModel = this.getUserModel(userId);
36
        return this.usersMapper.map(userModel, User.class);
37
    }
38
39
    private UserModelInterface getUserModel(Integer id, UsersOptionsInterface userOptions) {
40
        final UserModelInterface userModel = this.usersService.find(id, userOptions);
41
        if (userModel == null) {
42
            throw new NotFoundException();
43
        }
44
        return userModel;
45
    }
46
47
    private UserModelInterface getUserModel(Integer id) {
48
        return this.getUserModel(id, this.usersOptionsBuilder.forAuth());
49
    }
50
}
51