Skip to content

Commit

Permalink
feat: add updatedCount to NotificationsReadAllNotifications response …
Browse files Browse the repository at this point in the history
…and extend request with additional parameters

- Added 'updatedCount' to `NotificationsReadAllNotificationsOKResponse` and updated the required fields.
- Extended the `NotificationsReadAllNotificationsOKResponseBody` class to include 'updatedCount' with validation and getter methods.
- Enhanced the `NotificationsReadAllNotificationsRequest` class by adding optional parameters: 'severities', 'referenceId', 'referenceAggregate', and 'referenceDomain' with respective validation and methods for handling these new fields.
  • Loading branch information
mittwald-machine committed Oct 10, 2024
1 parent 43d8291 commit 3d634a3
Show file tree
Hide file tree
Showing 5 changed files with 946 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ class NotificationsReadAllNotificationsOKResponse implements ResponseContainer
'status' => [
'$ref' => '#/components/schemas/de.mittwald.v1.messaging.NotificationStatus',
],
'updatedCount' => [
'description' => 'The number of notifications that have been updated.',
'format' => 'int32',
'type' => 'integer',
],
],
'required' => [
'status',
'updatedCount',
],
'type' => 'object',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,42 @@ class NotificationsReadAllNotificationsOKResponseBody
'status' => [
'$ref' => '#/components/schemas/de.mittwald.v1.messaging.NotificationStatus',
],
'updatedCount' => [
'description' => 'The number of notifications that have been updated.',
'format' => 'int32',
'type' => 'integer',
],
],
'required' => [
'status',
'updatedCount',
],
'type' => 'object',
];

private NotificationStatus $status;

public function __construct(NotificationStatus $status)
/**
* The number of notifications that have been updated.
*/
private int $updatedCount;

public function __construct(NotificationStatus $status, int $updatedCount)
{
$this->status = $status;
$this->updatedCount = $updatedCount;
}

public function getStatus(): NotificationStatus
{
return $this->status;
}

public function getUpdatedCount(): int
{
return $this->updatedCount;
}

public function withStatus(NotificationStatus $status): self
{
$clone = clone $this;
Expand All @@ -45,6 +62,20 @@ public function withStatus(NotificationStatus $status): self
return $clone;
}

public function withUpdatedCount(int $updatedCount): self
{
$validator = new Validator();
$validator->validate($updatedCount, static::$schema['properties']['updatedCount']);
if (!$validator->isValid()) {
throw new InvalidArgumentException($validator->getErrors()[0]['message']);
}

$clone = clone $this;
$clone->updatedCount = $updatedCount;

return $clone;
}

/**
* Builds a new instance from an input array
*
Expand All @@ -61,8 +92,9 @@ public static function buildFromInput(array|object $input, bool $validate = true
}

$status = NotificationStatus::from($input->{'status'});
$updatedCount = (int)($input->{'updatedCount'});

$obj = new self($status);
$obj = new self($status, $updatedCount);

return $obj;
}
Expand All @@ -76,6 +108,7 @@ public function toJson(): array
{
$output = [];
$output['status'] = $this->status->value;
$output['updatedCount'] = $this->updatedCount;

return $output;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ class NotificationsReadAllNotificationsRequest
private static array $schema = [
'type' => 'object',
'properties' => [
'severities' => [
'items' => [
'enum' => [
'success',
'info',
'warning',
'error',
],
'type' => 'string',
],
'type' => 'array',
],
'referenceId' => [
'format' => 'uuid',
'type' => 'string',
],
'referenceAggregate' => [
'type' => 'string',
],
'referenceDomain' => [
'type' => 'string',
],
'body' => [
'type' => 'object',
],
Expand All @@ -26,6 +48,17 @@ class NotificationsReadAllNotificationsRequest
],
];

/**
* @var string[]|null
*/
private ?array $severities = null;

private ?string $referenceId = null;

private ?string $referenceAggregate = null;

private ?string $referenceDomain = null;

private NotificationsReadAllNotificationsRequestBody $body;

private array $headers = [
Expand All @@ -37,11 +70,125 @@ public function __construct(NotificationsReadAllNotificationsRequestBody $body)
$this->body = $body;
}

/**
* @return string[]|null
*/
public function getSeverities(): ?array
{
return $this->severities ?? null;
}

public function getReferenceId(): ?string
{
return $this->referenceId ?? null;
}

public function getReferenceAggregate(): ?string
{
return $this->referenceAggregate ?? null;
}

public function getReferenceDomain(): ?string
{
return $this->referenceDomain ?? null;
}

