Skip to content

Commit

Permalink
Merge pull request #1 from koencaerels/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
koencaerels authored Oct 4, 2023
2 parents ae4f868 + a64e7d4 commit 31fe50c
Show file tree
Hide file tree
Showing 112 changed files with 3,679 additions and 543 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private function __construct(
protected string $code,
protected string $name,
protected int $yearlySubscriptionFee,
protected string $publicLabel,
) {
}

Expand All @@ -34,6 +35,7 @@ public static function hydrateFromJson($json): self
trim($json->code),
trim($json->name),
intval($json->yearlySubscriptionFee),
trim($json->publicLabel),
);
}

Expand All @@ -55,4 +57,9 @@ public function getYearlySubscriptionFee(): int
{
return $this->yearlySubscriptionFee;
}

public function getPublicLabel(): string
{
return $this->publicLabel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public function go(AddFederation $command): bool
1,
$command->getCode(),
$command->getName(),
$command->getYearlySubscriptionFee()
$command->getYearlySubscriptionFee(),
$command->getPublicLabel()
);
$this->federationRepo->save($model);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private function __construct(
protected string $code,
protected string $name,
protected int $yearlySubscriptionFee,
protected string $publicLabel,
) {
}

Expand All @@ -36,6 +37,7 @@ public static function hydrateFromJson($json): self
trim($json->code),
trim($json->name),
intval($json->yearlySubscriptionFee),
trim($json->publicLabel)
);
}

Expand All @@ -62,4 +64,9 @@ public function getYearlySubscriptionFee(): int
{
return $this->yearlySubscriptionFee;
}

