Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit fc52e82

Browse files
committed
feat(Me): support me/shopping-lists endpoint
1 parent 7ac97a1 commit fc52e82

File tree

10 files changed

+499
-0
lines changed

10 files changed

+499
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
*/
4+
5+
namespace Commercetools\Core\Builder\Request;
6+
7+
use Commercetools\Core\Model\ShoppingList\MyShoppingListDraft;
8+
use Commercetools\Core\Model\ShoppingList\ShoppingList;
9+
use Commercetools\Core\Request\Me\MeShoppingListByIdGetRequest;
10+
use Commercetools\Core\Request\Me\MeShoppingListCreateRequest;
11+
use Commercetools\Core\Request\Me\MeShoppingListDeleteRequest;
12+
use Commercetools\Core\Request\Me\MeShoppingListQueryRequest;
13+
use Commercetools\Core\Request\Me\MeShoppingListUpdateRequest;
14+
15+
class MeShoppingListRequestBuilder
16+
{
17+
18+
/**
19+
* @return MeShoppingListQueryRequest
20+
*/
21+
public function query()
22+
{
23+
return MeShoppingListQueryRequest::of();
24+
}
25+
26+
/**
27+
* @param ShoppingList $shoppingList
28+
* @return MeShoppingListUpdateRequest
29+
*/
30+
public function update(ShoppingList $shoppingList)
31+
{
32+
return MeShoppingListUpdateRequest::ofIdAndVersion($shoppingList->getId(), $shoppingList->getVersion());
33+
}
34+
35+
/**
36+
* @param string $shoppingListId
37+
* @return MeShoppingListByIdGetRequest
38+
*/
39+
public function getById($shoppingListId)
40+
{
41+
return MeShoppingListByIdGetRequest::ofId($shoppingListId);
42+
}
43+
44+
/**
45+
* @param MyShoppingListDraft $myShoppingListDraft
46+
* @return MeShoppingListCreateRequest
47+
*/
48+
public function create(MyShoppingListDraft $myShoppingListDraft)
49+
{
50+
return MeShoppingListCreateRequest::ofDraft($myShoppingListDraft);
51+
}
52+
53+
/**
54+
* @param ShoppingList $shoppingList
55+
* @return MeShoppingListDeleteRequest
56+
*/
57+
public function delete(ShoppingList $shoppingList)
58+
{
59+
return MeShoppingListDeleteRequest::ofIdAndVersion($shoppingList->getId(), $shoppingList->getVersion());
60+
}
61+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
*/
4+
5+
namespace Commercetools\Core\Model\ShoppingList;
6+
7+
use Commercetools\Core\Model\Common\Context;
8+
use Commercetools\Core\Model\Common\Resource;
9+
use Commercetools\Core\Model\Common\LocalizedString;
10+
use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft;
11+
12+
/**
13+
* @package Commercetools\Core\Model\ShoppingList
14+
* @link https://docs.commercetools.com/http-api-projects-me-shoppingLists#myshoppinglistdraft
15+
* @method LocalizedString getName()
16+
* @method MyShoppingListDraft setName(LocalizedString $name = null)
17+
* @method LocalizedString getDescription()
18+
* @method MyShoppingListDraft setDescription(LocalizedString $description = null)
19+
* @method LineItemDraftCollection getLineItems()
20+
* @method MyShoppingListDraft setLineItems(LineItemDraftCollection $lineItems = null)
21+
* @method TextLineItemDraftCollection getTextLineItems()
22+
* @method MyShoppingListDraft setTextLineItems(TextLineItemDraftCollection $textLineItems = null)
23+
* @method CustomFieldObjectDraft getCustom()
24+
* @method MyShoppingListDraft setCustom(CustomFieldObjectDraft $custom = null)
25+
* @method int getDeleteDaysAfterLastModification()
26+
* @method MyShoppingListDraft setDeleteDaysAfterLastModification(int $deleteDaysAfterLastModification = null)
27+
*/
28+
class MyShoppingListDraft extends Resource
29+
{
30+
public function fieldDefinitions()
31+
{
32+
return [
33+
'name' => [static::TYPE => LocalizedString::class],
34+
'description' => [static::TYPE => LocalizedString::class],
35+
'lineItems' => [static::TYPE => LineItemDraftCollection::class],
36+
'textLineItems' => [static::TYPE => TextLineItemDraftCollection::class],
37+
'custom' => [static::TYPE => CustomFieldObjectDraft::class],
38+
'deleteDaysAfterLastModification' => [static::TYPE => 'int'],
39+
];
40+
}
41+
42+
/**
43+
* @param LocalizedString $name
44+
* @param Context|null $context
45+
* @return MyShoppingListDraft
46+
*/
47+
public static function ofName(LocalizedString $name, $context = null)
48+
{
49+
return static::of($context)->setName($name);
50+
}
51+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
*/
4+
5+
namespace Commercetools\Core\Request\Me;
6+
7+
use Commercetools\Core\Model\Common\Context;
8+
use Commercetools\Core\Request\AbstractByIdGetRequest;
9+
use Commercetools\Core\Model\ShoppingList\ShoppingList;
10+
use Commercetools\Core\Response\ApiResponseInterface;
11+
use Commercetools\Core\Model\MapperInterface;
12+
13+
/**
14+
* @package Commercetools\Core\Request\Me
15+
* @link https://docs.commercetools.com/http-api-projects-me-shoppingLists#get-shoppinglist-by-id
16+
* @method ShoppingList mapResponse(ApiResponseInterface $response)
17+
* @method ShoppingList mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null)
18+
*/
19+
class MeShoppingListByIdGetRequest extends AbstractByIdGetRequest
20+
{
21+
protected $resultClass = ShoppingList::class;
22+
23+
/**
24+
* @param string $id
25+
* @param Context $context
26+
*/
27+
public function __construct($id, Context $context = null)
28+
{
29+
parent::__construct(MeShoppingListsEndpoint::endpoint(), $id, $context);
30+
}
31+
32+
/**
33+
* @param string $id
34+
* @param Context $context
35+
* @return static
36+
*/
37+
public static function ofId($id, Context $context = null)
38+
{
39+
return new static($id, $context);
40+
}
41+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
*/
4+
5+
namespace Commercetools\Core\Request\Me;
6+
7+
use Commercetools\Core\Model\Common\Context;
8+
use Commercetools\Core\Model\ShoppingList\MyShoppingListDraft;
9+
use Commercetools\Core\Request\AbstractCreateRequest;
10+
use Commercetools\Core\Model\ShoppingList\ShoppingList;
11+
use Commercetools\Core\Response\ApiResponseInterface;
12+
use Commercetools\Core\Model\MapperInterface;
13+
14+
/**
15+
* @package Commercetools\Core\Request\Me
16+
* @link https://docs.commercetools.com/http-api-projects-me-shoppingLists#create-a-shoppinglist
17+
* @method ShoppingList mapResponse(ApiResponseInterface $response)
18+
* @method ShoppingList mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null)
19+
*/
20+
class MeShoppingListCreateRequest extends AbstractCreateRequest
21+
{
22+
protected $resultClass = ShoppingList::class;
23+
24+
/**
25+
* @param MyShoppingListDraft $ShoppingList
26+
* @param Context $context
27+
*/
28+
public function __construct(MyShoppingListDraft $ShoppingList, Context $context = null)
29+
{
30+
parent::__construct(MeShoppingListsEndpoint::endpoint(), $ShoppingList, $context);
31+
}
32+
33+
/**
34+
* @param MyShoppingListDraft $ShoppingList
35+
* @param Context $context
36+
* @return static
37+
*/
38+
public static function ofDraft(MyShoppingListDraft $ShoppingList, Context $context = null)
39+
{
40+
return new static($ShoppingList, $context);
41+
}
42+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
*/
4+
5+
namespace Commercetools\Core\Request\Me;
6+
7+
use Commercetools\Core\Model\Common\Context;
8+
use Commercetools\Core\Request\AbstractDeleteRequest;
9+
use Commercetools\Core\Model\ShoppingList\ShoppingList;
10+
use Commercetools\Core\Response\ApiResponseInterface;
11+
use Commercetools\Core\Model\MapperInterface;
12+
13+
/**
14+
* @package Commercetools\Core\Request\Me
15+
* @link https://docs.commercetools.com/http-api-projects-me-shoppingLists#delete-shoppinglist
16+
* @method ShoppingList mapResponse(ApiResponseInterface $response)
17+
* @method ShoppingList mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null)
18+
*/
19+
class MeShoppingListDeleteRequest extends AbstractDeleteRequest
20+
{
21+
protected $resultClass = ShoppingList::class;
22+
23+
/**
24+
* @param string $id
25+
* @param int $version
26+
* @param Context $context
27+
*/
28+
public function __construct($id, $version, Context $context = null)
29+
{
30+
parent::__construct(MeShoppingListsEndpoint::endpoint(), $id, $version, $context);
31+
}
32+
33+
/**
34+
* @param string $id
35+
* @param int $version
36+
* @param Context $context
37+
* @return static
38+
*/
39+
public static function ofIdAndVersion($id, $version, Context $context = null)
40+
{
41+
return new static($id, $version, $context);
42+
}
43+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
*/
4+
5+
namespace Commercetools\Core\Request\Me;
6+
7+
use Commercetools\Core\Model\Common\Context;
8+
use Commercetools\Core\Request\AbstractQueryRequest;
9+
use Commercetools\Core\Model\ShoppingList\ShoppingListCollection;
10+
use Commercetools\Core\Response\ApiResponseInterface;
11+
use Commercetools\Core\Model\MapperInterface;
12+
13+
/**
14+
* @package Commercetools\Core\Request\Me
15+
* @link https://docs.commercetools.com/http-api-projects-me-shoppingLists#query-shoppinglists
16+
* @method ShoppingListCollection mapResponse(ApiResponseInterface $response)
17+
* @method ShoppingListCollection mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null)
18+
*/
19+
class MeShoppingListQueryRequest extends AbstractQueryRequest
20+
{
21+
protected $resultClass = ShoppingListCollection::class;
22+
23+
/**
24+
* @param Context $context
25+
*/
26+
public function __construct(Context $context = null)
27+
{
28+
parent::__construct(MeShoppingListsEndpoint::endpoint(), $context);
29+
}
30+
31+
/**
32+
* @param Context $context
33+
* @return static
34+
*/
35+
public static function of(Context $context = null)
36+
{
37+
return new static($context);
38+
}
39+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
*/
4+
5+
namespace Commercetools\Core\Request\Me;
6+
7+
use Commercetools\Core\Model\Common\Context;
8+
use Commercetools\Core\Request\AbstractUpdateRequest;
9+
use Commercetools\Core\Model\ShoppingList\ShoppingList;
10+
use Commercetools\Core\Response\ApiResponseInterface;
11+
use Commercetools\Core\Model\MapperInterface;
12+
13+
/**
14+
* @package Commercetools\Core\Request\Me
15+
* @link https://docs.commercetools.com/http-api-projects-me-shoppingLists#update-shoppinglist
16+
* @method ShoppingList mapResponse(ApiResponseInterface $response)
17+
* @method ShoppingList mapFromResponse(ApiResponseInterface $response, MapperInterface $mapper = null)
18+
*/
19+
class MeShoppingListUpdateRequest extends AbstractUpdateRequest
20+
{
21+
protected $resultClass = ShoppingList::class;
22+
23+
/**
24+
* @param string $id
25+
* @param int $version
26+
* @param array $actions
27+
* @param Context $context
28+
*/
29+
public function __construct($id, $version, array $actions = [], Context $context = null)
30+
{
31+
parent::__construct(MeShoppingListsEndpoint::endpoint(), $id, $version, $actions, $context);
32+
}
33+
34+
/**
35+
* @param string $id
36+
* @param int $version
37+
* @param Context $context
38+
* @return static
39+
*/
40+
public static function ofIdAndVersion($id, $version, Context $context = null)
41+
{
42+
return new static($id, $version, [], $context);
43+
}
44+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
*/
4+
5+
namespace Commercetools\Core\Request\Me;
6+
7+
use Commercetools\Core\Client\JsonEndpoint;
8+
9+
/**
10+
* @package Commercetools\Core\Request\Me
11+
*/
12+
class MeShoppingListsEndpoint
13+
{
14+
/**
15+
* @return JsonEndpoint
16+
*/
17+
public static function endpoint()
18+
{
19+
return new JsonEndpoint('me/shopping-lists');
20+
}
21+
}

0 commit comments

Comments
 (0)