Completed
Pull Request — dev (#334)
by
unknown
03:51 queued 20s
created

list(Integer)   A

Complexity

Conditions 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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