Skip to content

Commit

Permalink
Merge pull request #148 from deanblackborough/v2.02.0
Browse files Browse the repository at this point in the history
v2.01.1
  • Loading branch information
deanblackborough authored Sep 24, 2019
2 parents 7f774ed + 0a1130e commit 93959e8
Show file tree
Hide file tree
Showing 16 changed files with 639 additions and 607 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

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

## [v2.01.0] - 2019-09-xx
## [v2.01.1] - 2019-09-24
### Changed
- The `description` field in the `item_type` tables is now nullable.
- We have updated the `item_type` tables; all descriptions are now null.
- We have upgraded to version 5.8 of the Laravel framework.

### Fixed
- The subcategory parameter is only passed through to the relevant controller if the category parameter is also valid.

## [v2.01.0] - 2019-09-22
### Added
- We have added a `Header` utility class that can be used to generate the expected headers for collection and item requests.
- We have added a `RoutePermission` class which returns the view and manage permission for each route.
Expand Down
24 changes: 12 additions & 12 deletions app/Http/Controllers/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,15 @@ public function optionsShow(
/**
* Create a new item
*
* @param Request $request
* @param string $resource_type_id
* @param string $resource_id
*
* @return JsonResponse
*/
public function create(Request $request, string $resource_type_id, string $resource_id): JsonResponse
public function create(
string $resource_type_id,
string $resource_id
): JsonResponse
{
Route::resource(
$resource_type_id,
Expand All @@ -302,17 +304,17 @@ public function create(Request $request, string $resource_type_id, string $resou

$item_type = new ItemTypeAllocatedExpense([
'item_id' => $item->id,
'name' => $request->input('description'), // Fix later
'description' => $request->input('description'),
'effective_date' => $request->input('effective_date'),
'publish_after' => $request->input('publish_after', null),
'total' => $request->input('total'),
'percentage' => $request->input('percentage', 100),
'name' => request()->input('name'),
'description' => request()->input('description', null),
'effective_date' => request()->input('effective_date'),
'publish_after' => request()->input('publish_after', null),
'total' => request()->input('total'),
'percentage' => request()->input('percentage', 100),
]);

$item_type->setActualisedTotal(
$request->input('total'),
$request->input('percentage', 100)
request()->input('total'),
request()->input('percentage', 100)
);

$item_type->save();
Expand Down Expand Up @@ -394,15 +396,13 @@ public function update(
/**
* Delete the assigned item
*
* @param Request $request,
* @param string $resource_type_id,
* @param string $resource_id,
* @param string $item_id
*
* @return JsonResponse
*/
public function delete(
Request $request,
string $resource_type_id,
string $resource_id,
string $item_id
Expand Down
4 changes: 4 additions & 0 deletions app/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ 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',
Expand Down Expand Up @@ -240,6 +241,7 @@ public function paginatedCollection(
case 'actualised_total':
case 'description':
case 'effective_date':
case 'name':
case 'total':
$collection->orderBy('item_type_allocated_expense.' . $field, $direction);
break;
Expand Down Expand Up @@ -281,6 +283,7 @@ public function single(
where('resource.resource_type_id', '=', $resource_type_id)->
select(
'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',
Expand Down Expand Up @@ -332,6 +335,7 @@ public function instanceToArray(Item $item, ItemTypeAllocatedExpense $item_type)
{
return [
'item_id' => $item->id,
'item_name' => $item_type->name,
'item_description' => $item_type->description,
'item_effective_date' => $item_type->effective_date,
'item_publish_after' => $item_type->publish_after,
Expand Down
2 changes: 2 additions & 0 deletions app/Models/ResourceTypeItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function paginatedCollection(
'resource.name AS resource_name',
'resource.description AS resource_description',
'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',
Expand Down Expand Up @@ -222,6 +223,7 @@ public function paginatedCollection(
case 'actualised_total':
case 'description':
case 'effective_date':
case 'name':
case 'total':
$collection->orderBy('item_type_allocated_expense.' . $field, $direction);
break;
Expand Down
1 change: 1 addition & 0 deletions app/Models/Transformers/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function toArray(): array
{
$item = [
'id' => $this->hash->item()->encode($this->item['item_id']),
'name' => $this->item['item_name'],
'description' => $this->item['item_description'],
'total' => number_format((float) $this->item['item_total'],2, '.', ''),
'percentage' => $this->item['item_percentage'],
Expand Down
1 change: 1 addition & 0 deletions app/Models/Transformers/ResourceTypeItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function toArray(): array
{
$item = [
'id' => $this->hash->item()->encode($this->item['item_id']),
'name' => $this->item['item_name'],
'description' => $this->item['item_description'],
'total' => number_format((float) $this->item['item_total'], 2, '.', ''),
'percentage' => (int) $this->item['item_percentage'],
Expand Down
2 changes: 1 addition & 1 deletion app/Validators/Request/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ private static function validate()
break;

case 'subcategory':
case 'sub_category':
if (array_key_exists($key, self::$parameters) === true) {
if (
array_key_exists('category', self::$parameters) === false ||
(new SubCategory())->
where('sub_category.id', '=', self::$parameters[$key])->
where('sub_category.category_id', '=', self::$parameters['category'])->
Expand Down
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
{
"name": "costs-to-expect/api",
"description": "The API for https://api.costs-to-expect.com",
"keywords": ["api", "laravel", "child cost"],
"keywords": [
"api",
"laravel",
"child cost"
],
"license": "MIT",
"type": "project",
"require": {
"php": "^7.3",
"ext-json": "*",
"doctrine/dbal": "^2.9",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"hashids/hashids": "^3.0",
"laravel/framework": "5.7.*",
"laravel/framework": "^5.8.0",
"laravel/passport": "^7.0",
"laravel/tinker": "^1.0"
},
Expand All @@ -37,8 +42,7 @@
},
"extra": {
"laravel": {
"dont-discover": [
]
"dont-discover": []
}
},
"scripts": {
Expand Down
Loading

0 comments on commit 93959e8

Please sign in to comment.