Applied latest changes from styleCI

This commit is contained in:
Dan Brown 2021-10-20 10:49:45 +01:00
parent 7bbcaa7cbc
commit 859934d6a3
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
5 changed files with 60 additions and 55 deletions

View File

@ -20,13 +20,13 @@ class AttachmentApiController extends ApiController
'name' => 'required|min:1|max:255|string', 'name' => 'required|min:1|max:255|string',
'uploaded_to' => 'required|integer|exists:pages,id', 'uploaded_to' => 'required|integer|exists:pages,id',
'file' => 'required_without:link|file', 'file' => 'required_without:link|file',
'link' => 'required_without:file|min:1|max:255|safe_url' 'link' => 'required_without:file|min:1|max:255|safe_url',
], ],
'update' => [ 'update' => [
'name' => 'min:1|max:255|string', 'name' => 'min:1|max:255|string',
'uploaded_to' => 'integer|exists:pages,id', 'uploaded_to' => 'integer|exists:pages,id',
'file' => 'file', 'file' => 'file',
'link' => 'min:1|max:255|safe_url' 'link' => 'min:1|max:255|safe_url',
], ],
]; ];
@ -72,11 +72,14 @@ class AttachmentApiController extends ApiController
$attachment = $this->attachmentService->saveNewUpload($uploadedFile, $page->id); $attachment = $this->attachmentService->saveNewUpload($uploadedFile, $page->id);
} else { } else {
$attachment = $this->attachmentService->saveNewFromLink( $attachment = $this->attachmentService->saveNewFromLink(
$requestData['name'], $requestData['link'], $page->id $requestData['name'],
$requestData['link'],
$page->id
); );
} }
$this->attachmentService->updateFile($attachment, $requestData); $this->attachmentService->updateFile($attachment, $requestData);
return response()->json($attachment); return response()->json($attachment);
} }
@ -140,6 +143,7 @@ class AttachmentApiController extends ApiController
} }
$this->attachmentService->updateFile($attachment, $requestData); $this->attachmentService->updateFile($attachment, $requestData);
return response()->json($attachment); return response()->json($attachment);
} }
@ -158,5 +162,4 @@ class AttachmentApiController extends ApiController
return response('', 204); return response('', 204);
} }
} }

View File

@ -90,6 +90,7 @@ class Attachment extends Model
public function scopeVisible(): Builder public function scopeVisible(): Builder
{ {
$permissionService = app()->make(PermissionService::class); $permissionService = app()->make(PermissionService::class);
return $permissionService->filterRelatedEntity( return $permissionService->filterRelatedEntity(
Page::class, Page::class,
Attachment::query(), Attachment::query(),

View File

@ -171,6 +171,7 @@ class AttachmentService
} }
$attachment->save(); $attachment->save();
return $attachment->refresh(); return $attachment->refresh();
} }

View File

@ -143,8 +143,8 @@ class AttachmentsApiTest extends TestCase
'error' => [ 'error' => [
'message' => 'The given data was invalid.', 'message' => 'The given data was invalid.',
'validation' => [ 'validation' => [
"file" => ["The file field is required when link is not present."], 'file' => ['The file field is required when link is not present.'],
"link" => ["The link field is required when file is not present."], 'link' => ['The link field is required when file is not present.'],
], ],
'code' => 422, 'code' => 422,
], ],
@ -179,8 +179,8 @@ class AttachmentsApiTest extends TestCase
'name' => $attachment->createdBy->name, 'name' => $attachment->createdBy->name,
], ],
'links' => [ 'links' => [
"html" => "<a target=\"_blank\" href=\"http://localhost/attachments/{$attachment->id}\">my attachment</a>", 'html' => "<a target=\"_blank\" href=\"http://localhost/attachments/{$attachment->id}\">my attachment</a>",
"markdown" => "[my attachment](http://localhost/attachments/{$attachment->id})" 'markdown' => "[my attachment](http://localhost/attachments/{$attachment->id})",
], ],
]); ]);
} }
@ -216,8 +216,8 @@ class AttachmentsApiTest extends TestCase
'name' => $attachment->updatedBy->name, 'name' => $attachment->updatedBy->name,
], ],
'links' => [ 'links' => [
"html" => "<a target=\"_blank\" href=\"http://localhost/attachments/{$attachment->id}\">My file attachment</a>", 'html' => "<a target=\"_blank\" href=\"http://localhost/attachments/{$attachment->id}\">My file attachment</a>",
"markdown" => "[My file attachment](http://localhost/attachments/{$attachment->id})" 'markdown' => "[My file attachment](http://localhost/attachments/{$attachment->id})",
], ],
]); ]);
@ -250,7 +250,6 @@ class AttachmentsApiTest extends TestCase
$attachment = $this->createAttachmentForPage($page); $attachment = $this->createAttachmentForPage($page);
$file = $this->getTestFile('textfile.txt'); $file = $this->getTestFile('textfile.txt');
$resp = $this->call('PUT', "{$this->baseEndpoint}/{$attachment->id}", ['name' => 'My updated file'], [], ['file' => $file]); $resp = $this->call('PUT', "{$this->baseEndpoint}/{$attachment->id}", ['name' => 'My updated file'], [], ['file' => $file]);
$resp->assertStatus(200); $resp->assertStatus(200);
@ -278,7 +277,7 @@ class AttachmentsApiTest extends TestCase
$details = [ $details = [
'name' => 'My updated API attachment', 'name' => 'My updated API attachment',
'link' => 'https://cats.example.com' 'link' => 'https://cats.example.com',
]; ];
$resp = $this->putJson("{$this->baseEndpoint}/{$attachment->id}", $details); $resp = $this->putJson("{$this->baseEndpoint}/{$attachment->id}", $details);
@ -315,8 +314,9 @@ class AttachmentsApiTest extends TestCase
'order' => 1, 'order' => 1,
'created_by' => $admin->id, 'created_by' => $admin->id,
'updated_by' => $admin->id, 'updated_by' => $admin->id,
'path' => 'https://attachment.example.com' 'path' => 'https://attachment.example.com',
], $attributes)); ], $attributes));
return $attachment; return $attachment;
} }