Skip to content

Commit

Permalink
Merge pull request #179 from deanblackborough/v2.11.0
Browse files Browse the repository at this point in the history
v2.10.2
  • Loading branch information
deanblackborough authored Apr 30, 2020
2 parents 06ce448 + 1b64806 commit 02371b5
Show file tree
Hide file tree
Showing 42 changed files with 1,064 additions and 701 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

The complete changelog for the Costs to Expect REST API, our changelog follows the format defined at https://keepachangelog.com/en/1.0.0/

## [v2.10.2] - 2020-04-30
### Changed
- We have updated all item endpoints to return `updated`; this is the date and time an item was updated, not its category assignments.
- We have updated item collection and show endpoints; we are going to allow the possibility of items not having categories and subcategories. When you add the `include-categories` and `include-subcategories` parameters to a request, we will not exclude items without category assignments.
- We have updated the API to the latest release of Laravel 7.
- We have updated the front end dependencies for the welcome page.
- We have updated the `item-types` route to show additional information on each tracking method.
- We have updated all decimal fields to 13,2 rather than 10,2.
- We have updated all description fields; we have switched all the description fields from varchar(255) to text.

### Fixed
- We have corrected a bad link on the landing page.
- We have corrected a typo on the landing page.
- We have switched the table we look at to return created at for an item; we should be using the sub table, not the base item table.
- We have corrected the `/resource-types/` OPTIONS request; `public` is not a required field.

