Skip to content

Commit 60e581a

Browse files
[Item] CAES-1512: Refactoring meta, implemented endpoint to check exists items. (#546)
Co-authored-by: Aleksandr Beshkenadze <ab@caesar.team>
1 parent 6928c51 commit 60e581a

30 files changed

Lines changed: 354 additions & 148 deletions

src/Controller/Api/Item/ItemController.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use App\Form\Type\Request\Item\CreateBatchKeypairsRequestType;
1515
use App\Form\Type\Request\Item\CreateItemRequestType;
1616
use App\Form\Type\Request\Item\ItemsCollectionRequestType;
17+
use App\Form\Type\Request\Item\ItemsIdCollectionRequestType;
1718
use App\Limiter\Inspector\ItemCountInspector;
1819
use App\Limiter\LimiterInterface;
1920
use App\Limiter\Model\LimitCheck;
@@ -27,6 +28,7 @@
2728
use App\Request\Item\CreateBatchKeypairsRequest;
2829
use App\Request\Item\CreateItemRequest;
2930
use App\Request\Item\ItemsCollectionRequest;
31+
use App\Request\Item\ItemsIdCollectionRequest;
3032
use App\Security\Voter\ItemVoter;
3133
use App\Security\Voter\TeamItemVoter;
3234
use Fourxxi\RestRequestError\Exception\FormInvalidRequestException;
@@ -87,6 +89,40 @@ public function items(Request $request, ItemRepository $repository, BatchItemVie
8789
);
8890
}
8991

92+
/**
93+
* Get all items information.
94+
*
95+
* @SWG\Tag(name="Item")
96+
* @SWG\Parameter(
97+
* name="body",
98+
* in="body",
99+
* @Model(type=ItemsIdCollectionRequestType::class)
100+
* )
101+
* @SWG\Response(
102+
* response=200,
103+
* description="Success item created",
104+
* @SWG\Schema(type="array", @SWG\Items(type="string"))
105+
* )
106+
*
107+
* @Route(
108+
* path="/unexists",
109+
* name="api_items_unexists",
110+
* methods={"POST"}
111+
* )
112+
*/
113+
public function unexists(Request $request, ItemRepository $repository): array
114+
{
115+
$collectionRequest = new ItemsIdCollectionRequest();
116+
117+
$form = $this->createForm(ItemsIdCollectionRequestType::class, $collectionRequest);
118+
$form->submit($request->request->all());
119+
if (!$form->isValid()) {
120+
throw new FormInvalidRequestException($form);
121+
}
122+
123+
return $repository->getDiffItems($collectionRequest->getItems());
124+
}
125+
90126
/**
91127
* Get single raws item.
92128
*

src/Entity/Embedded/ItemMeta.php

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,52 @@ class ItemMeta
1414
/**
1515
* @ORM\Column(type="integer", options={"default"=0})
1616
*/
17-
private int $attachCount;
17+
private int $attachmentsCount;
1818

1919
/**
2020
* @ORM\Column(nullable=true)
2121
*/
22-
private ?string $webSite;
22+
private ?string $website;
2323

24-
public function __construct(int $attachCount = 0, ?string $webSite = null)
24+
/**
25+
* @ORM\Column(nullable=true)
26+
*/
27+
private ?string $title;
28+
29+
public function __construct(int $attachmentsCount = 0, ?string $website = null, ?string $title = null)
30+
{
31+
$this->attachmentsCount = $attachmentsCount;
32+
$this->website = $website;
33+
$this->title = $title;
34+
}
35+
36+
public function getAttachmentsCount(): int
37+
{
38+
return $this->attachmentsCount;
39+
}
40+
41+
public function setAttachmentsCount(int $attachmentsCount): void
2542
{
26-
$this->attachCount = $attachCount;
27-
$this->webSite = $webSite;
43+
$this->attachmentsCount = $attachmentsCount;
2844
}
2945

