-
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
37 changed files
with
672 additions
and
173 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
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,12 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class ShareController extends Controller | ||
{ | ||
public function show(Request $request): void | ||
{ | ||
} | ||
} |
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,93 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Helpers\StringHelper; | ||
use App\Services\AddNoteToName; | ||
use App\Services\DestroyNote; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\View\View; | ||
|
||
class UserNameController extends Controller | ||
{ | ||
public function show(Request $request): View | ||
{ | ||
$name = $request->attributes->get('name'); | ||
|
||
return view('components.note-show', [ | ||
'note' => $name->getNoteForUser(), | ||
'url' => route('user.name.edit', [ | ||
'id' => $name->id, | ||
]), | ||
'deleteUrl' => route('user.name.destroy', [ | ||
'id' => $name->id, | ||
]), | ||
]); | ||
} | ||
|
||
public function edit(Request $request): View | ||
{ | ||
$name = $request->attributes->get('name'); | ||
|
||
return view('names.partials.edit-note', [ | ||
'note' => $name->getNoteForUser(), | ||
'url' => [ | ||
'show' => route('user.name.show', [ | ||
'id' => $name->id, | ||
]), | ||
'update' => route('user.name.update', [ | ||
'id' => $name->id, | ||
'name' => StringHelper::sanitizeNameForURL($name->name), | ||
]), | ||
], | ||
]); | ||
} | ||
|
||
public function update(Request $request): View | ||
{ | ||
$name = $request->attributes->get('name'); | ||
|
||
(new AddNoteToName( | ||
nameId: $name->id, | ||
userId: auth()->id(), | ||
noteText: $request->input('note'), | ||
))->execute(); | ||
|
||
Cache::forget('user-favorites-' . auth()->id()); | ||
Cache::forget('user-favorites-details-' . auth()->id()); | ||
|
||
return view('components.note-show', [ | ||
'note' => $name->getNoteForUser(), | ||
'url' => route('user.name.edit', [ | ||
'id' => $name->id, | ||
]), | ||
'deleteUrl' => route('user.name.destroy', [ | ||
'id' => $name->id, | ||
]), | ||
]); | ||
} | ||
|
||
public function destroy(Request $request): View | ||
{ | ||
$name = $request->attributes->get('name'); | ||
|
||
(new DestroyNote( | ||
userId: auth()->id(), | ||
nameId: $name->id, | ||
))->execute(); | ||
|
||
Cache::forget('user-favorites-' . auth()->id()); | ||
Cache::forget('user-favorites-details-' . auth()->id()); | ||
|
||
return view('components.note-show', [ | ||
'note' => $name->getNoteForUser(), | ||
'url' => route('user.name.edit', [ | ||
'id' => $name->id, | ||
]), | ||
'deleteUrl' => route('user.name.destroy', [ | ||
'id' => $name->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
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
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\Services; | ||
|
||
use App\Models\Note; | ||
|
||
class DestroyNote extends BaseService | ||
{ | ||
private Note $note; | ||
|
||
public function __construct( | ||
public int $userId, | ||
public int $nameId, | ||
) { | ||
} | ||
|
||
public function execute(): void | ||
{ | ||
$this->check(); | ||
} | ||
|
||
private function check(): void | ||
{ | ||
$this->note = Note::where([ | ||
'name_id' => $this->nameId, | ||
'user_id' => $this->userId, | ||
])->firstOrFail(); | ||
|
||
$this->note->delete(); | ||
} | ||
} |
Oops, something went wrong.