Paket 1: eine aktive Angebotsfassung und Bestellbezeichnung
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8cd382c357
commit
7820bececb
13 files changed
+529
-25
No files matched your search
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Catalog\OfferStatus;
|
||||
use App\Domain\Catalog\OfferVersion;
|
||||
use App\Models\User;
|
||||
@@ -11,9 +12,11 @@
|
||||
|
||||
class GrantIssuer
|
||||
{
|
||||
public function __construct(private readonly OfferService $offers) {}
|
||||
|
||||
public function claim(User $user, Offer $offer): Acquisition
|
||||
{
|
||||
$version = $this->activeVersion($offer);
|
||||
$version = $this->offers->currentActiveVersion($offer);
|
||||
|
||||
if (! in_array($version->grant_kind, ['auf_abruf', 'bei_registrierung'], true)) {
|
||||
throw new DomainRuleException('Dieses Angebot wird nicht frei vergeben.');
|
||||
@@ -32,8 +35,9 @@ public function grantRegistrationOffers(User $user): void
|
||||
->where('status', OfferStatus::Aktiv)
|
||||
->where('grant_kind', 'bei_registrierung')
|
||||
->where('holder_kind', 'person')
|
||||
->with('offer')
|
||||
->orderByDesc('number')
|
||||
->get()
|
||||
->unique('offer_id')
|
||||
->each(function (OfferVersion $version) use ($user): void {
|
||||
$this->issue($user, $version, AcquisitionType::FreierAbruf, 'offer', $version->offer_id);
|
||||
});
|
||||
@@ -47,7 +51,7 @@ public function grantManually(User $user, Offer $offer, User $actor, string $rea
|
||||
throw new DomainRuleException('Eine manuelle Vergabe braucht eine Begründung.');
|
||||
}
|
||||
|
||||
$version = $this->activeVersion($offer);
|
||||
$version = $this->offers->currentActiveVersion($offer);
|
||||
|
||||
if ($version->holder_kind !== 'person') {
|
||||
throw new DomainRuleException('Dieses Angebot richtet sich nicht an Personen.');
|
||||
@@ -118,15 +122,4 @@ public function issue(
|
||||
return $acquisition->load('grants');
|
||||
});
|
||||
}
|
||||
|
||||
private function activeVersion(Offer $offer): OfferVersion
|
||||
{
|
||||
$version = $offer->versions()->where('status', OfferStatus::Aktiv)->orderByDesc('number')->first();
|
||||
|
||||
if ($version === null) {
|
||||
throw new DomainRuleException('Das Angebot hat keine aktive Fassung.');
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user