-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a public note on a name on a public list (#55)
- Loading branch information
Showing
11 changed files
with
217 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Name; | ||
use App\Services\ToggleNameToNameList; | ||
use App\Services\UpdateNoteToNameInList; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Redirect; | ||
|
||
class StoreNoteForNameInListController extends Controller | ||
{ | ||
public function edit(Request $request, int $listId, int $nameId): View | ||
{ | ||
$requestedList = $request->attributes->get('list'); | ||
|
||
$name = Name::findOrFail($nameId); | ||
|
||
$record = DB::table('list_name') | ||
->where('name_id', $nameId) | ||
->where('list_id', $listId) | ||
->first(); | ||
|
||
return view('user.lists.edit-note', [ | ||
'list' => [ | ||
'name' => $requestedList->name, | ||
'url' => [ | ||
'show' => route('list.show', ['liste' => $listId]), | ||
'update' => route('name.list.update', [ | ||
'liste' => $listId, | ||
'id' => $nameId, | ||
]), | ||
], | ||
], | ||
'name' => $name->name, | ||
'note' => is_null($record->public_note) ? '' : $record->public_note, | ||
]); | ||
} | ||
|
||
/** | ||
* Add a note for the given name in the given list. | ||
*/ | ||
public function update(Request $request, int $listId, int $nameId): RedirectResponse | ||
{ | ||
$requestedList = $request->attributes->get('list'); | ||
|
||
(new UpdateNoteToNameInList( | ||
nameListId: $listId, | ||
nameId: $nameId, | ||
note: $request->input('note'), | ||
))->execute(); | ||
|
||
Cache::forget('route-list-' . $requestedList->id); | ||
Cache::forget('user-lists-' . auth()->id()); | ||
Cache::forget('list-details-' . $requestedList->id); | ||
Cache::forget('admin-lists'); | ||
|
||
return Redirect::route('list.show', [ | ||
'liste' => $listId, | ||
]); | ||
} | ||
|
||
public function destroy(Request $request, int $listId, int $nameId): void | ||
{ | ||
$requestedList = $request->attributes->get('list'); | ||
|
||
(new ToggleNameToNameList( | ||
nameId: $nameId, | ||
listId: $requestedList->id, | ||
))->execute(); | ||
|
||
Cache::forget('route-list-' . $requestedList->id); | ||
Cache::forget('user-lists-' . auth()->id()); | ||
Cache::forget('list-details-' . $requestedList->id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use Illuminate\Support\Facades\DB; | ||
|
||
class UpdateNoteToNameInList extends BaseService | ||
{ | ||
public function __construct( | ||
public int $nameListId, | ||
public int $nameId, | ||
public string $note, | ||
) { | ||
} | ||
|
||
public function execute(): void | ||
{ | ||
$this->create(); | ||
} | ||
|
||
private function create(): void | ||
{ | ||
DB::table('list_name') | ||
->where('list_id', $this->nameListId) | ||
->where('name_id', $this->nameId) | ||
->update(['public_note' => $this->note]); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
database/migrations/2024_02_19_182155_update_list_name_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::table('list_name', function (Blueprint $table) { | ||
$table->text('public_note')->nullable(); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<x-guest-layout class="bg-gray-50"> | ||
<div class="bg-violet-100 mb-10"> | ||
<div class="border-b border-violet-200"> | ||
@include('layouts.unlogged-navigation') | ||
</div> | ||
|
||
<div class="border-b border-violet-200"> | ||
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8 py-2"> | ||
<ul class="text-xs"> | ||
<li class="inline after:content-['>'] after:text-gray-500 after:text-xs"> | ||
<a hx-boost="true" href="{{ route('home.index') }}" class="text-violet-900 underline">Accueil</a> | ||
</li> | ||
<li class="inline after:content-['>'] after:text-gray-500 after:text-xs"> | ||
<a hx-boost="true" href="{{ route('list.index') }}" class="text-violet-900 underline">Toutes vos listes de prénoms</a> | ||
</li> | ||
<li class="inline after:content-['>'] after:text-gray-500 after:text-xs"> | ||
<a hx-boost="true" href="{{ $list['url']['show'] }}" class="text-violet-900 underline">{{ $list['name'] }}</a> | ||
</li> | ||
<li class="inline">Ajout d'une note</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<div class="mx-auto max-w-2xl sm:px-6 lg:px-8 py-2"> | ||
<form method="POST" action="{{ $list['url']['update'] }}" class="mb-8 shadow sm:rounded-lg"> | ||
@csrf | ||
@method('PUT') | ||
|
||
<div class="relative border-b dark:border-gray-600 px-6 py-4 bg-yellow-50"> | ||
<h1 class="text-center font-bold">Ajout d'une note au prénom {{ $name }}</h1> | ||
</div> | ||
|
||
<!-- description --> | ||
<div class="relative px-6 pt-4 pb-6"> | ||
<x-input-label for="note" | ||
:value="'Note'" /> | ||
|
||
<x-textarea class="mt-1 block w-full" | ||
id="note" | ||
name="note" | ||
type="text">{{ old('note', $note) }}</x-textarea> | ||
|
||
<x-input-error class="mt-2" :messages="$errors->get('description')" /> | ||
</div> | ||
|
||
<!-- actions --> | ||
<div class="flex items-center justify-between border-t dark:border-gray-600 bg-white dark:bg-gray-800 px-6 py-4"> | ||
<x-link href="{{ $list['url']['show'] }}">Retour</x-link> | ||
|
||
<div> | ||
<x-primary-button class="w-full text-center" dusk="submit-form-button"> | ||
Sauvegarder | ||
</x-primary-button> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</x-guest-layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters