Passed
Pull Request — dev (#392)
by
unknown
06:23
created

getQuestionModel(Integer)   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
1
package easytests.api.v1.controllers;
2
3
import easytests.api.v1.exceptions.*;
4
import easytests.api.v1.mappers.QuestionsMapper;
5
import easytests.core.models.QuestionModelInterface;
6
import easytests.core.options.QuestionsOptionsInterface;
7
import easytests.core.options.builder.QuestionsOptionsBuilderInterface;
8
import easytests.core.services.QuestionsService;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.beans.factory.annotation.Qualifier;
11
import org.springframework.web.bind.annotation.*;
12
13
/**
14
 * @author RisaMagpie
15
 */
16
@RestController("QuestionControllerV1")
17
@SuppressWarnings("checkstyle:MultipleStringLiterals")
18
@RequestMapping("/v1/questions")
19
public class QuestionsController extends AbstractController {
20
21
    @Autowired
22
    protected QuestionsService questionsService;
23
24
    @Autowired
25
    protected QuestionsOptionsBuilderInterface questionsOptionsBuilder;
26
27
    @Autowired
28
    @Qualifier("QuestionsMapperV1")
29
    private QuestionsMapper questionsMapper;
30
31
    /**
32
     * list
33
     */
34
    /**
35
     * create
36
     */
37
    /**
38
     * update
39
     */
40
    /**
41
     * show(questionId)
42
     */
43
    @DeleteMapping("/{questionId}")
44
    public void delete(@PathVariable Integer questionId) throws NotFoundException, ForbiddenException {
45
        final QuestionModelInterface questionModel = this.getQuestionModel(questionId);
46
47
        if (questionModel == null) {
0 ignored issues
show
Bug introduced by
This condition always evaluates to false. Consider refactoring your code to no longer check for it or rewrite the condition.
Loading history...
48
            throw new NotFoundException();
49
        }
50
51
        if (!this.acl.hasAccess(questionModel)) {
52
            throw new ForbiddenException();
53
        }
54
55
        this.questionsService.delete(questionModel);
56
    }
57
58
    private QuestionModelInterface getQuestionModel(Integer id, QuestionsOptionsInterface questionOptions)
59
            throws NotFoundException {
60
        final QuestionModelInterface questionModel = this.questionsService.find(id, questionOptions);
61
        if (questionModel == null) {
62
            throw new NotFoundException();
63
        }
64
        return questionModel;
65
    }
66
67
    private QuestionModelInterface getQuestionModel(Integer id) throws NotFoundException {
68
        return this.getQuestionModel(id, this.questionsOptionsBuilder.forDelete());
69
    }
70
71
}
72