Passed
Pull Request — dev (#348)
by
unknown
05:04
created

easytests.api.v1.controllers.SubjectsController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 3
c 4
b 1
f 0
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A list(Integer) 0 18 3
1
package easytests.api.v1.controllers;
2
3
import easytests.api.v1.exceptions.ForbiddenException;
4
import easytests.api.v1.mappers.SubjectsMapper;
5
import easytests.api.v1.models.Subject;
6
import easytests.common.exceptions.NotFoundException;
7
import easytests.core.models.SubjectModelInterface;
8
import easytests.core.models.UserModelInterface;
9
import easytests.core.models.empty.UserModelEmpty;
10
import easytests.core.options.builder.SubjectsOptionsBuilderInterface;
11
import easytests.core.services.SubjectsServiceInterface;
12
import easytests.core.services.UsersServiceInterface;
13
import java.util.List;
14
import java.util.stream.Collectors;
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.beans.factory.annotation.Qualifier;
17
import org.springframework.web.bind.annotation.GetMapping;
18
import org.springframework.web.bind.annotation.*;
19
import org.springframework.web.bind.annotation.RequestParam;
20
21
22
23
/**
24
 * @author VeronikaRevjakina
25
 */
26
@RestController("SubjectsControllerV1")
27
@SuppressWarnings("checkstyle:MultipleStringLiterals")
28
@RequestMapping("/v1/subjects")
29
public class SubjectsController extends AbstractController{
30
31
    @Autowired
32
    protected SubjectsServiceInterface subjectsService;
33
34
    @Autowired
35
    private SubjectsOptionsBuilderInterface subjectsOptionsBuilder;
36
37
    @Autowired
38
    protected UsersServiceInterface usersService;
39
40
    @Autowired
41
    @Qualifier("SubjectsMapperV1")
42
    private SubjectsMapper subjectsMapper;
43
44
45
    @GetMapping("")
46
    public List<Subject> list(@RequestParam(name = "userId", required = true) Integer userId)
47
         throws NotFoundException, ForbiddenException{
48
            final UserModelInterface userModel = this.usersService.find(userId);
49
50
            if (userModel == null) {
51
                throw new NotFoundException();
52
            }
53
            if (!this.acl.hasAccess(userModel)) {
54
                throw new ForbiddenException();
55
            }
56
57
        final List<SubjectModelInterface> subjectsModels = this.subjectsService.findByUser(new UserModelEmpty(userId));
58
59
        return subjectsModels
60
                .stream()
61
                .map(model -> this.subjectsMapper.map(model, Subject.class))
62
                .collect(Collectors.toList());
63
    }
64
    /**
65
     * create
66
     */
67
    /**
68
     * update
69
     */
70
    /**
71
     * show(subjectId)
72
     */
73
    /**
74
     * delete(subjectId)
75
     */
76
}
77