Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sprachschulsystem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Pokorný
Sprachschulsystem
Commits
ac767596
There was an error fetching the commit references. Please try again later.
Commit
ac767596
authored
1 year ago
by
Dominika Zemanovičová
Browse files
Options
Downloads
Patches
Plain Diff
Simplify QuestionFacade
parent
e37b3ba7
No related branches found
No related tags found
3 merge requests
!31
M2
,
!30
M2 exercise
,
!29
M2 exercise
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
application/module-exercise/src/main/java/org/fuseri/moduleexercise/question/QuestionFacade.java
+5
-39
5 additions, 39 deletions
...va/org/fuseri/moduleexercise/question/QuestionFacade.java
with
5 additions
and
39 deletions
application/module-exercise/src/main/java/org/fuseri/moduleexercise/question/QuestionFacade.java
+
5
−
39
View file @
ac767596
...
@@ -5,15 +5,11 @@ import org.fuseri.model.dto.exercise.AnswerDto;
...
@@ -5,15 +5,11 @@ import org.fuseri.model.dto.exercise.AnswerDto;
import
org.fuseri.model.dto.exercise.QuestionCreateDto
;
import
org.fuseri.model.dto.exercise.QuestionCreateDto
;
import
org.fuseri.model.dto.exercise.QuestionDto
;
import
org.fuseri.model.dto.exercise.QuestionDto
;
import
org.fuseri.model.dto.exercise.QuestionUpdateDto
;
import
org.fuseri.model.dto.exercise.QuestionUpdateDto
;
import
org.fuseri.moduleexercise.answer.Answer
;
import
org.fuseri.moduleexercise.answer.AnswerMapper
;
import
org.fuseri.moduleexercise.answer.AnswerMapper
;
import
org.fuseri.moduleexercise.answer.AnswerService
;
import
org.fuseri.moduleexercise.answer.AnswerService
;
import
org.fuseri.moduleexercise.exercise.Exercise
;
import
org.fuseri.moduleexercise.exercise.ExerciseService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -24,18 +20,16 @@ import java.util.List;
...
@@ -24,18 +20,16 @@ import java.util.List;
@Service
@Service
public
class
QuestionFacade
{
public
class
QuestionFacade
{
private
final
QuestionService
questionService
;
private
final
QuestionService
questionService
;
private
final
ExerciseService
exerciseService
;
private
final
AnswerService
answerService
;
private
final
AnswerService
answerService
;
private
final
QuestionMapper
questionMapper
;
private
final
QuestionMapper
questionMapper
;
private
final
AnswerMapper
answerMapper
;
private
final
AnswerMapper
answerMapper
;
@Autowired
@Autowired
public
QuestionFacade
(
public
QuestionFacade
(
QuestionService
questionService
,
ExerciseService
exerciseService
,
QuestionService
questionService
,
AnswerService
answerService
,
QuestionMapper
questionMapper
,
AnswerService
answerService
,
QuestionMapper
questionMapper
,
AnswerMapper
answerMapper
)
{
AnswerMapper
answerMapper
)
{
this
.
questionService
=
questionService
;
this
.
questionService
=
questionService
;
this
.
exerciseService
=
exerciseService
;
this
.
answerService
=
answerService
;
this
.
answerService
=
answerService
;
this
.
questionMapper
=
questionMapper
;
this
.
questionMapper
=
questionMapper
;
this
.
answerMapper
=
answerMapper
;
this
.
answerMapper
=
answerMapper
;
...
@@ -48,8 +42,7 @@ public class QuestionFacade {
...
@@ -48,8 +42,7 @@ public class QuestionFacade {
* @return a QuestionDto object representing the found question
* @return a QuestionDto object representing the found question
*/
*/
public
QuestionDto
find
(
long
id
)
{
public
QuestionDto
find
(
long
id
)
{
var
a
=
questionService
.
find
(
id
);
return
questionMapper
.
toDto
(
questionService
.
find
(
id
));
return
questionMapper
.
toDto
(
a
);
}
}
/**
/**
...
@@ -69,30 +62,7 @@ public class QuestionFacade {
...
@@ -69,30 +62,7 @@ public class QuestionFacade {
* @return a QuestionDto object representing the added question
* @return a QuestionDto object representing the added question
*/
*/
public
QuestionDto
create
(
QuestionCreateDto
dto
)
{
public
QuestionDto
create
(
QuestionCreateDto
dto
)
{
Question
question
=
questionMapper
.
fromCreateDto
(
dto
);
return
questionMapper
.
toDto
(
questionService
.
create
(
questionMapper
.
fromCreateDto
(
dto
)));
Exercise
exercise
;
exercise
=
exerciseService
.
find
(
dto
.
getExerciseId
());
exercise
.
getQuestions
().
add
(
question
);
question
.
setExercise
(
exercise
);
var
answerDtos
=
dto
.
getAnswers
();
var
answers
=
new
HashSet
<
Answer
>();
for
(
var
answerDto
:
answerDtos
)
{
Answer
answer
=
answerMapper
.
fromCreateDto
(
answerDto
);
answer
=
answerService
.
create
(
answer
);
answers
.
add
(
answer
);
}
question
.
setAnswers
(
answers
);
var
createdQuestion
=
questionService
.
create
(
question
);
for
(
var
answer
:
answers
)
{
answer
.
setQuestion
(
createdQuestion
);
}
return
questionMapper
.
toDto
(
createdQuestion
);
}
}
/**
/**
...
@@ -102,8 +72,8 @@ public class QuestionFacade {
...
@@ -102,8 +72,8 @@ public class QuestionFacade {
* @return dto of updated question
* @return dto of updated question
*/
*/
public
QuestionDto
patchUpdate
(
long
id
,
QuestionUpdateDto
dto
)
{
public
QuestionDto
patchUpdate
(
long
id
,
QuestionUpdateDto
dto
)
{
var
a
=
questionService
.
patchUpdateWithoutAnswers
(
id
,
questionMapper
.
fromUpdateDto
(
dto
));
var
updatedQuestion
=
questionService
.
patchUpdateWithoutAnswers
(
id
,
questionMapper
.
fromUpdateDto
(
dto
));
return
questionMapper
.
toDto
(
a
);
return
questionMapper
.
toDto
(
updatedQuestion
);
}
}
/**
/**
...
@@ -112,10 +82,6 @@ public class QuestionFacade {
...
@@ -112,10 +82,6 @@ public class QuestionFacade {
* @param id of qustion to delete
* @param id of qustion to delete
*/
*/
public
void
delete
(
long
id
)
{
public
void
delete
(
long
id
)
{
var
question
=
questionService
.
find
(
id
);
for
(
var
answer
:
question
.
getAnswers
())
{
answerService
.
delete
(
answer
.
getId
());
}
questionService
.
delete
(
id
);
questionService
.
delete
(
id
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment