Merge remote-tracking branch 'origin/v2.1.0-api-calls' into v2.1.0

This commit is contained in:
Jérémy Munsch 2023-08-21 17:12:26 +02:00
commit c4ba52bbac
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC
18 changed files with 731 additions and 89 deletions

View file

@ -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);

View file

@ -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());
}
/**

View file

@ -171,6 +171,7 @@ class DocumentController extends Controller
*/
public function destroy(Document $document)
{
$document->tags()->sync([]);
foreach ($document->children as $documentChild) {
Document::removeDocument($documentChild);
$documentChild->deleteOrFail();

View file

@ -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)
{

View file

@ -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);
}
}

View 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,
];
}
}

View 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,
];
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View 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,
];
}
}

View 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,
];
}
}

View file

@ -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);
}
}

View file

@ -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
*/

View file

@ -84,4 +84,16 @@ class User extends Authenticatable
$model->password = Hash::make($model->password);
}
}
// * RELATIONSHIPS
/**
* MorphToMany directories relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function directories()
{
return $this->morphToMany(Directory::class, 'directorables');
}
}

View file

@ -9,9 +9,9 @@
@endif
@for ($i = 0; $i < count($data->attach); $i++)
@component('mail::button', ['url' => $data->attach[$i], 'color' => 'success'])
{{ $data->filesName[$i] }}
@endcomponent
@endfor
@component('mail::button', ['url' => $data->attach[$i], 'color' => 'success'])
{{ $data->filesName[$i] }}
@endcomponent
@endfor
@endcomponent
@endcomponent

View file

@ -3,7 +3,7 @@
@section('title', __('Forbidden'))
@section('code', '403')
@section('message', __($exception->getMessage() ?: 'Forbidden'))
@section('submessage', __('Vous n\'êtes pas authorisé à acceder a cet élément.'))
@section('submessage', __('Vous n\'êtes pas authorisé à accéder à cet élément.'))
@section('button', true)

View file

@ -0,0 +1,260 @@
{
"info": {
"_postman_id": "14822885-c98d-45cd-aa9d-3aaabd619c25",
"name": "com-app-bo-v2.0",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json",
"_exporter_id": "27033893"
},
"item": [
{
"name": "Settings",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/settings?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"settings"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "App",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/app?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"app"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "AppUsers",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/users?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"users"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "Directories",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/directories?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"directories"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "Documents",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/documents?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"documents"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "Version",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/version?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"version"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "Contacts",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"userId\": 1,\r\n \"contacts\": [{\r\n \"uniq_id\": \"3213211354dsdfsdf4654\",\r\n \"user_id\": 1,\r\n \"email\": \"john.doe@ldc.fr\",\r\n \"type\": \"other\",\r\n \"other\": \"Production publicitaire\",\r\n \"select1\": \"pole-sable\",\r\n \"select2\": \"grossiste-distributeur-cash\",\r\n \"lastname\": \"John\",\r\n \"firstname\": \"Doe\",\r\n \"company\": \"Avigros\",\r\n \"address\": \"37 rue laugier 75017 paris\",\r\n \"phone\": \"0634609299\",\r\n \"products\": [true,null,null,null,null,null,null,true],\r\n \"card_url\": null,\r\n \"notes\": \"Poulet crapaudine sans le pour rotissoire - Idéalement France - Travail avec média France toute en frais\",\r\n \"visits\": \"[{'title':'21/01/2023','note':'Échange concernant le book volaille découpe\\n\\n'}]\",\r\n \"to_delete\": false\r\n }]\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://{{$domain}}/api/contacts?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"contacts"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "SendBrochure",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"emails\": {\r\n \"app_user_id\": 1,\r\n \"subject\": \"mail test\",\r\n \"email\": \"john.doe@ldc.fr\",\r\n \"message\": \"Bonjour, ceci est un message !\",\r\n \"documents\": [{\r\n \"uuid\": \"96f03105-63dd-4ee6-8d44-460af5215328\",\r\n \"type\": \"pdf\",\r\n \"title\": \"test\"\r\n }]\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://{{$domain}}/api/sendBrochure?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"sendBrochure"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "$domain",
"value": "com-app-bo-old.s-web.test",
"type": "string"
},
{
"key": "$token",
"value": "toto",
"type": "string"
}
]
}

View file

@ -0,0 +1,286 @@
{
"info": {
"_postman_id": "88ecfee1-af91-4215-8906-3c904fd261a9",
"name": "com-app-bo-v2.1",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "27033893"
},
"item": [
{
"name": "Settings",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/settings?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"settings"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "Formulary settings",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/settings/form?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"settings",
"form"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "App",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/app?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"app"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "AppUsers",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/users?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"users"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "Directories",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/directories?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"directories"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "Documents",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/documents?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"documents"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "Version",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{$domain}}/api/version?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"version"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "Contacts",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"userId\": 1,\r\n \"contacts\": [{\r\n \"uniq_id\": \"3213211354dsdfsdf4654\",\r\n \"app_user_id\": 1,\r\n \"email\": \"john.doe@ldc.fr\",\r\n \"type\": \"other\",\r\n \"other\": \"Production publicitaire\",\r\n \"select1\": \"pole-sable\",\r\n \"select2\": \"grossiste-distributeur-cash\",\r\n \"firstname\": \"John\",\r\n \"lastname\": \"Doe\",\r\n \"company\": \"Avigros\",\r\n \"address\": \"37 rue laugier 75017 paris\",\r\n \"phone\": \"0634609299\",\r\n \"products\": [true,null,null,null,null,null,null,true],\r\n \"card_url\": null,\r\n \"notes\": \"Poulet crapaudine sans le pour rotissoire - Idéalement France - Travail avec média France toute en frais\",\r\n \"visits\": \"[{'title':'21/01/2023','note':'Échange concernant le book volaille découpe\\n\\n'}]\",\r\n \"to_delete\": false\r\n }]\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://{{$domain}}/api/contacts?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"contacts"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
},
{
"name": "SendBrochure",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"emails\": {\r\n \"app_user_id\": 1,\r\n \"subject\": \"mail test\",\r\n \"email\": \"john.doe@ldc.fr\",\r\n \"message\": \"Bonjour, ceci est un message !\",\r\n \"documents\": [{\r\n \"uuid\": \"354474ff-0419-4ecc-b245-9a7936caeedb\",\r\n \"type\": \"pdf\",\r\n \"title\": \"test\"\r\n }]\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://{{$domain}}/api/sendBrochure?token={{$token}}",
"protocol": "https",
"host": [
"{{$domain}}"
],
"path": [
"api",
"sendBrochure"
],
"query": [
{
"key": "token",
"value": "{{$token}}"
}
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "$domain",
"value": "com-app-bo.s-web.test",
"type": "string"
},
{
"key": "$token",
"value": "toto",
"type": "string"
}
]
}