Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ The API for TastyIgniter comes packed with a range of features to enhance your e

Documentation can be found on the [TastyIgniter documentation website](https://tastyigniter.com/docs/extensions/api).

## Changelog

Please see [CHANGELOG](https://github.com/tastyigniter/ti-ext-api/blob/master/CHANGELOG.md) for more information on what has changed recently.

## Reporting issues

If you encounter a bug in this extension, please report it using the [Issue Tracker](https://github.com/tastyigniter/ti-ext-api/issues) on GitHub.
If you encounter a bug in this extension, please report it using the [Issue Tracker](https://github.com/tastyigniter/TastyIgniter/issues) on GitHub.

## Contributing

Expand Down
221 changes: 221 additions & 0 deletions docs/addresses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
## Addresses

This endpoint lets you `list`, `create`, `retrieve`, `update` and `delete` customer addresses on your TastyIgniter site.

Responses follow the [JSON:API specification](https://jsonapi.org).

### The address object

#### Attributes

| Key | Type | Description |
|--------------|----------|-----------------------------------------------------------------------------|
| `address_1` | `string` | **Required**. First line of the address (between 3 and 128 characters). |
| `address_2` | `string` | Second line of the address (between 1 and 128 characters). |
| `city` | `string` | **Required**. City or town (between 2 and 128 characters). |
| `state` | `string` | State or county (max 128 characters). |
| `postcode` | `string` | Postcode or ZIP code (max 128 characters). |
| `country_id` | `integer`| **Required**. Country ID from the countries table. |
| `customer_id`| `integer`| The customer this address belongs to. Set automatically for customer tokens.|

#### The country relation

When you request `?include=country`, each address may include a `country` relation with attributes such as `country_name`, `iso_code_2`, `iso_code_3`, `format`, `status`, `priority`.

### List addresses

Retrieves a list of addresses. Customers see only their own addresses; staff see all according to token abilities.

Required abilities: `addresses:read`

```
GET /api/addresses
```

#### Parameters

| Key | Type | Description |
|-------------|-----------|-----------------------------------------------------------------------------|
| `page` | `integer` | Page number. |
| `pageLimit` | `integer` | Number of items per page. |
| `include` | `string` | Relations to include. Options: `country`. Example: `?include=country` |

#### Response

```html
Status: 200 OK
```

```json
{
"data": [
{
"type": "addresses",
"id": "1",
"attributes": {
"address_1": "1 Some Road",
"address_2": null,
"city": "London",
"state": "",
"postcode": "W1A 3NN",
"country_id": 222,
"customer_id": 1
}
}
],
"meta": {
"pagination": {
"total": 1,
"count": 1,
"per_page": 20,
"current_page": 1,
"total_pages": 1
}
},
"links": {
"self": "https://your.url/api/addresses?page=1",
"first": "https://your.url/api/addresses?page=1",
"last": "https://your.url/api/addresses?page=1"
}
}
```

### Create an address

Creates a new address. For customer tokens, `customer_id` is set automatically.

Required abilities: `addresses:write`

```
POST /api/addresses
```

#### Parameters

| Key | Type | Description |
|--------------|----------|------------------------------------------------------------|
| `address_1` | `string` | **Required**. First line (3–128 characters). |
| `address_2` | `string` | Second line (optional). |
| `city` | `string` | **Required**. City (2–128 characters). |
| `state` | `string` | State or county (optional). |
| `postcode` | `string` | Postcode or ZIP (optional). |
| `country_id` | `integer`| **Required**. Country ID. |
| `customer_id`| `integer` | Customer ID (admin only; ignored for customer tokens). |

#### Payload example

```json
{
"address_1": "1 Some Road",
"address_2": "Flat 2",
"city": "London",
"state": "",
"postcode": "W1A 3NN",
"country_id": 222
}
```

#### Response

```html
Status: 201 Created
```

```json
{
"data": {
"type": "addresses",
"id": "1",
"attributes": {
"address_1": "1 Some Road",
"address_2": "Flat 2",
"city": "London",
"state": "",
"postcode": "W1A 3NN",
"country_id": 222,
"customer_id": 1
}
}
}
```

### Retrieve an address

Fetches a single address by ID.

Required abilities: `addresses:read`

```
GET /api/addresses/:id
```

#### Parameters

| Key | Type | Description |
|-----------|----------|----------------------------------------------------------------|
| `include` | `string` | Relations to include. Options: `country`. Example: `?include=country` |

#### Response

```html
Status: 200 OK
```

```json
{
"data": {
"type": "addresses",
"id": "1",
"attributes": {
"address_1": "1 Some Road",
"address_2": null,
"city": "London",
"state": "",
"postcode": "W1A 3NN",
"country_id": 222,
"customer_id": 1
}
}
}
```

### Update an address

Updates an existing address.

Required abilities: `addresses:write`

```
PUT /api/addresses/:id
PATCH /api/addresses/:id
```

#### Parameters

Same as create; all fields are optional when updating.

#### Response

```html
Status: 200 OK
```

Returns the updated address object in the same shape as the retrieve response.

### Delete an address

Permanently deletes an address.

Required abilities: `addresses:write`

```
DELETE /api/addresses/:id
```

#### Response

```html
Status: 204 No Content
```

No response body.
35 changes: 35 additions & 0 deletions docs/orders.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,41 @@ Status: 200 OK
}
```

### Update order status

Updates only the order status. Use this when you only need to change the status (e.g. from pending to completed) without sending other order fields.

Required abilities: `orders:write`

```
PATCH /api/orders/:order_id/status
```

#### Parameters

| Key | Type | Description |
|-------------------|----------|-----------------------------------------------------------------------------|
| `status_id` | `integer`| **Required**. The Unique Identifier of the status to assign to the order. |
| `comment` | `string` | Optional comment to attach to the status change (max 500 characters). |
| `notify` | `boolean`| Optional. Whether to notify the customer of the status change (default: false). |

#### Payload example

```json
{
"status_id": 4,
"status_comment": "Order ready for collection"
}
```

#### Response

```html
Status: 200 OK
```

Returns the updated order object in the same shape as the retrieve/update response (including the new `status_id` and `status_updated_at`).

### Delete an order

Permanently deletes an order. It cannot be undone.
Expand Down
37 changes: 36 additions & 1 deletion docs/reservations.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ PATCH /api/reservations/:reservation_id
| `email` | `string` | The reservation's email address |
| `telephone` | `string` | The reservation's telephone number |
| `newsletter` | `boolean` | Whether the reservation opts into newsletter marketing |
| `reservation_group_id` | `integer` | The group the reservation belongs to, if any. |
| `status` | `boolean` | Has the value `true` if the reservation is enabled or the value `false` if the reservation is disabled. |
| `addresses` | `array` | The reservation's addresses, if any |

Expand Down Expand Up @@ -418,6 +417,42 @@ Status: 200 OK
}
```

### Update reservation status

Updates only the reservation status. Use this when you only need to change the status (e.g. from pending to confirmed) without sending other reservation fields. Only staff tokens may update reservation status; customer tokens receive 403.

Required abilities: `reservations:write`

```
PATCH /api/reservations/:reservation_id/status
```

#### Parameters

| Key | Type | Description |
|--------------|----------|-----------------------------------------------------------------------------|
| `status_id` | `integer`| **Required**. The Unique Identifier of the status to assign (must exist in `statuses`). |
| `comment` | `string` | Optional comment to attach to the status change (max 500 characters). |
| `notify` | `boolean`| Whether to notify the customer of the status change. |

#### Payload example

```json
{
"status_id": 8,
"comment": "Table confirmed",
"notify": true
}
```

#### Response

```html
Status: 200 OK
```

Returns the updated reservation object in the same shape as the retrieve/update response (including the new `status_id` and `status_updated_at`).

### Delete a reservation

Permanently deletes a reservation. It cannot be undone.
Expand Down
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
parameters:
ignoreErrors:
-
message: '#^Access to an undefined property Igniter\\User\\Models\\Address\:\:\$country\.$#'
identifier: property.notFound
count: 1
path: src/ApiResources/Transformers/AddressTransformer.php

-
message: '#^Access to an undefined property Igniter\\Cart\\Models\\Category\:\:\$locations\.$#'
identifier: property.notFound
Expand Down
4 changes: 4 additions & 0 deletions resources/lang/en/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@
'orders' => [
'label_customer_id' => 'Customer ID',
],

'addresses' => [
'label_customer_id' => 'Customer ID',
],
];
37 changes: 37 additions & 0 deletions src/ApiResources/Addresses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Igniter\Api\ApiResources;

use Igniter\Api\ApiResources\Repositories\AddressRepository;
use Igniter\Api\ApiResources\Requests\AddressRequest;
use Igniter\Api\ApiResources\Transformers\AddressTransformer;
use Igniter\Api\Classes\ApiController;
use Igniter\Api\Http\Actions\RestController;

/**
* Addresses API Controller
*/
class Addresses extends ApiController
{
public array $implement = [RestController::class];

public $restConfig = [
'actions' => [
'index' => [
'pageLimit' => 20,
],
'store' => [],
'show' => [],
'update' => [],
'destroy' => [],
],
'request' => AddressRequest::class,
'repository' => AddressRepository::class,
'transformer' => AddressTransformer::class,
'resourceKey' => 'addresses',
];

protected string|array $requiredAbilities = ['addresses:*'];
}
Loading
Loading