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