Skip to content

Commit

Permalink
Merge pull request #10 from teamq-ec/DM2-2646-desarrollo-del-sistema-…
Browse files Browse the repository at this point in the history
…de-registro-de-usuarios-con-angular-y-laravel

Dm2 2646 desarrollo del sistema de registro de usuarios con angular y laravel
  • Loading branch information
fe222004 authored Jul 26, 2024
2 parents 65c658d + 04abe88 commit 0e32d84
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:0hUj54Gbe261h5UYbuXmWsigir+WrXBQuQAZKLsMe4Q=
APP_DEBUG=true
APP_URL=http://localhost:8000/api
APP_URL=http://localhost:8000

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
Expand Down
26 changes: 26 additions & 0 deletions app/Http/Controllers/ApplianceController.php
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);
}
}
22 changes: 4 additions & 18 deletions app/Http/Controllers/ServiceRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Http\Requests\ServiceRequestRequest;
use App\Http\Resources\ServiceRequestResource;
use App\Models\ServiceRequest;
use Illuminate\Http\Request;

Expand All @@ -16,14 +17,6 @@ public function index()
//
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*/
Expand All @@ -38,17 +31,10 @@ public function store(ServiceRequestRequest $request)
/**
* Display the specified resource.
*/
public function show(string $id)
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
$serviceRequest = ServiceRequest::with('user')->findOrFail($id);
return new ServiceRequestResource($serviceRequest);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions app/Http/Resources/ServiceRequestCollection.php
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);
});
}
}
32 changes: 32 additions & 0 deletions app/Http/Resources/ServiceRequestResource.php
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,
];
}
}
26 changes: 26 additions & 0 deletions app/Http/Resources/UserResource.php
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,
];
}
}
2 changes: 2 additions & 0 deletions app/Models/ServiceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ServiceRequest extends Model implements HasMedia
'service_type', 'preferred_contact_method', 'damaged_appliance_image', 'state'
];

public $timestamps = true;

public function user()
{
return $this->belongsTo(User::class);
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
"laravel/tinker": "^2.8",
"spatie/laravel-medialibrary": "^10.0.0"
"spatie/laravel-medialibrary": "^10.0.0",
"spatie/laravel-query-builder": "^5.7"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
Expand Down
136 changes: 135 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions config/query-builder.php
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,
];
Loading

0 comments on commit 0e32d84

Please sign in to comment.