parent
e2cf8b34d0
commit
1f97a8ceac
@ -1,9 +1,27 @@
|
|||||||
package com.flagg10ma.taf.dto;
|
package com.flagg10ma.taf.dto;
|
||||||
|
|
||||||
|
import com.flagg10ma.taf.model.Event;
|
||||||
|
import com.flagg10ma.taf.model.Label;
|
||||||
|
import com.flagg10ma.taf.model.Task;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public record CompleteEventDto(
|
public record CompleteEventDto(
|
||||||
EventDto event,
|
EventDto event,
|
||||||
Collection<LabelDto> labels
|
Collection<LabelDto> labels
|
||||||
) {
|
) {
|
||||||
|
public static CompleteEventDto fromModel(Event event) {
|
||||||
|
Set<Label> allLabels = new HashSet<>();
|
||||||
|
|
||||||
|
for (Task task : event.tasks()) {
|
||||||
|
allLabels.addAll(task.labels());
|
||||||
|
}
|
||||||
|
return new CompleteEventDto(
|
||||||
|
EventDto.fromModel(event),
|
||||||
|
allLabels.stream().map(LabelDto::fromModel).collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,28 @@
|
|||||||
package com.flagg10ma.taf.dto;
|
package com.flagg10ma.taf.dto;
|
||||||
|
|
||||||
|
import com.flagg10ma.taf.model.Event;
|
||||||
|
import com.flagg10ma.taf.model.Label;
|
||||||
|
import com.flagg10ma.taf.model.Task;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public record EventListDto(
|
public record EventListDto(
|
||||||
Collection<EventDto> events,
|
Collection<EventDto> events,
|
||||||
Collection<LabelDto> labels
|
Collection<LabelDto> labels
|
||||||
) {
|
) {
|
||||||
|
public static EventListDto fromModel(Collection<Event> events) {
|
||||||
|
Set<Label> allLabels = new HashSet<>();
|
||||||
|
|
||||||
|
for (Event event : events)
|
||||||
|
for (Task task : event.tasks()) {
|
||||||
|
allLabels.addAll(task.labels());
|
||||||
|
}
|
||||||
|
return new EventListDto(
|
||||||
|
events.stream().map(EventDto::fromModel).collect(Collectors.toList()),
|
||||||
|
allLabels.stream().map(LabelDto::fromModel).collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,32 @@
|
|||||||
package com.flagg10ma.taf.dto;
|
package com.flagg10ma.taf.dto;
|
||||||
|
|
||||||
|
import com.flagg10ma.taf.model.Event;
|
||||||
|
import com.flagg10ma.taf.model.Task;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public record TaskListDto(
|
public record TaskListDto(
|
||||||
Collection<SimplifiedTaskDto> tasks,
|
Collection<SimplifiedTaskDto> tasks,
|
||||||
Collection<SimplifiedEventDto> events,
|
Collection<SimplifiedEventDto> events,
|
||||||
Collection<LabelDto> labels
|
Collection<LabelDto> labels
|
||||||
) {
|
) {
|
||||||
|
public static TaskListDto fromModel(Collection<Task> tasks, Collection<Event> events) {
|
||||||
|
Collection<SimplifiedTaskDto> taskDtos = tasks.stream()
|
||||||
|
.map(SimplifiedTaskDto::fromModel)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
Collection<SimplifiedEventDto> eventDtos = events.stream()
|
||||||
|
.map(SimplifiedEventDto::fromModel)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
Set<LabelDto> labelDtos = new HashSet<>();
|
||||||
|
for (Task task: tasks) {
|
||||||
|
labelDtos.addAll(task.labels().stream().map(LabelDto::fromModel).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TaskListDto(taskDtos, eventDtos, labelDtos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue