updating api calls according to the front
This commit is contained in:
parent
f2dc31bbee
commit
b9e7927935
12 changed files with 166 additions and 83 deletions
|
|
@ -19,7 +19,9 @@ class AppController extends Controller
|
|||
$settings = Setting::where('key', 'Button1')->orWhere('key', 'Button2')->orWhere('key', 'Button3')->get();
|
||||
|
||||
foreach ($settings as $setting) {
|
||||
$response['folders'][$setting->key] = Directory::find($setting->value)->only('id', 'name');
|
||||
$directory = Directory::find($setting->value)->only('id', 'name');
|
||||
$directory['name'] = json_encode($directory['name']);
|
||||
$response['folders'][$setting->key] = $directory;
|
||||
}
|
||||
|
||||
return new ApiResponseResource("OK", $response);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@
|
|||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\AppUserResource;
|
||||
use App\Http\Resources\ContactResource;
|
||||
use App\Http\Resources\DirectoryResource;
|
||||
use App\Http\Resources\DocumentResource;
|
||||
use App\Mail\SendFlyer;
|
||||
use App\Mail\SendFlyerFailed;
|
||||
use App\Models\AppUser;
|
||||
|
|
@ -26,7 +30,7 @@ class SyncController extends Controller
|
|||
*/
|
||||
public function getUsers(Request $request)
|
||||
{
|
||||
return new \App\Http\Resources\AppUserCollection(AppUser::where('status', 1)->get());
|
||||
return AppUserResource::collection(AppUser::where('status', 1)->get());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -37,7 +41,7 @@ class SyncController extends Controller
|
|||
{
|
||||
$userId = $request->userId;
|
||||
$this->syncContacts($request->contacts, $userId);
|
||||
return new \App\Http\Resources\ContactsCollection(Contact::where('app_user_id', $userId)->get());
|
||||
return ContactResource::collection(Contact::where('app_user_id', $userId)->get());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -46,7 +50,7 @@ class SyncController extends Controller
|
|||
*/
|
||||
public function getDirectories(Request $request)
|
||||
{
|
||||
return new \App\Http\Resources\DirectoriesCollection(Directory::all());
|
||||
return DirectoryResource::collection(Directory::all());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -55,7 +59,7 @@ class SyncController extends Controller
|
|||
*/
|
||||
public function getDocuments(Request $request)
|
||||
{
|
||||
return new \App\Http\Resources\DocumentsCollection(Document::where('status', 1)->get());
|
||||
return DocumentResource::collection(Document::where('status', 1)->get());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ class ApiResponseResource extends JsonResource
|
|||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class AppUserCollection extends ResourceCollection
|
||||
{
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
33
app/Http/Resources/AppUserResource.php
Normal file
33
app/Http/Resources/AppUserResource.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AppUserResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
//phpcs:enable
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'email' => $this->email,
|
||||
'surname' => $this->lastname,
|
||||
'firstname' => $this->firstname,
|
||||
'password' => $this->password,
|
||||
'activated' => $this->status,
|
||||
'role' => ($this->role === 1) ? "TOTAL" : "USER",
|
||||
'authorizedFolders' => $this->authorizedFolders,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
41
app/Http/Resources/ContactResource.php
Normal file
41
app/Http/Resources/ContactResource.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ContactResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
//phpcs:enable
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'email' => $this->email,
|
||||
'type' => $this->type,
|
||||
'other' => $this->other,
|
||||
'select1' => $this->select1,
|
||||
'select2' => $this->select2,
|
||||
'name' => $this->lastname,
|
||||
'firstname' => $this->firstname,
|
||||
'company' => $this->company,
|
||||
'address' => $this->address,
|
||||
'phone' => $this->phone,
|
||||
'products' => $this->products,
|
||||
'card_url' => $this->card_url,
|
||||
'notes' => $this->notes,
|
||||
'visits' => $this->visits,
|
||||
'user_id' => $this->app_user_id,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class ContactsCollection extends ResourceCollection
|
||||
{
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class DirectoriesCollection extends ResourceCollection
|
||||
{
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
30
app/Http/Resources/DirectoryResource.php
Normal file
30
app/Http/Resources/DirectoryResource.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DirectoryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
//phpcs:enable
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => json_encode($this->name),
|
||||
'parent' => $this->directory_id,
|
||||
'order' => $this->order,
|
||||
'needAuthorization' => $this->needAuthorization,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
47
app/Http/Resources/DocumentResource.php
Normal file
47
app/Http/Resources/DocumentResource.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DocumentResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
switch ($this->lang) {
|
||||
case 1:
|
||||
$tmpLang = "fr";
|
||||
break;
|
||||
case 2:
|
||||
$tmpLang = "en";
|
||||
break;
|
||||
case 3:
|
||||
$tmpLang = "de";
|
||||
break;
|
||||
case 4:
|
||||
$tmpLang = "nl";
|
||||
break;
|
||||
}
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'uuid' => $this->uuid,
|
||||
'title' => $this->title,
|
||||
'type' => $this->type,
|
||||
'directory' => $this->directory_id,
|
||||
'path' => $this->path,
|
||||
'lang' => $tmpLang,
|
||||
'published' => ($this->status) ? 1 : 0,
|
||||
'parent' => $this->document_id,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class DocumentsCollection extends ResourceCollection
|
||||
{
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,11 +12,11 @@ use Illuminate\Support\Facades\Storage;
|
|||
* @property integer $id
|
||||
* @property integer $uuid
|
||||
* @property string $title
|
||||
* @property string $type
|
||||
* @property TypeEnum $type
|
||||
* @property integer $directory_id
|
||||
* @property integer $document_id
|
||||
* @property string $path
|
||||
* @property string $lang
|
||||
* @property LangEnum $lang
|
||||
* @property boolean $status
|
||||
* @property integer $order
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue