Skip to content

Commit

Permalink
Making the wishlist timestampable
Browse files Browse the repository at this point in the history
Adding `createdAt` and `updatedAt` fields to track if the wishlist is old and can be deleted.
  • Loading branch information
mamazu committed Oct 15, 2023
1 parent c34dd8b commit 69957bd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Entity/Wishlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\Component\Resource\Model\TimestampableTrait;

class Wishlist implements WishlistInterface
{
use TimestampableTrait;

protected ?int $id = null;

protected ?string $name;
Expand All @@ -38,6 +41,8 @@ public function __construct()
$this->wishlistProducts = new ArrayCollection();
$this->token = new WishlistToken();
$this->id = null;

$this->createdAt = new \DateTime();
}

public function getId(): ?int
Expand Down
8 changes: 8 additions & 0 deletions src/Resources/config/doctrine/Wishlist.orm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
Expand Down Expand Up @@ -30,6 +31,13 @@
<join-column name="channel_id" on-delete="CASCADE" />
</many-to-one>

<field name="createdAt" column="created_at" type="datetime">
<gedmo:timestampable on="create"/>
</field>
<field name="updatedAt" column="updated_at" type="datetime" nullable="true">
<gedmo:timestampable on="update"/>
</field>

<indexes>
<index name="token_idx" columns="token"/>
<index name="channel_shop_user_token_idx" columns="channel_id,shop_user_id,token"/>
Expand Down
3 changes: 2 additions & 1 deletion tests/Behat/Context/Api/WishlistContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public function userIsAuthenticated(string $email, string $password): void
'body' => json_encode($body),
]
);
Assert::eq($response->getStatusCode(), 200);

$json = json_decode((string) $response->getBody());

Expand Down Expand Up @@ -127,7 +126,9 @@ public function userHasAWishlist(): void
$this->getOptions(self::POST, [])
);

Assert::eq($response->getStatusCode(), 201);
$jsonBody = json_decode((string) $response->getBody());
var_dump($jsonBody);

/** @var WishlistInterface $wishlist */
$wishlist = $this->wishlistRepository->find((int) $jsonBody->id);
Expand Down

0 comments on commit 69957bd

Please sign in to comment.