Completed
Pull Request — dev (#334)
by
unknown
02:34
created

list(Integer)   A

Complexity

Conditions 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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