Test Setup Failed
Pull Request — dev (#334)
by
unknown
02:47
created

list(Integer)   A

Complexity

Conditions 4

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
dl 0
loc 24
rs 9.304
c 0
b 0
f 0
1
package easytests.api.v1.controllers;
2
3
import easytests.api.v1.exceptions.BadRequestException;
4
import easytests.api.v1.exceptions.ForbiddenException;
5
import easytests.api.v1.mappers.IssuesMapper;
6
import easytests.api.v1.models.Issue;
7
import easytests.common.exceptions.NotFoundException;
8
import easytests.core.models.IssueModelInterface;
9
import easytests.core.models.SubjectModelInterface;
10
import easytests.core.models.empty.SubjectModelEmpty;
11
import easytests.core.options.builder.IssuesOptionsBuilder;
12
import easytests.core.services.IssuesServiceInterface;
13
import easytests.core.services.SubjectsServiceInterface;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.beans.factory.annotation.Qualifier;
16
import org.springframework.web.bind.annotation.*;
17
18
import java.util.List;
19
import java.util.stream.Collectors;
20
21
/**
22
 * @author Yarik2308
23
 */
24
@RestController("IssuesControllerV1")
25
@SuppressWarnings("checkstyle:MultipleStringLiterals")
26
@RequestMapping("/v1/issues")
27
public class IssuesController extends AbstractController{
28
29
    @Autowired
30
    protected IssuesServiceInterface issuesService;
31
32
    @Autowired
33
    protected IssuesOptionsBuilder issuesOptions;
34
35
    @Autowired
36
    protected SubjectsServiceInterface subjectsService;
37
38
    @Autowired
39
    @Qualifier("IssuesMapperV1")
40
    private IssuesMapper issuesMapper;
41
42
    @GetMapping
43
    public List<Issue> list(@RequestParam(name = "subjectId", required = true) Integer subjectId)
44
            throws NotFoundException, ForbiddenException {
45
        final SubjectModelInterface subjectModel = this.subjectsService.find(subjectId);
46
47
        if(subjectModel == null) {
48
            throw new NotFoundException();
49
        }
50
51
        if(!this.acl.hasAccess(subjectModel)) {
52
            throw new ForbiddenException();
53
        }
54
55
        final List<IssueModelInterface> issuesModels = this.issuesService
56
                .findBySubject(new SubjectModelEmpty(subjectId));
57
58
        if(issuesModels == null) {
59
            throw new NotFoundException();
60
        }
61
62
        return issuesModels
63
                .stream()
64
                .map(model -> this.issuesMapper.map(model, Issue.class))
65
                .collect(Collectors.toList());
66
    }
67
    /**
68
     * create
69
     */
70
    /**
71
     * update
72
     */
73
    /**
74
     * show(issueId)
75
     */
76
    /**
77
     * delete(issueId)
78
     */
79
80
}
81