Completed
Pull Request — dev (#380)
by
unknown
06:27 queued 01:32
created

getQuestionModel(Integer,QuestionsOptionsInterface)   A

Complexity

Conditions 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 7
rs 10
cc 2
1
package easytests.api.v1.controllers;
2
3
import easytests.api.v1.exceptions.ForbiddenException;
4
import easytests.api.v1.mappers.QuestionsMapper;
5
import easytests.api.v1.models.Question;
6
import easytests.common.exceptions.NotFoundException;
7
import easytests.core.models.QuestionModelInterface;
8
import easytests.core.options.AnswersOptions;
9
import easytests.core.options.QuestionsOptions;
10
import easytests.core.options.QuestionsOptionsInterface;
11
import easytests.core.options.builder.QuestionsOptionsBuilderInterface;
12
import easytests.core.services.QuestionsServiceInterface;
13
import easytests.core.services.TopicsServiceInterface;
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
19
/**
20
 * @author RisaMagpie
21
 */
22
@RestController("QuestionsControllerV1")
23
@SuppressWarnings("checkstyle:MultipleStringLiterals")
24
@RequestMapping("/v1/questions")
25
public class QuestionsController extends AbstractController {
26
27
    @Autowired
28
    protected QuestionsServiceInterface questionsService;
29
30
    @Autowired
31
    protected QuestionsOptionsBuilderInterface questionsOptionsBuilder;
32
33
    @Autowired
34
    protected TopicsServiceInterface topicsService;
35
36
    @Autowired
37
    @Qualifier("QuestionsMapperV1")
38
    private QuestionsMapper questionsMapper;
39
40
    /**
41
     * list
42
     */
43
    /**
44
     * create
45
     */
46
    /**
47
     * update
48
     */
49
    @GetMapping("/{questionId}")
50
    public Question show(@PathVariable Integer questionId) throws NotFoundException, ForbiddenException {
51
        final QuestionModelInterface questionModel = this.getQuestionModel(
52
                questionId,
53
                (new QuestionsOptions()).withAnswers(new AnswersOptions())
54
        );
55
        if (!this.acl.hasAccess(questionModel)) {
56
            throw new ForbiddenException();
57
        }
58
        return this.questionsMapper.map(questionModel, Question.class);
59
    }
60
61
    private QuestionModelInterface getQuestionModel(Integer id, QuestionsOptionsInterface
62
            questionOptions) throws NotFoundException {
63
        final QuestionModelInterface questionModel = this.questionsService.find(id, questionOptions);
64
        if (questionModel == null) {
65
            throw new NotFoundException();
66
        }
67
        return questionModel;
68
    }
69
70
    private QuestionModelInterface getQuestionModel(Integer id) throws NotFoundException {
0 ignored issues
show
Unused Code introduced by
Remove this unused private "getQuestionModel" method.
Loading history...
71
        return this.getQuestionModel(id, this.questionsOptionsBuilder.forAuth());
72
    }
73
    /**
74
     * delete(questionId)
75
     */
76
}
77