Skip to content

Commit

Permalink
Merge pull request #15 from hnuti-brontosaurus/event-tags
Browse files Browse the repository at this point in the history
event response: support tags
  • Loading branch information
dakur authored Nov 18, 2023
2 parents 7cd11ad + e0ad0b6 commit cf10f8d
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Event/Response/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class Event
{

/**
* @param Tag[] $tags
* @param string[] $administrationUnits
* @param Photo[] $photos
* @param array<mixed> $rawData
Expand All @@ -34,6 +35,7 @@ private function __construct(
private Location $location,
private Group $group,
private Category $category,
private array $tags,
private Program $program,
private IntendedFor $intendedFor,
private array $administrationUnits,
Expand Down Expand Up @@ -80,6 +82,13 @@ private function __construct(
* name: string,
* slug: string,
* },
* tags: array<array{
* id: int,
* name: string,
* slug: string,
* description: string,
* is_active: bool,
* }>,
* program: array{
* id: int,
* name: string,
Expand Down Expand Up @@ -141,6 +150,7 @@ public static function fromResponseData(array $data): self
),
Group::fromScalar($data['group']['slug']),
Category::fromScalar($data['category']['slug']),
array_map(static fn(array $tag) => Tag::fromPayload($tag), $data['tags']),
Program::fromScalar($data['program']['slug']),
IntendedFor::fromScalar($data['intended_for']['slug']),
$data['administration_units'],
Expand Down Expand Up @@ -242,6 +252,15 @@ public function getCategory(): Category
}


/**
* @return Tag[]
*/
public function getTags(): array
{
return $this->tags;
}


public function getProgram(): Program
{
return $this->program;
Expand Down
68 changes: 68 additions & 0 deletions src/Event/Response/Tag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php declare(strict_types = 1);

namespace HnutiBrontosaurus\BisClient\Event\Response;


final class Tag
{

private function __construct(
private int $id,
private string $name,
private string $slug,
private string $description,
private bool $isActive,
) {}


/**
* @param array{
* id: int,
* name: string,
* slug: string,
* description: string,
* is_active: bool,
* } $payload
*/
public static function fromPayload(array $payload): self
{
return new self(
$payload['id'],
$payload['name'],
$payload['slug'],
$payload['description'],
$payload['is_active'],
);
}


public function getId(): int
{
return $this->id;
}


public function getName(): string
{
return $this->name;
}


public function getSlug(): string
{
return $this->slug;
}


public function getDescription(): string
{
return $this->description;
}


public function isActive(): bool
{
return $this->isActive;
}

}

0 comments on commit cf10f8d

Please sign in to comment.