Skip to content

Commit

Permalink
remove create part, keep only update
Browse files Browse the repository at this point in the history
  • Loading branch information
miqayelsrapionyan committed Sep 13, 2023
1 parent 4787454 commit 12ea968
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 84 deletions.
2 changes: 1 addition & 1 deletion build/GPBMetadata/Proto/Translation.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 6 additions & 33 deletions build/TranslationPackage/TranslationItem.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions proto/translation.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ message TranslationItem {
string resource = 5;
string resource_id = 6;
string editor = 7;
string created_at = 8;
string updated_at = 9;
map<string, string> params = 10;
string updated_at = 8;
map<string, string> params = 9;
}

message OrderBy {
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/ColumnEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
enum ColumnEnum: string
{
case KEY = 'key';
case CREATED_AT = 'created_at';
case UPDATED_AT = 'updated_at';
}
12 changes: 3 additions & 9 deletions src/TranslationAppClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function getTranslations(TranslationQueryValueObject $valueObject): array
'id' => $translationItem->getId(),
'key' => $translationItem->getKey(),
'value' => $translationItem->getValue(),
'createdAt' => $translationItem->getCreatedAt(),
'updatedAt' => $translationItem->getUpdatedAt(),
'editor' => $translationItem->getEditor(),
'params' => $translationItem->getParams(),
Expand All @@ -66,27 +65,23 @@ public function getTranslations(TranslationQueryValueObject $valueObject): array
}

/**
* Update translation if id exists, or create new one.
* Update translation by id.
*
* @param \Uc\TranslationAppSdk\ValueObjects\TranslationItemValueObject $valueObject
*
* @return array
*/
public function updateOrCreate(TranslationItemValueObject $valueObject): array
public function update(TranslationItemValueObject $valueObject): array
{
$data = new TranslationItem();

if ($valueObject->hasId()) {
$data->setId($valueObject->getId());
}

if ($valueObject->hasParams()) {
$data->setParams($valueObject->getParams());
}

$data->setId($valueObject->getId());
$data->setKey($valueObject->getKey());
$data->setValue($valueObject->getValue());
$data->setCreatedAt($valueObject->getCreatedAt());
$data->setUpdatedAt($valueObject->getUpdatedAt());
$data->setEditor($valueObject->getEditor());
$data->setResource($valueObject->getResource());
Expand All @@ -101,7 +96,6 @@ public function updateOrCreate(TranslationItemValueObject $valueObject): array
'id' => $data->getId(),
'key' => $data->getKey(),
'value' => $data->getValue(),
'createdAt' => $data->getCreatedAt(),
'updatedAt' => $data->getUpdatedAt(),
'editor' => $data->getEditor(),
'resource' => $data->getResource(),
Expand Down
41 changes: 12 additions & 29 deletions src/ValueObjects/TranslationItemValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@

namespace Uc\TranslationAppSdk\ValueObjects;

class TranslationItemValueObject
readonly class TranslationItemValueObject
{
public function __construct(
protected readonly string $key,
protected readonly string $value,
protected readonly string $languageCode,
protected readonly string $createdAt,
protected readonly string $updatedAt,
protected readonly string $resource,
protected readonly int $resourceId,
protected readonly string $editor,
protected readonly ?int $id,
protected readonly ?array $params,
protected string $key,
protected string $value,
protected string $languageCode,
protected string $updatedAt,
protected string $resource,
protected int $resourceId,
protected string $editor,
protected int $id,
protected ?array $params,
)
{
}
Expand Down Expand Up @@ -61,14 +60,6 @@ public function getLanguageCode(): string
return $this->languageCode;
}

/**
* @return string
*/
public function getCreatedAt(): string
{
return $this->createdAt;
}

/**
* @return string
*/
Expand All @@ -86,21 +77,13 @@ public function getResourceId(): int
}

/**
* @return int|null
* @return int
*/
public function getId(): ?int
public function getId(): int
{
return $this->id;
}

/**
* @return bool
*/
public function hasId(): bool
{
return !empty($this->getId());
}

/**
* @return array|null
*/
Expand Down
16 changes: 8 additions & 8 deletions src/ValueObjects/TranslationQueryValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace Uc\TranslationAppSdk\ValueObjects;

class TranslationQueryValueObject
readonly class TranslationQueryValueObject
{
public function __construct(
protected readonly int $resourceId,
protected readonly string $languageCode,
protected readonly string $resource,
protected readonly ?string $key = null,
protected readonly array $orderBy = [],
protected readonly int $page = 0,
protected readonly int $first = 10,
protected int $resourceId,
protected string $languageCode,
protected string $resource,
protected ?string $key = null,
protected array $orderBy = [],
protected int $page = 0,
protected int $first = 10,
){
}

Expand Down

0 comments on commit 12ea968

Please sign in to comment.