Passed
Pull Request — dev (#375)
by
unknown
05:41
created

create(User)   A

Complexity

Conditions 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.55
cc 3
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.Identity;
6
import easytests.api.v1.models.User;
7
import easytests.core.models.UserModel;
8
import easytests.core.models.UserModelInterface;
9
import easytests.core.options.builder.UsersOptionsBuilderInterface;
10
import easytests.core.services.UsersServiceInterface;
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.beans.factory.annotation.Qualifier;
13
import org.springframework.http.HttpStatus;
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 {
24
25
    @Autowired
26
    protected UsersServiceInterface usersService;
27
28
    @Autowired
29
    private UsersOptionsBuilderInterface usersOptionsBuilder;
30
31
    @Autowired
32
    @Qualifier("UsersMapperV1")
33
    private UsersMapper usersMapper;
34
35
    /**
36
     * list
37
     */
38
    @PostMapping("")
39
    @ResponseStatus(HttpStatus.CREATED)
40
    public Identity create(@RequestBody User user) throws BadRequestException {
41
        if (user.getId() != null) {
42
            throw new IdentifiedModelException();
43
        }
44
        if (this.usersService.findByEmail(user.getEmail()) != null) {
45
            throw new BadRequestException();
46
        }
47
48
        final UserModelInterface userModel = this.usersMapper.map(user, UserModel.class);
49
50
        userModel.setPassword("");
51
52
        this.usersService.save(userModel);
53
54
        return this.usersMapper.map(userModel, Identity.class);
55
    }
56
    /**
57
     * update
58
     */
59
    /**
60
     * show(userId)
61
     */
62
    /**
63
     * delete(userId)
64
     */
65
    /**
66
     * showMe
67
     */
68
}
69