Feature: Delete submission (#137)
* Feature: Delete submission * Small polishing --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
24
app/Http/Controllers/Forms/RecordController.php
Normal file
24
app/Http/Controllers/Forms/RecordController.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Forms;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Forms\Form;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RecordController extends Controller
|
||||
{
|
||||
public function delete(Request $request, $id, $recordId)
|
||||
{
|
||||
$form = Form::findOrFail((int) $id);
|
||||
$this->authorize('delete', $form);
|
||||
|
||||
$record = $form->submissions()->where('id', $recordId)->firstOrFail();
|
||||
$record->delete();
|
||||
|
||||
return $this->success([
|
||||
'message' => 'Record successfully removed.'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class FormSubmissionResource extends JsonResource
|
||||
public function toArray($request)
|
||||
{
|
||||
$this->generateFileLinks();
|
||||
$this->addTimestamp();
|
||||
$this->addExtraData();
|
||||
|
||||
return [
|
||||
'data' => $this->data,
|
||||
@@ -25,10 +25,11 @@ class FormSubmissionResource extends JsonResource
|
||||
];
|
||||
}
|
||||
|
||||
private function addTimestamp()
|
||||
private function addExtraData()
|
||||
{
|
||||
$this->data = array_merge($this->data, [
|
||||
"created_at" => $this->created_at->toDateTimeString()
|
||||
"created_at" => $this->created_at->toDateTimeString(),
|
||||
'id' => $this->id
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace App\Service\OpenAi\Utils;
|
||||
* Licensed under MIT license.
|
||||
*/
|
||||
|
||||
use App\Exceptions\Coursework\InvalidJsonException;
|
||||
use Aws\Exception\InvalidJsonException;
|
||||
|
||||
/**
|
||||
* Attempts to fix truncated JSON by padding contextual counterparts at the end.
|
||||
|
||||
Reference in New Issue
Block a user