1818
1919import java .util .HashSet ;
2020import java .util .List ;
21- import java .util .Optional ;
2221import java .util .Set ;
2322import java .util .stream .Collectors ;
2423
2928@ SuppressWarnings ("java:S6813" )
3029public abstract class TaskMapper {
3130 @ Autowired
32- private TaskStatusRepository taskStatusRepository ;
31+ private TaskStatusRepository taskStatusRepository ;
3332 @ Autowired
34- private LabelRepository labelRepository ;
35-
33+ private LabelRepository labelRepository ;
3634
3735 @ Mapping (target = "name" , source = "title" )
3836 @ Mapping (target = "description" , source = "content" )
@@ -48,6 +46,13 @@ public abstract class TaskMapper {
4846 @ Mapping (target = "taskLabelIds" , source = "labels" ) // , qualifiedByName = "mapTaskLabel")
4947 public abstract TaskDTO map (Task model );
5048
49+ @ Mapping (target = "name" , source = "title" )
50+ @ Mapping (target = "description" , source = "content" )
51+ @ Mapping (target = "taskStatus.slug" , source = "status" )
52+ @ Mapping (target = "assignee.id" , source = "assigneeId" )
53+ @ Mapping (target = "labels" , source = "taskLabelIds" )
54+ public abstract Task map (TaskDTO model ); // for test
55+
5156 @ Mapping (target = "name" , source = "title" )
5257 @ Mapping (target = "description" , source = "content" )
5358 @ Mapping (target = "taskStatus" , source = "status" )
@@ -72,17 +77,8 @@ public Set<Label> toLabels(Set<Long> taskLabelIds) {
7277 if (taskLabelIds == null ) {
7378 return new HashSet <>();
7479 } else {
75- Set <Label > result = new HashSet <>();
76- List <Label > listLabels = labelRepository .findAll ();
77- for (Long n : taskLabelIds ) {
78- Optional <Label > value = listLabels .stream ()
79- .filter (v -> (v .getId () == n ))
80- .findFirst ();
81- if (value .isPresent ()) {
82- result .add (value .get ());
83- }
84- }
85- return result ;
80+ List <Label > listLabels = labelRepository .findAllById (taskLabelIds );
81+ return new HashSet <>(listLabels );
8682 }
8783 }
8884
0 commit comments