From 39b017d42987ca3b4cb97366534dd3236ef2bfe4 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Fri, 21 Jul 2023 10:53:33 +0200 Subject: [PATCH 1/5] delete existings tags on document when remove it --- app/Http/Controllers/Bo/DocumentController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/Bo/DocumentController.php b/app/Http/Controllers/Bo/DocumentController.php index d2a19b7..9129547 100644 --- a/app/Http/Controllers/Bo/DocumentController.php +++ b/app/Http/Controllers/Bo/DocumentController.php @@ -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(); From f2dc31bbeeb0f2c5f547768d924d3977283d858c Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Fri, 21 Jul 2023 14:51:02 +0200 Subject: [PATCH 2/5] set relation user to directory --- app/Models/User.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Models/User.php b/app/Models/User.php index 33fc3a0..3cdf19f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -73,4 +73,16 @@ class User extends Authenticatable } }); } + + // * RELATIONSHIPS + + /** + * MorphToMany directories relation. + * + * @return \Illuminate\Database\Eloquent\Relations\MorphToMany + */ + public function directories() + { + return $this->morphToMany(Directory::class, 'directorables'); + } } From b9e7927935f3dfdd3b4926b8afd02c8683bc3657 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Fri, 21 Jul 2023 14:53:44 +0200 Subject: [PATCH 3/5] updating api calls according to the front --- app/Http/Controllers/API/AppController.php | 4 +- app/Http/Controllers/API/SyncController.php | 12 +++-- app/Http/Resources/ApiResponseResource.php | 2 + app/Http/Resources/AppUserCollection.php | 19 -------- app/Http/Resources/AppUserResource.php | 33 ++++++++++++++ app/Http/Resources/ContactResource.php | 41 +++++++++++++++++ app/Http/Resources/ContactsCollection.php | 19 -------- app/Http/Resources/DirectoriesCollection.php | 19 -------- app/Http/Resources/DirectoryResource.php | 30 +++++++++++++ app/Http/Resources/DocumentResource.php | 47 ++++++++++++++++++++ app/Http/Resources/DocumentsCollection.php | 19 -------- app/Models/Document.php | 4 +- 12 files changed, 166 insertions(+), 83 deletions(-) delete mode 100644 app/Http/Resources/AppUserCollection.php create mode 100644 app/Http/Resources/AppUserResource.php create mode 100644 app/Http/Resources/ContactResource.php delete mode 100644 app/Http/Resources/ContactsCollection.php delete mode 100644 app/Http/Resources/DirectoriesCollection.php create mode 100644 app/Http/Resources/DirectoryResource.php create mode 100644 app/Http/Resources/DocumentResource.php delete mode 100644 app/Http/Resources/DocumentsCollection.php diff --git a/app/Http/Controllers/API/AppController.php b/app/Http/Controllers/API/AppController.php index 6ca236a..0eac5e1 100644 --- a/app/Http/Controllers/API/AppController.php +++ b/app/Http/Controllers/API/AppController.php @@ -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); diff --git a/app/Http/Controllers/API/SyncController.php b/app/Http/Controllers/API/SyncController.php index 33b8271..686b051 100644 --- a/app/Http/Controllers/API/SyncController.php +++ b/app/Http/Controllers/API/SyncController.php @@ -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()); } /** diff --git a/app/Http/Resources/ApiResponseResource.php b/app/Http/Resources/ApiResponseResource.php index d132077..5e031a8 100644 --- a/app/Http/Resources/ApiResponseResource.php +++ b/app/Http/Resources/ApiResponseResource.php @@ -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) { diff --git a/app/Http/Resources/AppUserCollection.php b/app/Http/Resources/AppUserCollection.php deleted file mode 100644 index fa5b396..0000000 --- a/app/Http/Resources/AppUserCollection.php +++ /dev/null @@ -1,19 +0,0 @@ - $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, + ]; + } +} diff --git a/app/Http/Resources/ContactResource.php b/app/Http/Resources/ContactResource.php new file mode 100644 index 0000000..a0e0445 --- /dev/null +++ b/app/Http/Resources/ContactResource.php @@ -0,0 +1,41 @@ + $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, + ]; + } +} diff --git a/app/Http/Resources/ContactsCollection.php b/app/Http/Resources/ContactsCollection.php deleted file mode 100644 index d5102ad..0000000 --- a/app/Http/Resources/ContactsCollection.php +++ /dev/null @@ -1,19 +0,0 @@ - $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, + ]; + } +} diff --git a/app/Http/Resources/DocumentResource.php b/app/Http/Resources/DocumentResource.php new file mode 100644 index 0000000..a4c085a --- /dev/null +++ b/app/Http/Resources/DocumentResource.php @@ -0,0 +1,47 @@ +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, + ]; + } +} diff --git a/app/Http/Resources/DocumentsCollection.php b/app/Http/Resources/DocumentsCollection.php deleted file mode 100644 index 6647935..0000000 --- a/app/Http/Resources/DocumentsCollection.php +++ /dev/null @@ -1,19 +0,0 @@ - Date: Mon, 24 Jul 2023 12:41:21 +0200 Subject: [PATCH 4/5] fix flyer mail --- resources/views/bo/mails/sendflyer.blade.php | 10 +++++----- resources/views/vendor/errors/403.blade.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/views/bo/mails/sendflyer.blade.php b/resources/views/bo/mails/sendflyer.blade.php index ee6596a..e82c0db 100644 --- a/resources/views/bo/mails/sendflyer.blade.php +++ b/resources/views/bo/mails/sendflyer.blade.php @@ -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 diff --git a/resources/views/vendor/errors/403.blade.php b/resources/views/vendor/errors/403.blade.php index 3f9ded5..08ae36b 100644 --- a/resources/views/vendor/errors/403.blade.php +++ b/resources/views/vendor/errors/403.blade.php @@ -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) From 5a1fcd6077537be0e563123ccf14832d9ec5def5 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Mon, 24 Jul 2023 14:28:45 +0200 Subject: [PATCH 5/5] add exports postman api calls --- .../com-app-bo-v2.0.postman_collection.json | 260 ++++++++++++++++ .../com-app-bo-v2.1.postman_collection.json | 286 ++++++++++++++++++ 2 files changed, 546 insertions(+) create mode 100644 tests/Api/Exports/com-app-bo-v2.0.postman_collection.json create mode 100644 tests/Api/Exports/com-app-bo-v2.1.postman_collection.json diff --git a/tests/Api/Exports/com-app-bo-v2.0.postman_collection.json b/tests/Api/Exports/com-app-bo-v2.0.postman_collection.json new file mode 100644 index 0000000..fc81d62 --- /dev/null +++ b/tests/Api/Exports/com-app-bo-v2.0.postman_collection.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/tests/Api/Exports/com-app-bo-v2.1.postman_collection.json b/tests/Api/Exports/com-app-bo-v2.1.postman_collection.json new file mode 100644 index 0000000..2dbda2f --- /dev/null +++ b/tests/Api/Exports/com-app-bo-v2.1.postman_collection.json @@ -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" + } + ] +} \ No newline at end of file