## [v2.10.1] - 2020-04-03
### Changed
- We have tweaked our Docker setup to allow a local API and App/Website; the ports have been changed and a network has been created.
Expand Down
8 changes: 4 additions & 4 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class Handler extends ExceptionHandler
/**
* Report or log an exception.
*
* @param \Exception $exception
* @param \Throwable $exception
* @return void
*/
public function report(Exception $exception)
public function report(\Throwable $exception)
{
parent::report($exception);
}
Expand All @@ -46,10 +46,10 @@ public function report(Exception $exception)
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @param \Throwable $exception
* @return \Illuminate\Http\JsonResponse
*/
public function render($request, Exception $exception)
public function render($request, \Throwable $exception)
{
if ($exception instanceof AuthenticationException) {
Response::authenticationRequired();
Expand Down
67 changes: 35 additions & 32 deletions app/Models/Item/AllocatedExpense.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ public function single(
): ?array
{
$fields = [
'item.id AS item_id',
'item_type_allocated_expense.name AS item_name',
'item_type_allocated_expense.description AS item_description',
'item_type_allocated_expense.effective_date AS item_effective_date',
'item_type_allocated_expense.total AS item_total',
'item_type_allocated_expense.percentage AS item_percentage',
'item_type_allocated_expense.actualised_total AS item_actualised_total',
'item.created_at AS item_created_at'
"item.id AS item_id",
"{$this->table}.name AS item_name",
"{$this->table}.description AS item_description",
"{$this->table}.effective_date AS item_effective_date",
"{$this->table}.total AS item_total",
"{$this->table}.percentage AS item_percentage",
"{$this->table}.actualised_total AS item_actualised_total",
"{$this->table}.created_at AS item_created_at",
"{$this->table}.updated_at AS item_updated_at"
];

$result = $this->from('item')->
Expand All @@ -78,8 +79,8 @@ public function single(
array_key_exists('include-categories', $parameters) === true &&
General::booleanValue($parameters['include-categories']) === true
) {
$result->join('item_category', 'item.id', 'item_category.item_id')->
join('category', 'item_category.category_id', 'category.id');
$result->leftJoin('item_category', 'item.id', 'item_category.item_id')->
leftJoin('category', 'item_category.category_id', 'category.id');

$fields[] = 'item_category.id AS item_category_id';
$fields[] = 'category.id AS category_id';
Expand All @@ -90,8 +91,8 @@ public function single(
array_key_exists('include-subcategories', $parameters) === true &&
General::booleanValue($parameters['include-subcategories']) === true
) {
$result->join('item_sub_category', 'item_category.id', 'item_sub_category.item_category_id')->
join('sub_category', 'item_sub_category.sub_category_id', 'sub_category.id');
$result->leftJoin('item_sub_category', 'item_category.id', 'item_sub_category.item_category_id')->
leftJoin('sub_category', 'item_sub_category.sub_category_id', 'sub_category.id');

$fields[] = 'item_sub_category.id AS item_subcategory_id';
$fields[] = 'sub_category.id AS subcategory_id';
Expand All @@ -104,9 +105,9 @@ public function single(

if ($item !== null) {
return $item->toArray();
} else {
return null;
}

return null;
}

/**
Expand All @@ -125,11 +126,11 @@ public function maximumEffectiveDateYear(int $resource_id): int
first();

if ($result === null) {
return intval(date('Y'));
} else {
return intval($result->year_limit);
return (int) (date('Y'));
}

return (int) ($result->year_limit);

}

/**
Expand All @@ -148,10 +149,10 @@ public function minimumEffectiveDateYear(int $resource_id): int
first();

if ($result === null) {
return intval(date('Y'));
} else {
return intval($result->year_limit);
return (int) (date('Y'));
}

return (int) ($result->year_limit);
}

/**
Expand All @@ -173,7 +174,8 @@ public function instanceToArray(Model $item, Model $item_type): array
'item_total' => $item_type->total,
'item_percentage' => $item_type->percentage,
'item_actualised_total' => $item_type->actualised_total,
'item_created_at' => $item->created_at->toDateTimeString()
'item_created_at' => $item->created_at->toDateTimeString(),
'item_updated_at' => $item->updated_at->toDateTimeString()
];
}

Expand Down Expand Up @@ -285,13 +287,14 @@ public function paginatedCollection(
{
$select_fields = [
'item.id AS item_id',
'item_type_allocated_expense.name AS item_name',
'item_type_allocated_expense.description AS item_description',
'item_type_allocated_expense.effective_date AS item_effective_date',
'item_type_allocated_expense.total AS item_total',
'item_type_allocated_expense.percentage AS item_percentage',
'item_type_allocated_expense.actualised_total AS item_actualised_total',
'item.created_at AS item_created_at'
"{$this->table}.name AS item_name",
"{$this->table}.description AS item_description",
"{$this->table}.effective_date AS item_effective_date",
"{$this->table}.total AS item_total",
"{$this->table}.percentage AS item_percentage",
"{$this->table}.actualised_total AS item_actualised_total",
"{$this->table}.created_at AS item_created_at",
"{$this->table}.updated_at AS item_updated_at"
];

$category_join = false;
Expand All @@ -307,8 +310,8 @@ public function paginatedCollection(
array_key_exists('include-categories', $parameters) === true &&
General::booleanValue($parameters['include-categories']) === true
) {
$collection->join('item_category', 'item.id', 'item_category.item_id')->
join('category', 'item_category.category_id', 'category.id');
$collection->leftJoin('item_category', 'item.id', 'item_category.item_id')->
leftJoin('category', 'item_category.category_id', 'category.id');

$category_join = true;

Expand All @@ -326,8 +329,8 @@ public function paginatedCollection(
array_key_exists('include-subcategories', $parameters) === true &&
General::booleanValue($parameters['include-subcategories']) === true
) {
$collection->join('item_sub_category', 'item_category.id', 'item_sub_category.item_category_id')->
join('sub_category', 'item_sub_category.sub_category_id', 'sub_category.id');
$collection->leftJoin('item_sub_category', 'item_category.id', 'item_sub_category.item_category_id')->
leftJoin('sub_category', 'item_sub_category.sub_category_id', 'sub_category.id');

$subcategory_join = true;

Expand Down
31 changes: 17 additions & 14 deletions app/Models/Item/SimpleExpense.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function instanceToArray(Model $item, Model $item_type): array
'item_name' => $item_type->name,
'item_description' => $item_type->description,
'item_total' => $item_type->total,
'item_created_at' => $item->created_at->toDateTimeString()
'item_created_at' => $item->created_at->toDateTimeString(),
'item_updated_at' => $item->updated_at->toDateTimeString()
];
}

Expand All @@ -71,7 +72,8 @@ public function single(
"{$this->table}.name AS item_name",
"{$this->table}.description AS item_description",
"{$this->table}.total AS item_total",
'item.created_at AS item_created_at'
"{$this->table}.created_at AS item_created_at",
"{$this->table}.updated_at AS item_updated_at"
];

$result = $this->from('item')->
Expand All @@ -86,8 +88,8 @@ public function single(
array_key_exists('include-categories', $parameters) === true &&
General::booleanValue($parameters['include-categories']) === true
) {
$result->join('item_category', 'item.id', 'item_category.item_id')->
join('category', 'item_category.category_id', 'category.id');
$result->leftJoin('item_category', 'item.id', 'item_category.item_id')->
leftJoin('category', 'item_category.category_id', 'category.id');

$fields[] = 'item_category.id AS item_category_id';
$fields[] = 'category.id AS category_id';
Expand All @@ -98,8 +100,8 @@ public function single(
array_key_exists('include-subcategories', $parameters) === true &&
General::booleanValue($parameters['include-subcategories']) === true
) {
$result->join('item_sub_category', 'item_category.id', 'item_sub_category.item_category_id')->
join('sub_category', 'item_sub_category.sub_category_id', 'sub_category.id');
$result->leftJoin('item_sub_category', 'item_category.id', 'item_sub_category.item_category_id')->
leftJoin('sub_category', 'item_sub_category.sub_category_id', 'sub_category.id');

$fields[] = 'item_sub_category.id AS item_subcategory_id';
$fields[] = 'sub_category.id AS subcategory_id';
Expand Down Expand Up @@ -202,10 +204,11 @@ public function paginatedCollection(
{
$select_fields = [
'item.id AS item_id',
'item_type_simple_expense.name AS item_name',
'item_type_simple_expense.description AS item_description',
'item_type_simple_expense.total AS item_total',
'item.created_at AS item_created_at'
"{$this->table}.name AS item_name",
"{$this->table}.description AS item_description",
"{$this->table}.total AS item_total",
"{$this->table}.created_at AS item_created_at",
"{$this->table}.updated_at AS item_updated_at"
];

$category_join = false;
Expand All @@ -221,8 +224,8 @@ public function paginatedCollection(
array_key_exists('include-categories', $parameters) === true &&
General::booleanValue($parameters['include-categories']) === true
) {
$collection->join('item_category', 'item.id', 'item_category.item_id')->
join('category', 'item_category.category_id', 'category.id');
$collection->leftJoin('item_category', 'item.id', 'item_category.item_id')->
leftJoin('category', 'item_category.category_id', 'category.id');

$category_join = true;

Expand All @@ -240,8 +243,8 @@ public function paginatedCollection(
array_key_exists('include-subcategories', $parameters) === true &&
General::booleanValue($parameters['include-subcategories']) === true
) {
$collection->join('item_sub_category', 'item_category.id', 'item_sub_category.item_category_id')->
join('sub_category', 'item_sub_category.sub_category_id', 'sub_category.id');
$collection->leftJoin('item_sub_category', 'item_category.id', 'item_sub_category.item_category_id')->
leftJoin('sub_category', 'item_sub_category.sub_category_id', 'sub_category.id');

$subcategory_join = true;

Expand Down
9 changes: 6 additions & 3 deletions app/Models/Item/SimpleItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function instanceToArray(Model $item, Model $item_type): array
'item_name' => $item_type->name,
'item_description' => $item_type->description,
'item_quantity' => $item_type->total,
'item_created_at' => $item->created_at->toDateTimeString()
'item_created_at' => $item->created_at->toDateTimeString(),
'item_updated_at' => $item->updated_at->toDateTimeString()
];
}

Expand All @@ -71,7 +72,8 @@ public function single(
"{$this->table}.name AS item_name",
"{$this->table}.description AS item_description",
"{$this->table}.quantity AS item_quantity",
'item.created_at AS item_created_at'
"{$this->table}.created_at AS item_created_at",
"{$this->table}.updated_at AS item_updated_at"
];

$result = $this->from('item')->
Expand Down Expand Up @@ -161,7 +163,8 @@ public function paginatedCollection(
"{$this->table}.name AS item_name",
"{$this->table}.description AS item_description",
"{$this->table}.quantity AS item_quantity",
'item.created_at AS item_created_at'
"{$this->table}.created_at AS item_created_at",
"{$this->table}.updated_at AS item_updated_at"
];

$collection = $this->from('item')->
Expand Down
4 changes: 4 additions & 0 deletions app/Models/ItemType.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public function paginatedCollection(
$collection = $this->select(
'item_type.id AS item_type_id',
'item_type.name AS item_type_name',
'item_type.friendly_name AS item_type_friendly_name',
'item_type.description AS item_type_description',
'item_type.example AS item_type_example',
'item_type.created_at AS item_type_created_at'
);

Expand Down Expand Up @@ -97,7 +99,9 @@ public function single(int $item_type_id): array
$result = $this->select(
'item_type.id AS item_type_id',
'item_type.name AS item_type_name',
'item_type.friendly_name AS item_type_friendly_name',
'item_type.description AS item_type_description',
'item_type.example AS item_type_example',
'item_type.created_at AS item_type_created_at'
);

Expand Down
2 changes: 1 addition & 1 deletion app/Models/ResourceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ResourceType extends Model
{
protected $table = 'resource_type';

protected $guarded = ['id', 'created_at', 'updated_at'];
protected $guarded = ['id'];

/**
* Return an array of the fields that can be PATCHed.
Expand Down
11 changes: 6 additions & 5 deletions app/Models/ResourceTypeItem/AllocatedExpense.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public function paginatedCollection(
'item_type_allocated_expense.total AS item_total',
'item_type_allocated_expense.percentage AS item_percentage',
'item_type_allocated_expense.actualised_total AS item_actualised_total',
'item.created_at AS item_created_at'
'item_type_allocated_expense.created_at AS item_created_at',
'item_type_allocated_expense.updated_at AS item_updated_at'
];

$collection = $this->join('item_type_allocated_expense', 'item.id', 'item_type_allocated_expense.item_id')->
Expand All @@ -149,8 +150,8 @@ public function paginatedCollection(
array_key_exists('include-categories', $parameters_collection) === true &&
General::booleanValue($parameters_collection['include-categories']) === true
) {
$collection->join('item_category', 'item.id', 'item_category.item_id')->
join('category', 'item_category.category_id', 'category.id');
$collection->leftJoin('item_category', 'item.id', 'item_category.item_id')->
leftJoin('category', 'item_category.category_id', 'category.id');

$category_join = true;

Expand All @@ -168,8 +169,8 @@ public function paginatedCollection(
array_key_exists('include-subcategories', $parameters_collection) === true &&
General::booleanValue($parameters_collection['include-subcategories']) === true
) {
$collection->join('item_sub_category', 'item_category.id', 'item_sub_category.item_category_id')->
join('sub_category', 'item_sub_category.sub_category_id', 'sub_category.id');
$collection->leftJoin('item_sub_category', 'item_category.id', 'item_sub_category.item_category_id')->
leftJoin('sub_category', 'item_sub_category.sub_category_id', 'sub_category.id');

$subcategory_join = true;

Expand Down
11 changes: 6 additions & 5 deletions app/Models/ResourceTypeItem/SimpleExpense.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public function paginatedCollection(
'item_type_simple_expense.name AS item_name',
'item_type_simple_expense.description AS item_description',
'item_type_simple_expense.total AS item_total',
'item.created_at AS item_created_at'
'item_type_simple_expense.created_at AS item_created_at',
'item_type_simple_expense.updated_at AS item_updated_at'
];

$collection = $this->join('item_type_simple_expense', 'item.id', 'item_type_simple_expense.item_id')->
Expand All @@ -124,8 +125,8 @@ public function paginatedCollection(
array_key_exists('include-categories', $parameters_collection) === true &&
General::booleanValue($parameters_collection['include-categories']) === true
) {
$collection->join('item_category', 'item.id', 'item_category.item_id')->
join('category', 'item_category.category_id', 'category.id');
$collection->leftJoin('item_category', 'item.id', 'item_category.item_id')->
leftJoin('category', 'item_category.category_id', 'category.id');

$category_join = true;

Expand All @@ -143,8 +144,8 @@ public function paginatedCollection(
array_key_exists('include-subcategories', $parameters_collection) === true &&
General::booleanValue($parameters_collection['include-subcategories']) === true
) {
$collection->join('item_sub_category', 'item_category.id', 'item_sub_category.item_category_id')->
join('sub_category', 'item_sub_category.sub_category_id', 'sub_category.id');
$collection->leftJoin('item_sub_category', 'item_category.id', 'item_sub_category.item_category_id')->
leftJoin('sub_category', 'item_sub_category.sub_category_id', 'sub_category.id');

$subcategory_join = true;

Expand Down
Loading

0 comments on commit 02371b5

Please sign in to comment.