fix membership
This commit is contained in:
parent
c15c210234
commit
350faba732
|
@ -207,7 +207,7 @@ class Api
|
|||
"Fails fetching membership {$membershipId} for {$memberId}",
|
||||
);
|
||||
|
||||
return $membership ? new Membership($membership) : null;
|
||||
return $membership ? Membership::from($membership) : null;
|
||||
}
|
||||
|
||||
public function courses(): Collection
|
||||
|
|
|
@ -3,35 +3,37 @@
|
|||
namespace Zoomyboy\LaravelNami\Data;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Spatie\DataTransferObject\Attributes\CastWith;
|
||||
use Spatie\DataTransferObject\Attributes\MapFrom;
|
||||
use Spatie\DataTransferObject\DataTransferObject;
|
||||
use Zoomyboy\LaravelNami\Casters\CarbonCaster;
|
||||
use Zoomyboy\LaravelNami\Casters\NullableCarbonCaster;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Attributes\WithCast;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Zoomyboy\LaravelNami\Casters\CarbonCast;
|
||||
|
||||
class Membership extends DataTransferObject
|
||||
class Membership extends Data
|
||||
{
|
||||
public ?int $id;
|
||||
public function __construct(
|
||||
public ?int $id,
|
||||
|
||||
#[MapFrom('gruppierungId')]
|
||||
public int $groupId;
|
||||
#[MapInputName('gruppierungId')]
|
||||
public int $groupId,
|
||||
|
||||
#[MapFrom('aktivVon')]
|
||||
#[CastWith(CarbonCaster::class)]
|
||||
public Carbon $startsAt;
|
||||
#[MapInputName('aktivVon')]
|
||||
#[WithCast(CarbonCast::class, format: 'Y-m-d H:i:s')]
|
||||
public Carbon $startsAt,
|
||||
|
||||
#[MapFrom('aktivBis')]
|
||||
#[CastWith(NullableCarbonCaster::class)]
|
||||
public ?Carbon $endsAt;
|
||||
#[MapInputName('aktivBis')]
|
||||
#[WithCast(CarbonCast::class, format: 'Y-m-d H:i:s')]
|
||||
public ?Carbon $endsAt,
|
||||
|
||||
#[MapFrom('taetigkeitId')]
|
||||
public int $activityId;
|
||||
#[MapInputName('taetigkeitId')]
|
||||
public int $activityId,
|
||||
|
||||
#[MapFrom('untergliederungId')]
|
||||
public ?int $subactivityId;
|
||||
#[MapInputName('untergliederungId')]
|
||||
public ?int $subactivityId,
|
||||
|
||||
#[MapFrom('gruppierung')]
|
||||
public ?string $group;
|
||||
#[MapInputName('gruppierung')]
|
||||
public ?string $group,
|
||||
) {
|
||||
}
|
||||
|
||||
public function toNami(): array
|
||||
{
|
||||
|
@ -44,16 +46,4 @@ class Membership extends DataTransferObject
|
|||
'untergliederungId' => $this->subactivityId,
|
||||
];
|
||||
}
|
||||
|
||||
public static function fromArray(array $data): self
|
||||
{
|
||||
return new self([
|
||||
'gruppierungId' => data_get($data, 'groupId'),
|
||||
'id' => data_get($data, 'id'),
|
||||
'aktivVon' => data_get($data, 'startsAt'),
|
||||
'aktivBis' => data_get($data, 'endsAt'),
|
||||
'taetigkeitId' => data_get($data, 'activityId'),
|
||||
'untergliederungId' => data_get($data, 'subactivityId'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ namespace Zoomyboy\LaravelNami\Data;
|
|||
use Carbon\Carbon;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Attributes\WithCast;
|
||||
use Spatie\LaravelData\Casts\DateTimeInterfaceCast;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Zoomyboy\LaravelNami\Casters\CarbonCast;
|
||||
use Zoomyboy\LaravelNami\Casters\StringCast;
|
||||
|
@ -19,7 +18,7 @@ class MembershipEntry extends Data
|
|||
public string $group,
|
||||
|
||||
#[MapInputName('entries_aktivVon')]
|
||||
#[WithCast(DateTimeInterfaceCast::class, format: 'Y-m-d H:i:s')]
|
||||
#[WithCast(CarbonCast::class, format: 'Y-m-d H:i:s')]
|
||||
public Carbon $startsAt,
|
||||
|
||||
#[MapInputName('entries_aktivBis')]
|
||||
|
|
|
@ -78,7 +78,7 @@ class MembershipTest extends TestCase
|
|||
Carbon::setTestNow(Carbon::parse('2022-02-03 03:00:00'));
|
||||
app(MembershipFake::class)->createsSuccessfully(6, 133);
|
||||
|
||||
$membershipId = $this->login()->putMembership(6, Membership::fromArray([
|
||||
$membershipId = $this->login()->putMembership(6, Membership::from([
|
||||
'id' => null,
|
||||
'subactivityId' => 3,
|
||||
'activityId' => 2,
|
||||
|
@ -102,7 +102,7 @@ class MembershipTest extends TestCase
|
|||
Carbon::setTestNow(Carbon::parse('2022-02-03 03:00:00'));
|
||||
app(MembershipFake::class)->destroysSuccessfully(6, 133);
|
||||
|
||||
$this->login()->deleteMembership(6, Membership::fromArray([
|
||||
$this->login()->deleteMembership(6, Membership::from([
|
||||
'id' => 133,
|
||||
'subactivityId' => 3,
|
||||
'activityId' => 2,
|
||||
|
@ -120,7 +120,7 @@ class MembershipTest extends TestCase
|
|||
app(MembershipFake::class)->failsDeleting(6, 133);
|
||||
app(MembershipFake::class)->updatesSuccessfully(6, 133);
|
||||
|
||||
$this->login()->deleteMembership(6, Membership::fromArray([
|
||||
$this->login()->deleteMembership(6, Membership::from([
|
||||
'id' => 133,
|
||||
'subactivityId' => 3,
|
||||
'activityId' => 2,
|
||||
|
@ -142,7 +142,7 @@ class MembershipTest extends TestCase
|
|||
app(MembershipFake::class)->failsDeleting(6, null);
|
||||
app(MembershipFake::class)->updatesSuccessfully(6, null);
|
||||
|
||||
$this->login()->deleteMembership(6, Membership::fromArray([
|
||||
$this->login()->deleteMembership(6, Membership::from([
|
||||
'id' => null,
|
||||
'subactivityId' => 3,
|
||||
'activityId' => 2,
|
||||
|
|
Loading…
Reference in New Issue