Skip to content

Commit 6928c51

Browse files
authored
Merge pull request #544 from caesar-team/develop
Fix v2.0.2
2 parents 40e4f3c + aa7b86f commit 6928c51

15 files changed

Lines changed: 187 additions & 0 deletions

File tree

src/Controller/Api/Item/ItemController.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Entity\Item;
99
use App\Factory\Entity\ItemFactory;
1010
use App\Factory\View\Item\BatchItemViewFactory;
11+
use App\Factory\View\Item\ItemRawsViewFactory;
1112
use App\Factory\View\Item\ItemViewFactory;
1213
use App\Form\Type\Request\Item\CreateBatchItemsRequestType;
1314
use App\Form\Type\Request\Item\CreateBatchKeypairsRequestType;
@@ -19,6 +20,7 @@
1920
use App\Model\DTO\GroupedUserItems;
2021
use App\Model\Query\ItemsAllQuery;
2122
use App\Model\View\Item\BatchItemsView;
23+
use App\Model\View\Item\ItemRawsView;
2224
use App\Model\View\Item\ItemView;
2325
use App\Repository\ItemRepository;
2426
use App\Request\Item\CreateBatchItemsRequest;
@@ -85,6 +87,32 @@ public function items(Request $request, ItemRepository $repository, BatchItemVie
8587
);
8688
}
8789

90+
/**
91+
* Get single raws item.
92+
*
93+
* @SWG\Tag(name="Item")
94+
* @SWG\Response(
95+
* response=200,
96+
* description="Item data",
97+
* @Model(type=ItemRawsView::class)
98+
* )
99+
*
100+
* @SWG\Response(
101+
* response=404,
102+
* description="No such item"
103+
* )
104+
*
105+
* @Route(
106+
* path="/{id}/raws",
107+
* name="api_show_item_raws",
108+
* methods={"GET"}
109+
* )
110+
*/
111+
public function raws(Item $item, ItemRawsViewFactory $factory): ItemRawsView
112+
{
113+
return $factory->createSingle($item);
114+
}
115+
88116
/**
89117
* Get batch items information.
90118
*

src/Entity/Item.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ class Item implements ChildItemAwareInterface
7272
*/
7373
protected $meta;
7474

75+
/**
76+
* @var string|null
77+
*
78+
* @ORM\Column(type="text", nullable=true)
79+
*/
80+
protected $raws;
81+
7582
/**
7683
* @var string
7784
*
@@ -239,6 +246,16 @@ public function setMeta(ItemMeta $meta): void
239246
$this->meta = $meta;
240247
}
241248

249+
public function setRaws(?string $raws): void
250+
{
251+
$this->raws = $raws;
252+
}
253+
254+
public function getRaws(): ?string
255+
{
256+
return $this->raws;
257+
}
258+
242259
public function getLastUpdated(): DateTime
243260
{
244261
return $this->lastUpdated;

src/Factory/Entity/ItemFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function createFromRequest(CreateItemRequest $request): Item
5353
$request->getMeta()->getAttachCount() ?: 0,
5454
$request->getMeta()->getWebSite()
5555
));
56+
$item->setRaws($request->getRaws());
5657

5758
return $item;
5859
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Factory\View\Item;
6+
7+
use App\Entity\Item;
8+
use App\Model\View\Item\ItemRawsView;
9+
10+
class ItemRawsViewFactory
11+
{
12+
public function createSingle(Item $item): ItemRawsView
13+
{
14+
$view = new ItemRawsView();
15+
$view->setId($item->getId()->toString());
16+
$view->setRaws($item->getRaws());
17+
18+
return $view;
19+
}
20+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
4444
])
4545
->add('title', TextType::class)
4646
->add('secret', TextType::class)
47+
->add('raws', TextType::class)
4748
->add('meta', ItemMetaType::class)
4849
->add('favorite', CheckboxType::class)
4950
->add('tags', CollectionType::class, [

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2626
])
2727
->add('title', TextType::class)
2828
->add('secret', TextType::class)
29+
->add('raws', TextType::class)
2930
->add('meta', ItemMetaType::class)
3031
->add('tags', CollectionType::class, [
3132
'entry_type' => TextType::class,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
final class Version20201118094040 extends AbstractMigration
11+
{
12+
public function up(Schema $schema): void
13+
{
14+
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
15+
16+
$this->addSql('ALTER TABLE item ADD raws TEXT DEFAULT NULL');
17+
}
18+
19+
public function down(Schema $schema): void
20+
{
21+
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
22+
23+
$this->addSql('ALTER TABLE item DROP raws');
24+
}
25+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Model\View\Item;
6+
7+
use Swagger\Annotations as SWG;
8+
9+
final class ItemRawsView
10+
{
11+
/**
12+
* @SWG\Property(type="string", example="4fcc6aef-3fd6-4c16-9e4b-5c37486c7d46")
13+
*/
14+
private string $id;
15+
16+
/**
17+
* @SWG\Property(type="string")
18+
*/
19+
private ?string $raws;
20+
21+
public function getId(): string
22+
{
23+
return $this->id;
24+
}
25+
26+
public function setId(string $id): void
27+
{
28+
$this->id = $id;
29+
}
30+
31+
public function getRaws(): ?string
32+
{
33+
return $this->raws;
34+
}
35+
36+
public function setRaws(?string $raws): void
37+
{
38+
$this->raws = $raws;
39+
}
40+
}

src/Modifier/ItemModifier.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function modifyByRequest(EditItemRequest $request): Item
3434
$request->getMeta()->getAttachCount() ?: 0,
3535
$request->getMeta()->getWebSite()
3636
));
37+
$item->setRaws($request->getRaws());
3738
$item->setTitle($request->getTitle());
3839
$item->setTags(new ArrayCollection($this->transformer->transform($request->getTags())));
3940
$this->repository->save($item);

src/Request/Item/CreateItemRequest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ final class CreateItemRequest
3535
*/
3636
private ?string $secret;
3737

38+
private ?string $raws;
39+
3840
private bool $favorite;
3941

4042
private array $tags;
@@ -50,6 +52,7 @@ public function __construct(User $user)
5052
$this->secret = null;
5153
$this->favorite = false;
5254
$this->meta = new ItemMetaRequest();
55+
$this->raws = null;
5356
$this->tags = [];
5457
}
5558

@@ -142,4 +145,14 @@ public function setMeta(ItemMetaRequest $meta): void
142145
{
143146
$this->meta = $meta;
144147
}
148+
149+
public function getRaws(): ?string
150+
{
151+
return $this->raws;
152+
}
153+
154+
public function setRaws(?string $raws): void
155+
{
156+
$this->raws = $raws;
157+
}
145158
}

0 commit comments

Comments
 (0)