-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlanToResourceConverter.java
31 lines (27 loc) · 1.14 KB
/
PlanToResourceConverter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package io.myfinbox.spendingplan.adapter.web.converters;
import io.myfinbox.rest.JarResource;
import io.myfinbox.rest.PlanResource;
import io.myfinbox.spendingplan.domain.Jar;
import io.myfinbox.spendingplan.domain.Plan;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
final class PlanToResourceConverter implements Converter<Plan, PlanResource> {
private final Converter<Jar, JarResource> jarResourceConverter;
@Override
public PlanResource convert(Plan plan) {
return new PlanResource()
.planId(plan.getId().id())
.name(plan.getName())
.creationTimestamp(plan.getCreationTimestamp().toString())
.amount(plan.getAmountAsNumber())
.currencyCode(plan.getCurrencyCode())
.accountId(plan.getAccount().id())
.description(plan.getDescription())
.jars(plan.getJars().stream()
.map(jarResourceConverter::convert)
.toList());
}
}