-
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.
- Loading branch information
Showing
17 changed files
with
302 additions
and
7 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
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,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Helpers\StringHelper; | ||
use App\Http\ViewModels\Names\NameViewModel; | ||
use App\Services\AddNoteToName; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\Redirect; | ||
use Illuminate\View\View; | ||
|
||
class UserNameController extends Controller | ||
{ | ||
public function update(Request $request): RedirectResponse | ||
{ | ||
$name = $request->attributes->get('name'); | ||
|
||
(new AddNoteToName( | ||
nameId: $name->id, | ||
userId: auth()->id(), | ||
noteText: $request->input('note'), | ||
))->execute(); | ||
|
||
return Redirect::route('name.show', [ | ||
'id' => $name->id, | ||
'name' => StringHelper::sanitizeNameForURL($name->name), | ||
]); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
class Note extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $table = 'notes'; | ||
|
||
protected $fillable = [ | ||
'user_id', | ||
'name_id', | ||
'content', | ||
]; | ||
|
||
public function user(): BelongsTo | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
|
||
public function name(): BelongsTo | ||
{ | ||
return $this->belongsTo(Name::class); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use App\Models\Note; | ||
|
||
class AddNoteToName extends BaseService | ||
{ | ||
private Note $note; | ||
|
||
public function __construct( | ||
public int $nameId, | ||
public int $userId, | ||
public string $noteText, | ||
) { | ||
} | ||
|
||
public function execute(): Note | ||
{ | ||
$this->create(); | ||
|
||
return $this->note; | ||
} | ||
|
||
private function create(): void | ||
{ | ||
$this->note = Note::updateOrCreate([ | ||
'name_id' => $this->nameId, | ||
'user_id' => $this->userId, | ||
], [ | ||
'content' => $this->noteText, | ||
]); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Name; | ||
use App\Models\User; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Note> | ||
*/ | ||
class NoteFactory extends Factory | ||
{ | ||
protected static ?string $password; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'user_id' => User::factory(), | ||
'name_id' => Name::factory(), | ||
'content' => fake()->sentence(), | ||
]; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
database/migrations/2024_01_16_223956_create_name_user_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,24 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('notes', function (Blueprint $table) { | ||
$table->id(); | ||
$table->unsignedBigInteger('user_id'); | ||
$table->unsignedBigInteger('name_id'); | ||
$table->string('content'); | ||
$table->timestamps(); | ||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); | ||
$table->foreign('name_id')->references('id')->on('names')->onDelete('cascade'); | ||
}); | ||
} | ||
}; |
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,54 @@ | ||
@if ($note != '') | ||
|
||
<div x-show="! edit" class="flex justify-between"> | ||
<span class="text-sm mb-2 text-gray-500 flex items-center"><x-heroicon-o-eye-slash class="w-4 h-4 mr-2" />Note privée</span> | ||
|
||
<ul class="text-sm"> | ||
<li class="inline mr-2"><span @click="edit = true" class="underline cursor-pointer hover:underline">Editer</span></li> | ||
<li class="inline"><span class="underline cursor-pointer hover:underline">Supprimer</span></li> | ||
</ul> | ||
</div> | ||
<div x-show='! edit'> | ||
{!! $note !!} | ||
</div> | ||
|
||
@else | ||
|
||
<div x-show="! edit" class="flex items-center justify-between"> | ||
<p class="text-sm">Ajoutez une note privée à ce prénom.</p> | ||
@auth | ||
<span @click="edit = true" class="rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 cursor-pointer flex items-center"> | ||
<x-heroicon-o-pencil-square class="w-4 h-4 mr-2 text-gray-500" /> | ||
<span>Ajouter</span> | ||
</span> | ||
@else | ||
<a href="{{ route('login') }}" class="rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 cursor-pointer flex items-center"> | ||
<x-heroicon-o-pencil-square class="w-4 h-4 mr-2 text-gray-500" /> | ||
<span>Ajouter</span> | ||
</a> | ||
@endauth | ||
</div> | ||
|
||
@endif | ||
|
||
<form x-show="edit"> | ||
<div class="relative mb-3"> | ||
<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('note')" /> | ||
</div> | ||
|
||
<div class="flex items-center"> | ||
<button | ||
hx-put="{{ $name['url']['note_edit'] }}" | ||
hx-headers='{"X-CSRF-TOKEN": "{{ csrf_token() }}"}' | ||
class="px-2 py-1 inline-flex items-center justify-center whitespace-nowrap rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 border border-gray-300 bg-transparent shadow-sm hover:bg-accent hover:text-accent-foreground transition ease-in-out duration-150 hover:bg-gray-100 dark:bg-gray-700 dark:text-white dark:hover:text-gray-800 mr-4"> | ||
Sauvegarder | ||
</button> | ||
|
||
<span @click="edit = false" class="cursor-pointer underline hover:no-underline">Annuler</span> | ||
</div> | ||
</form> |
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
Oops, something went wrong.