Completed
Push — dev ( 6fd399...4b590f )
by Konstantin
11:42 queued 03:10
created

easytests.api.v1.controllers.SubjectsController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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