-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from teamq-ec/DM2-2646-desarrollo-del-sistema-…
…de-registro-de-usuarios-con-angular-y-laravel Dm2 2646 desarrollo del sistema de registro de usuarios con angular y laravel
- Loading branch information
Showing
11 changed files
with
317 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
use Spatie\QueryBuilder\QueryBuilder; | ||
use Spatie\QueryBuilder\AllowedFilter; | ||
|
||
use App\Http\Resources\ServiceRequestCollection; | ||
use App\Models\ServiceRequest; | ||
|
||
class ApplianceController extends Controller | ||
{ | ||
public function getUserAppliances($userId) | ||
{ | ||
$appliances = QueryBuilder::for(ServiceRequest::class) | ||
->where('user_id', $userId) | ||
->allowedFilters([ | ||
AllowedFilter::partial('appliance_type'), | ||
AllowedFilter::partial('brand'), | ||
AllowedFilter::partial('problem_details'), | ||
AllowedFilter::partial('application_date'), | ||
]) | ||
->paginate(5); | ||
|
||
return new ServiceRequestCollection($appliances); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\ResourceCollection; | ||
|
||
class ServiceRequestCollection extends ResourceCollection | ||
{ | ||
/** | ||
* Transform the resource collection into an array. | ||
* | ||
* @return array<int|string, mixed> | ||
*/ | ||
public function toArray($request) | ||
{ | ||
return $this->collection->transform(function($serviceRequest) { | ||
return new ServiceRequestResource($serviceRequest); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class ServiceRequestResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'user' => new UserResource($this->whenLoaded('user')), | ||
'appliance_type' => $this->appliance_type, | ||
'brand' => $this->brand, | ||
'problem_details' => $this->problem_details, | ||
'collection_address' => $this->collection_address, | ||
'service_type' => $this->service_type, | ||
'preferred_contact_method' => $this->preferred_contact_method, | ||
'damaged_appliance_image' => $this->getFirstMediaUrl(), | ||
'application_date' => $this->application_date, | ||
'created_at' => $this->created_at ? $this->created_at->format('d/M/Y H:i:s') : null, | ||
'updated_at' => $this->updated_at ? $this->updated_at->format('d/M/Y H:i:s') : null, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class UserResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
'id'=>$this->id, | ||
'first_name' =>$this->first_name, | ||
'last_name'=>$this->last_name, | ||
'email' =>$this->email, | ||
'phone_number'=>$this->phone_number, | ||
'address'=>$this->address, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
* By default the package will use the `include`, `filter`, `sort` | ||
* and `fields` query parameters as described in the readme. | ||
* | ||
* You can customize these query string parameters here. | ||
*/ | ||
'parameters' => [ | ||
'include' => 'include', | ||
|
||
'filter' => 'filter', | ||
|
||
'sort' => 'sort', | ||
|
||
'fields' => 'fields', | ||
|
||
'append' => 'append', | ||
], | ||
|
||
/* | ||
* Related model counts are included using the relationship name suffixed with this string. | ||
* For example: GET /users?include=postsCount | ||
*/ | ||
'count_suffix' => 'Count', | ||
|
||
/* | ||
* Related model exists are included using the relationship name suffixed with this string. | ||
* For example: GET /users?include=postsExists | ||
*/ | ||
'exists_suffix' => 'Exists', | ||
|
||
/* | ||
* By default the package will throw an `InvalidFilterQuery` exception when a filter in the | ||
* URL is not allowed in the `allowedFilters()` method. | ||
*/ | ||
'disable_invalid_filter_query_exception' => false, | ||
|
||
/* | ||
* By default the package will throw an `InvalidSortQuery` exception when a sort in the | ||
* URL is not allowed in the `allowedSorts()` method. | ||
*/ | ||
'disable_invalid_sort_query_exception' => false, | ||
|
||
/* | ||
* By default the package will throw an `InvalidIncludeQuery` exception when an include in the | ||
* URL is not allowed in the `allowedIncludes()` method. | ||
*/ | ||
'disable_invalid_includes_query_exception' => false, | ||
|
||
/* | ||
* By default, the package expects relationship names to be snake case plural when using fields[relationship]. | ||
* For example, fetching the id and name for a userOwner relation would look like this: | ||
* GET /users?fields[user_owner]=id,name | ||
* | ||
* Set this to `false` if you don't want that and keep the requested relationship names as-is and allows you to | ||
* request the fields using a camelCase relationship name: | ||
* GET /users?fields[userOwner]=id,name | ||
*/ | ||
'convert_relation_names_to_snake_case_plural' => true, | ||
]; |
Oops, something went wrong.