public function getPublicLabel(): string
{
return $this->publicLabel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ public function __construct(
// Handler
// —————————————————————————————————————————————————————————————————————————

public function Change(ChangeFederation $command): bool
public function go(ChangeFederation $command): bool
{
$model = $this->federationRepo->getById($command->getId());
$model->change(
$command->getCode(),
$command->getName(),
$command->getYearlySubscriptionFee()
$command->getYearlySubscriptionFee(),
$command->getPublicLabel()
);
$this->federationRepo->save($model);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
namespace App\YoshiKan\Application\Command\Member\ChangeMemberGrade;

use App\YoshiKan\Domain\Model\Member\GradeLog;
use App\YoshiKan\Domain\Model\Member\GradeLogRepository;
use App\YoshiKan\Domain\Model\Member\GradeRepository;
use App\YoshiKan\Domain\Model\Member\MemberRepository;
use App\YoshiKan\Infrastructure\Database\Member\GradeLogRepository;

class ChangeMemberGradeHandler
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\YoshiKan\Application\Command\Member\MarkSubscriptionAsCanceled;

class MarkSubscriptionAsCanceled
{
// —————————————————————————————————————————————————————————————————————————
// Constructor
// —————————————————————————————————————————————————————————————————————————

private function __construct(
protected int $id,
) {
}

// —————————————————————————————————————————————————————————————————————————
// Hydrate from a json command
// —————————————————————————————————————————————————————————————————————————

public static function make(int $subscriptionId): self
{
return new self($subscriptionId);
}

public static function hydrateFromJson($json): self
{
return new self(
$json->id,
);
}

// —————————————————————————————————————————————————————————————————————————
// Getters
// —————————————————————————————————————————————————————————————————————————

public function getId(): int
{
return $this->id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\YoshiKan\Application\Command\Member\MarkSubscriptionAsCanceled;

use App\YoshiKan\Domain\Model\Member\SubscriptionRepository;
use App\YoshiKan\Domain\Model\Member\SubscriptionStatus;

class MarkSubscriptionAsCanceledHandler
{
// —————————————————————————————————————————————————————————————————————————
// Constructor
// —————————————————————————————————————————————————————————————————————————

public function __construct(
protected SubscriptionRepository $subscriptionRepository
) {
}

// —————————————————————————————————————————————————————————————————————————
// Handler
// —————————————————————————————————————————————————————————————————————————

public function go(MarkSubscriptionAsCanceled $command): bool
{
$subscription = $this->subscriptionRepository->getById($command->getId());
$result = false;

if (SubscriptionStatus::NEW === $subscription->getStatus()
|| SubscriptionStatus::AWAITING_PAYMENT === $subscription->getStatus()) {
$subscription->changeStatus(SubscriptionStatus::CANCELED);
$this->subscriptionRepository->save($subscription);
$result = true;
}

return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\YoshiKan\Application\Command\Member\MarkSubscriptionAsCanceled;

trait mark_subscription_as_canceled
{
/**
* @throws \Exception
*/
public function markSubscriptionAsCanceled(\stdClass $jsonCommand): bool
{
$command = MarkSubscriptionAsCanceled::hydrateFromJson($jsonCommand);

$this->permission->CheckRole(['ROLE_DEVELOPER', 'ROLE_ADMIN', 'ROLE_CHIEF_EDITOR']);

$handler = new MarkSubscriptionAsCanceledHandler($this->subscriptionRepository);
$result = $handler->go($command);
$this->entityManager->flush();

return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\YoshiKan\Application\Command\Member\MarkSubscriptionAsFinished;

class MarkSubscriptionAsFinished
{
// —————————————————————————————————————————————————————————————————————————
// Constructor
// —————————————————————————————————————————————————————————————————————————

private function __construct(
protected int $id,
) {
}

// —————————————————————————————————————————————————————————————————————————
// Hydrate from a json command
// —————————————————————————————————————————————————————————————————————————

public static function make(int $subscriptionId): self
{
return new self($subscriptionId);
}

public static function hydrateFromJson($json): self
{
return new self(
$json->id,
);
}

// —————————————————————————————————————————————————————————————————————————
// Getters
// —————————————————————————————————————————————————————————————————————————

public function getId(): int
{
return $this->id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\YoshiKan\Application\Command\Member\MarkSubscriptionAsFinished;

use App\YoshiKan\Domain\Model\Member\SubscriptionRepository;
use App\YoshiKan\Domain\Model\Member\SubscriptionStatus;

class MarkSubscriptionAsFinishedHandler
{
// —————————————————————————————————————————————————————————————————————————
// Constructor
// —————————————————————————————————————————————————————————————————————————

public function __construct(
protected SubscriptionRepository $subscriptionRepository
) {
}

// —————————————————————————————————————————————————————————————————————————
// Handler
// —————————————————————————————————————————————————————————————————————————
public function go(MarkSubscriptionAsFinished $command): bool
{
$result = false;
$subscription = $this->subscriptionRepository->getById($command->getId());

if (SubscriptionStatus::PAYED === $subscription->getStatus()) {
$subscription->changeStatus(SubscriptionStatus::COMPLETE);
$this->subscriptionRepository->save($subscription);
$result = true;
}

return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\YoshiKan\Application\Command\Member\MarkSubscriptionAsFinished;

trait mark_subscription_as_finished
{
/**
* @throws \Exception
*/
public function markSubscriptionAsFinished(\stdClass $jsonCommand): bool
{
$command = MarkSubscriptionAsFinished::hydrateFromJson($jsonCommand);

$this->permission->CheckRole(['ROLE_DEVELOPER', 'ROLE_ADMIN', 'ROLE_CHIEF_EDITOR']);

$handler = new MarkSubscriptionAsFinishedHandler($this->subscriptionRepository);
$result = $handler->go($command);
$this->entityManager->flush();

return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,37 @@

class MarkSubscriptionAsPayed
{
// —————————————————————————————————————————————————————————————————————————
// Constructor
// —————————————————————————————————————————————————————————————————————————

private function __construct(
protected int $id,
) {
}

// —————————————————————————————————————————————————————————————————————————
// Hydrate from a json command
// —————————————————————————————————————————————————————————————————————————

public static function make(int $subscriptionId): self
{
return new self($subscriptionId);
}

public static function hydrateFromJson($json): self
{
return new self(
$json->id,
);
}

// —————————————————————————————————————————————————————————————————————————
// Getters
// —————————————————————————————————————————————————————————————————————————

public function getId(): int
{
return $this->id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,63 @@

namespace App\YoshiKan\Application\Command\Member\MarkSubscriptionAsPayed;

use App\YoshiKan\Application\Command\Member\MarkSubscriptionAsCanceled\MarkSubscriptionAsCanceled;
use App\YoshiKan\Application\Command\Member\MarkSubscriptionAsCanceled\MarkSubscriptionAsCanceledHandler;
use App\YoshiKan\Domain\Model\Member\MemberRepository;
use App\YoshiKan\Domain\Model\Member\SubscriptionRepository;
use App\YoshiKan\Domain\Model\Member\SubscriptionStatus;

class MarkSubscriptionAsPayedHandler
{
// —————————————————————————————————————————————————————————————————————————
// Constructor
// —————————————————————————————————————————————————————————————————————————

public function __construct(
protected SubscriptionRepository $subscriptionRepository,
protected MemberRepository $memberRepository
) {
}

// —————————————————————————————————————————————————————————————————————————
// Handler
// —————————————————————————————————————————————————————————————————————————

public function go(MarkSubscriptionAsPayed $command): bool
{
$result = false;
$subscription = $this->subscriptionRepository->getById($command->getId());

if (SubscriptionStatus::AWAITING_PAYMENT === $subscription->getStatus()) {
$subscription->changeStatus(SubscriptionStatus::PAYED);
$this->subscriptionRepository->save($subscription);
$result = true;
}

// mark the subscription and license as paid on the actual member
if ($result && !is_null($subscription->getMember())) {
$member = $subscription->getMember();
if ($subscription->isMemberSubscriptionIsPartSubscription()) {
$member->markSubscriptionAsPayed();
}
if ($subscription->isLicenseIsPartSubscription()) {
$member->markLicenseAsPayed();
}
$this->memberRepository->save($member);
}

// cancel all other pending subscriptions for this member
if ($result && !is_null($subscription->getMember())) {
$cancelHandler = new MarkSubscriptionAsCanceledHandler($this->subscriptionRepository);
$subscriptions = $this->subscriptionRepository->getByMember($subscription->getMember());
foreach ($subscriptions as $subscription) {
if ($subscription->getId() !== $command->getId()) {
$cancelCommand = MarkSubscriptionAsCanceled::make($subscription->getId());
$cancelHandler->go($cancelCommand);
}
}
}

return $result;
}
}
Loading

0 comments on commit 31fe50c

Please sign in to comment.