diff --git a/src/ApiResource/Matchfunding/MatchStrategyApiResource.php b/src/ApiResource/Matchfunding/MatchStrategyApiResource.php index d96df59..98635bc 100644 --- a/src/ApiResource/Matchfunding/MatchStrategyApiResource.php +++ b/src/ApiResource/Matchfunding/MatchStrategyApiResource.php @@ -7,8 +7,11 @@ use ApiPlatform\Metadata as API; use App\ApiResource\Money; use App\Entity\Matchfunding\MatchAgainst; use App\Entity\Matchfunding\MatchStrategy; +use App\Mapping\Transformer\MatchFormulaMapTransformer; use App\State\ApiResourceStateProcessor; use App\State\ApiResourceStateProvider; +use AutoMapper\Attribute\MapFrom; +use AutoMapper\Attribute\MapTo; use Symfony\Component\Validator\Constraints as Assert; #[API\ApiResource( @@ -43,6 +46,8 @@ class MatchStrategyApiResource * The MatchFormula used to calculate matched funds. */ #[Assert\NotBlank()] + #[MapTo(MatchStrategy::class, property: 'formulaName', transformer: 'source.formula.name')] + #[MapFrom(MatchStrategy::class, property: 'formulaName', transformer: MatchFormulaMapTransformer::class)] public FormulaApiResource $formula; /** diff --git a/src/Mapping/Transformer/MatchFormulaMapTransformer.php b/src/Mapping/Transformer/MatchFormulaMapTransformer.php new file mode 100644 index 0000000..647123b --- /dev/null +++ b/src/Mapping/Transformer/MatchFormulaMapTransformer.php @@ -0,0 +1,21 @@ +formulaLocator->get($value); + + return FormulaApiResource::from($interface); + } +}