30-
public function getAttachCount(): int
46+
public function getWebsite(): ?string
3147
{
32-
return $this->attachCount;
48+
return $this->website;
3349
}
3450

35-
public function setAttachCount(int $attachCount): void
51+
public function setWebsite(?string $website): void
3652
{
37-
$this->attachCount = $attachCount;
53+
$this->website = $website;
3854
}
3955

40-
public function getWebSite(): ?string
56+
public function getTitle(): ?string
4157
{
42-
return $this->webSite;
58+
return $this->title;
4359
}
4460

45-
public function setWebSite(?string $webSite): void
61+
public function setTitle(?string $title): void
4662
{
47-
$this->webSite = $webSite;
63+
$this->title = $title;
4864
}
4965
}

src/Entity/Item.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ class Item implements ChildItemAwareInterface
5151
*/
5252
protected $previousList;
5353

54-
/**
55-
* @var string|null
56-
*
57-
* @ORM\Column(type="text", nullable=true)
58-
*/
59-
protected $title;
60-
6154
/**
6255
* @var string|null
6356
*
@@ -581,16 +574,6 @@ public function moveTo(Directory $directory): void
581574
$this->setTeam($directory->getTeam());
582575
}
583576

584-
public function getTitle(): ?string
585-
{
586-
return $this->title;
587-
}
588-
589-
public function setTitle(?string $title): void
590-
{
591-
$this->title = $title;
592-
}
593-
594577
public function getTeamKeypairGroupKey(): string
595578
{
596579
$groups = [];

src/Factory/Entity/ItemFactory.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ public function createTeamKeypairFromRequest(CreateKeypairRequest $request): Ite
2525
{
2626
$item = new Item($request->getOwner() ?: $request->getUser());
2727
$item->setParentList($request->getTeam()->getDefaultDirectory());
28-
$item->setTitle(NodeEnumType::TYPE_KEYPAIR);
2928
$item->setType(NodeEnumType::TYPE_KEYPAIR);
3029
$item->setSecret($request->getSecret());
3130
$item->setRelatedItem($request->getRelatedItem());
3231
$item->setTeam($request->getTeam());
3332

33+
$meta = new ItemMeta();
34+
$meta->setTitle(NodeEnumType::TYPE_KEYPAIR);
35+
$item->setMeta($meta);
36+
3437
return $item;
3538
}
3639

@@ -45,13 +48,13 @@ public function createFromRequest(CreateItemRequest $request): Item
4548
$item->setParentList($parentList);
4649
$item->setType($request->getType());
4750
$item->setSecret($request->getSecret());
48-
$item->setTitle($request->getTitle());
4951
$item->setFavorite($request->isFavorite());
5052
$item->setTags(new ArrayCollection($this->transformer->transform($request->getTags())));
5153
$item->setTeam($request->getTeam());
5254
$item->setMeta(new ItemMeta(
53-
$request->getMeta()->getAttachCount() ?: 0,
54-
$request->getMeta()->getWebSite()
55+
$request->getMeta()->getAttachmentsCount() ?: 0,
56+
$request->getMeta()->getWebsite(),
57+
$request->getMeta()->getTitle()
5558
));
5659
$item->setRaws($request->getRaws());
5760

src/Factory/Entity/MemberFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Factory\Entity;
66

77
use App\DBAL\Types\Enum\NodeEnumType;
8+
use App\Entity\Embedded\ItemMeta;
89
use App\Model\DTO\Member;
910
use App\Request\Team\CreateMemberRequest;
1011

@@ -33,10 +34,12 @@ public function createFromRequest(CreateMemberRequest $request): Member
3334
$keypair = $this->itemFactory->create();
3435
$keypair->setOwner($user);
3536
$keypair->setTeam($team);
36-
$keypair->setTitle(NodeEnumType::TYPE_KEYPAIR);
3737
$keypair->setType(NodeEnumType::TYPE_KEYPAIR);
3838
$keypair->setParentList($team->getDefaultDirectory());
3939
$keypair->setSecret($request->getSecret());
40+
$meta = new ItemMeta();
41+
$meta->setTitle(NodeEnumType::TYPE_KEYPAIR);
42+
$keypair->setMeta($meta);
4043

4144
return new Member($userTeam, $keypair);
4245
}

src/Factory/Entity/ShareFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Factory\Entity;
66

77
use App\DBAL\Types\Enum\NodeEnumType;
8+
use App\Entity\Embedded\ItemMeta;
89
use App\Model\DTO\Share;
910
use App\Request\Item\ShareBatchItemRequest;
1011

@@ -33,11 +34,13 @@ public function createFromRequest(ShareBatchItemRequest $request): array
3334

3435
$item = $this->itemFactory->create();
3536
$item->setOwner($user);
36-
$item->setTitle(NodeEnumType::TYPE_KEYPAIR);
3737
$item->setType(NodeEnumType::TYPE_KEYPAIR);
3838
$item->setParentList($user->getInbox());
3939
$item->setSecret($userRequest->getSecret());
4040
$item->setRelatedItem($relatedItem);
41+
$meta = new ItemMeta();
42+
$meta->setTitle(NodeEnumType::TYPE_KEYPAIR);
43+
$item->setMeta($meta);
4144

4245
$result[$user->getId()->toString()] = new Share($user, $item);
4346
}

src/Factory/Entity/VaultFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Factory\Entity;
66

77
use App\DBAL\Types\Enum\NodeEnumType;
8+
use App\Entity\Embedded\ItemMeta;
89
use App\Entity\UserTeam;
910
use App\Model\DTO\Vault;
1011
use App\Request\Team\CreateVaultRequest;
@@ -43,10 +44,12 @@ public function createFromRequest(CreateVaultRequest $request): Vault
4344
$item = $this->itemFactory->create();
4445
$item->setOwner($user);
4546
$item->setTeam($team);
46-
$item->setTitle(NodeEnumType::TYPE_KEYPAIR);
4747
$item->setType(NodeEnumType::TYPE_KEYPAIR);
4848
$item->setParentList($team->getDefaultDirectory());
4949
$item->setSecret($keypairRequest->getSecret());
50+
$meta = new ItemMeta();
51+
$meta->setTitle(NodeEnumType::TYPE_KEYPAIR);
52+
$item->setMeta($meta);
5053

5154
return new Vault($team, $item);
5255
}

src/Factory/View/Item/ItemMetaViewFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ class ItemMetaViewFactory
1212
public function createSingle(ItemMeta $meta): ItemMetaView
1313
{
1414
$view = new ItemMetaView();
15-
$view->setAttachCount($meta->getAttachCount());
16-
$view->setWebSite($meta->getWebSite());
15+
$view->setAttachmentsCount($meta->getAttachmentsCount());
16+
$view->setWebsite($meta->getWebsite());
17+
$view->setTitle($meta->getTitle());
1718

1819
return $view;
1920
}

src/Factory/View/Item/ItemViewFactory.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public function createSingle(Item $item): ItemView
4141
$view->setListId($item->getParentList()->getId()->toString());
4242
$view->setPreviousListId($item->getPreviousListId());
4343
$view->setSecret($item->getSecret());
44-
$view->setTitle($item->getTitle());
45-
4644
$view->setInvited($this->inviteItemViewFactory->createCollection($item->getKeyPairItemsWithoutRoot()));
4745
$view->setOwnerId($item->getOwner()->getId()->toString());
4846
if (null === $item->getTeam()) {

src/Form/Type/Request/Item/CreateItemRequestType.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
4242
NodeEnumType::TYPE_SYSTEM,
4343
],
4444
])
45-
->add('title', TextType::class)
4645
->add('secret', TextType::class)
4746
->add('raws', TextType::class)
4847
->add('meta', ItemMetaType::class)

0 commit comments

Comments
 (0)