public function getBody(): NotificationsReadAllNotificationsRequestBody
{
return $this->body;
}

/**
* @param string[] $severities
*/
public function withSeverities(array $severities): self
{
$validator = new Validator();
$validator->validate($severities, static::$schema['properties']['severities']);
if (!$validator->isValid()) {
throw new InvalidArgumentException($validator->getErrors()[0]['message']);
}

$clone = clone $this;
$clone->severities = $severities;

return $clone;
}

public function withoutSeverities(): self
{
$clone = clone $this;
unset($clone->severities);

return $clone;
}

public function withReferenceId(string $referenceId): self
{
$validator = new Validator();
$validator->validate($referenceId, static::$schema['properties']['referenceId']);
if (!$validator->isValid()) {
throw new InvalidArgumentException($validator->getErrors()[0]['message']);
}

$clone = clone $this;
$clone->referenceId = $referenceId;

return $clone;
}

public function withoutReferenceId(): self
{
$clone = clone $this;
unset($clone->referenceId);

return $clone;
}

public function withReferenceAggregate(string $referenceAggregate): self
{
$validator = new Validator();
$validator->validate($referenceAggregate, static::$schema['properties']['referenceAggregate']);
if (!$validator->isValid()) {
throw new InvalidArgumentException($validator->getErrors()[0]['message']);
}

$clone = clone $this;
$clone->referenceAggregate = $referenceAggregate;

return $clone;
}

public function withoutReferenceAggregate(): self
{
$clone = clone $this;
unset($clone->referenceAggregate);

return $clone;
}

public function withReferenceDomain(string $referenceDomain): self
{
$validator = new Validator();
$validator->validate($referenceDomain, static::$schema['properties']['referenceDomain']);
if (!$validator->isValid()) {
throw new InvalidArgumentException($validator->getErrors()[0]['message']);
}

$clone = clone $this;
$clone->referenceDomain = $referenceDomain;

return $clone;
}

public function withoutReferenceDomain(): self
{
$clone = clone $this;
unset($clone->referenceDomain);

return $clone;
}

public function withBody(NotificationsReadAllNotificationsRequestBody $body): self
{
$clone = clone $this;
Expand All @@ -65,10 +212,29 @@ public static function buildFromInput(array|object $input, bool $validate = true
static::validateInput($input);
}

$severities = null;
if (isset($input->{'severities'})) {
$severities = $input->{'severities'};
}
$referenceId = null;
if (isset($input->{'referenceId'})) {
$referenceId = $input->{'referenceId'};
}
$referenceAggregate = null;
if (isset($input->{'referenceAggregate'})) {
$referenceAggregate = $input->{'referenceAggregate'};
}
$referenceDomain = null;
if (isset($input->{'referenceDomain'})) {
$referenceDomain = $input->{'referenceDomain'};
}
$body = NotificationsReadAllNotificationsRequestBody::buildFromInput($input->{'body'}, validate: $validate);

$obj = new self($body);

$obj->severities = $severities;
$obj->referenceId = $referenceId;
$obj->referenceAggregate = $referenceAggregate;
$obj->referenceDomain = $referenceDomain;
return $obj;
}

Expand All @@ -80,6 +246,18 @@ public static function buildFromInput(array|object $input, bool $validate = true
public function toJson(): array
{
$output = [];
if (isset($this->severities)) {
$output['severities'] = $this->severities;
}
if (isset($this->referenceId)) {
$output['referenceId'] = $this->referenceId;
}
if (isset($this->referenceAggregate)) {
$output['referenceAggregate'] = $this->referenceAggregate;
}
if (isset($this->referenceDomain)) {
$output['referenceDomain'] = $this->referenceDomain;
}
$output['body'] = ($this->body)->toJson();

return $output;
Expand Down Expand Up @@ -142,6 +320,18 @@ public function buildRequestOptions(): array
{
$mapped = $this->toJson();
$query = [];
if (isset($mapped['severities'])) {
$query['severities'] = $mapped['severities'];
}
if (isset($mapped['referenceId'])) {
$query['referenceId'] = $mapped['referenceId'];
}
if (isset($mapped['referenceAggregate'])) {
$query['referenceAggregate'] = $mapped['referenceAggregate'];
}
if (isset($mapped['referenceDomain'])) {
$query['referenceDomain'] = $mapped['referenceDomain'];
}
return [
'query' => $query,
'headers' => $this->headers,
Expand Down
Loading

0 comments on commit 3d634a3

Please sign in to comment.