Completed
Pull Request — dev (#265)
by Konstantin
04:57
created

view(Integer)   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 4
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.controllers.AbstractCrudController;
6
import easytests.common.exceptions.NotFoundException;
7
import easytests.core.models.UserModelInterface;
8
import easytests.core.options.UsersOptionsInterface;
9
import easytests.core.options.builder.UsersOptionsBuilder;
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 extends AbstractCrudController {
22
23
    @Autowired
24
    private UsersOptionsBuilder usersOptionsBuilder;
25
26
    @Autowired
27
    @Qualifier("UsersMapperV1")
28
    private UsersMapper usersMapper;
29
30
    @GetMapping("{userId}/")
31
    public User view(@PathVariable Integer userId) {
32
        final UserModelInterface userModel = this.getUserModel(userId);
33
        return this.usersMapper.map(userModel, User.class);
34
    }
35
36
    private UserModelInterface getUserModel(Integer id, UsersOptionsInterface userOptions) {
37
        final UserModelInterface userModel = this.usersService.find(id, userOptions);
38
        if (userModel == null) {
39
            throw new NotFoundException();
40
        }
41
        return userModel;
42
    }
43
44
    private UserModelInterface getUserModel(Integer id) {
45
        return getUserModel(id, this.usersOptionsBuilder.forAuth());
46
    }
47
}
48