Completed
Push — dev ( 4b590f...6010cc )
by Konstantin
07:35 queued 01:23
created

easytests.api.v1.controllers.TopicsController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
dl 0
loc 38
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A list(Integer) 0 20 3
1
package easytests.api.v1.controllers;
2
3
import easytests.api.v1.exceptions.ForbiddenException;
4
import easytests.api.v1.exceptions.NotFoundException;
5
import easytests.api.v1.mappers.TopicsMapper;
6
import easytests.api.v1.models.Topic;
7
import easytests.core.models.SubjectModelInterface;
8
import easytests.core.models.TopicModelInterface;
9
import easytests.core.options.builder.TopicsOptionsBuilderInterface;
10
import easytests.core.services.SubjectsServiceInterface;
11
import easytests.core.services.TopicsServiceInterface;
12
import java.util.List;
13
import java.util.stream.Collectors;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.beans.factory.annotation.Qualifier;
16
import org.springframework.web.bind.annotation.GetMapping;
17
import org.springframework.web.bind.annotation.RequestMapping;
18
import org.springframework.web.bind.annotation.RequestParam;
19
import org.springframework.web.bind.annotation.RestController;
20
21
/**
22
 * @author lelay
23
 */
24
@RestController("TopicsControllerV1")
25
@SuppressWarnings("checkstyle:MultipleStringLiterals")
26
@RequestMapping("/v1/topics")
27
public class TopicsController extends AbstractController {
28
29
    @Autowired
30
    protected SubjectsServiceInterface subjectsService;
31
32
    @Autowired
33
    protected TopicsServiceInterface topicsService;
34
35
    @Autowired
36
    private TopicsOptionsBuilderInterface topicsOptionsBuilder;
37
38
    @Autowired
39
    @Qualifier("TopicsMapperV1")
40
    private TopicsMapper topicsMapper;
41
42
    @GetMapping("")
43
    public List<Topic> 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<TopicModelInterface> topicsModels =
56
                this.topicsService.findBySubject(subjectModel);
57
58
        return topicsModels
59
                .stream()
60
                .map(model -> this.topicsMapper.map(model, Topic.class))
61
                .collect(Collectors.toList());
62
    }
63
64
    /**
65
     * create
66
     */
67
    /**
68
     * update
69
     */
70
    /**
71
     * show(topicId)
72
     */
73
    /**
74
     * delete(topicId)
75
     */
76
}
77