|
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) { |
|
|
|
|
|
|
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) throws NotFoundException { |
|
59
|
|
|
final QuestionModelInterface questionModel = this.questionsService.find(id, questionOptions); |
|
60
|
|
|
if (questionModel == null) { |
|
61
|
|
|
throw new NotFoundException(); |
|
62
|
|
|
} |
|
63
|
|
|
return questionModel; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
private QuestionModelInterface getQuestionModel(Integer id) throws NotFoundException { |
|
67
|
|
|
return this.getQuestionModel(id, this.questionsOptionsBuilder.forDelete()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|