Completed
Pull Request — dev (#265)
by Konstantin
02:32
created

getUserModel(Integer,UsersOptionsInterface)   A

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
c 2
b 0
f 0
dl 0
loc 6
rs 10
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