Skip to content

Commit

Permalink
Rename UserID class
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanlopezinc committed Nov 2, 2023
1 parent 3b4f00b commit 3d0eb9a
Show file tree
Hide file tree
Showing 28 changed files with 54 additions and 57 deletions.
4 changes: 2 additions & 2 deletions app/Exceptions/BookmarkNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace App\Exceptions;

use App\Models\Bookmark;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use RuntimeException;
Expand All @@ -29,7 +29,7 @@ public function report(): void
*/
public static function throwIfDoesNotBelongToAuthUser(Bookmark $bookmark): void
{
if ($bookmark->user_id !== UserID::fromAuthUser()->value()) {
if ($bookmark->user_id !== UserId::fromAuthUser()->value()) {
throw new self;
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/Exceptions/FolderNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace App\Exceptions;

use App\Models\Folder;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use RuntimeException;
Expand All @@ -29,7 +29,7 @@ public function report(): void
*/
public static function throwIfDoesNotBelongToAuthUser(Folder $folder): void
{
if ($folder->user_id !== UserID::fromAuthUser()->value()) {
if ($folder->user_id !== UserId::fromAuthUser()->value()) {
throw new self;
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/AddEmailToAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Models\SecondaryEmail;
use App\Models\User;
use App\Services\AddEmailToAccountService as Service;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
Expand All @@ -26,7 +26,7 @@ public function __invoke(Request $request, Service $service): JsonResponse
]
]);

$service(UserID::fromAuthUser()->value(), $request->input('email'));
$service(UserId::fromAuthUser()->value(), $request->input('email'));

return response()->json();
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/FetchUserProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use App\Models\User;
use App\Http\Resources\UserResource;
use App\Repositories\UserRepository;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;

final class FetchUserProfileController
{
public function __invoke(UserRepository $repository): UserResource
{
/** @var User */
$user = $repository->findByID(UserID::fromAuthUser()->value());
$user = $repository->findByID(UserId::fromAuthUser()->value());

return new UserResource($user);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/VerifySecondaryEmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use App\Rules\TwoFACodeRule;
use App\Services\VerifySecondaryEmailService as Service;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use App\ValueObjects\TwoFACode;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
Expand All @@ -21,7 +21,7 @@ public function __invoke(Request $request, Service $service): JsonResponse
]);

$service->verify(
UserID::fromAuthUser()->value(),
UserId::fromAuthUser()->value(),
$request->input('email'),
TwoFACode::fromString($request->input('verification_code'))
);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/DeleteFavoriteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Exceptions\BookmarkNotFoundException;
use App\Models\Favorite;
use App\Rules\ResourceIdRule;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
Expand All @@ -21,7 +21,7 @@ public function __invoke(Request $request): JsonResponse
'bookmarks.*' => [new ResourceIdRule(), 'distinct:strict'],
]);

Favorite::where('user_id', UserID::fromAuthUser()->value())
Favorite::where('user_id', UserId::fromAuthUser()->value())
->whereIntegerInRaw('bookmark_id', $bookmarkIds = $request->input('bookmarks'))
->get(['bookmark_id', 'id'])
->tap(function (Collection $favorites) use ($bookmarkIds) {
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/FetchDuplicateBookmarksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\PaginationData;
use App\Repositories\BookmarkRepository;
use App\Rules\ResourceIdRule;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use Illuminate\Http\Request;

final class FetchDuplicateBookmarksController
Expand All @@ -28,7 +28,7 @@ public function __invoke(Request $request, BookmarkRepository $repository): Reso

$result = $repository->fetchPossibleDuplicates(
$bookmark,
UserID::fromAuthUser()->value(),
UserId::fromAuthUser()->value(),
PaginationData::fromRequest($request)
);

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/FetchUserCollaborationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\Http\Resources\PaginatedResourceCollection as ResourceCollection;
use App\Http\Resources\FilterUserCollaborationResource;
use App\Rules\UserCollaborationFieldsRule;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;

final class FetchUserCollaborationsController
{
Expand All @@ -22,7 +22,7 @@ public function __invoke(Request $request, Repository $repository): ResourceColl
]);

$result = $repository->get(
UserID::fromAuthUser()->value(),
UserId::fromAuthUser()->value(),
PaginationData::fromRequest($request),
);

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/FetchUserFavoritesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\Jobs\CheckBookmarksHealth;
use App\PaginationData;
use App\Repositories\FavoriteRepository as Repository;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use Illuminate\Http\Request;

final class FetchUserFavoritesController
Expand All @@ -18,7 +18,7 @@ public function __invoke(Request $request, Repository $repository): PaginatedRes
{
$request->validate(PaginationData::new()->asValidationRules());

$userFavorites = $repository->get(UserID::fromAuthUser()->value(), PaginationData::fromRequest($request));
$userFavorites = $repository->get(UserId::fromAuthUser()->value(), PaginationData::fromRequest($request));

dispatch(new CheckBookmarksHealth($userFavorites->getCollection()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use App\Repositories\Folder\FetchUserFoldersWhereContainsCollaboratorRepository as Repository;
use App\Rules\ResourceIdRule;
use App\Rules\UserCollaborationFieldsRule;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;

final class FetchUserFoldersWhereContainsCollaboratorController
{
Expand All @@ -24,7 +24,7 @@ public function __invoke(Request $request, Repository $repository): ResourceColl
]);

$result = $repository->get(
UserID::fromAuthUser()->value(),
UserId::fromAuthUser()->value(),
$request->integer('collaborator_id'),
PaginationData::fromRequest($request),
);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/FetchUserNotificationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Http\Resources\PaginatedResourceCollection;
use App\PaginationData;
use App\Repositories\NotificationRepository;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use Illuminate\Http\Request;

final class FetchUserNotificationsController
Expand All @@ -20,7 +20,7 @@ public function __invoke(Request $request, NotificationRepository $repository):
]);

return new PaginatedResourceCollection(
$repository->unread(UserID::fromAuthUser()->value(), PaginationData::fromRequest($request)),
$repository->unread(UserId::fromAuthUser()->value(), PaginationData::fromRequest($request)),
NotificationResource::class
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/FetchUserTagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Http\Resources\TagResource;
use App\PaginationData;
use App\Repositories\TagRepository;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use Illuminate\Http\Request;

final class FetchUserTagsController
Expand All @@ -18,7 +18,7 @@ public function __invoke(Request $request, TagRepository $repository): Paginated
$request->validate(PaginationData::new()->maxPerPage(50)->asValidationRules());

return new PaginatedResourceCollection(
$repository->getUserTags(UserID::fromAuthUser()->value(), PaginationData::fromRequest($request)),
$repository->getUserTags(UserId::fromAuthUser()->value(), PaginationData::fromRequest($request)),
TagResource::class
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Folder/FetchUserFoldersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use App\PaginationData;
use App\Repositories\Folder\UserFoldersRepository;
use App\Rules\FolderFieldsRule;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;

final class FetchUserFoldersController
{
Expand All @@ -23,7 +23,7 @@ public function __invoke(FetchUserFoldersRequest $request, UserFoldersRepository
]);

$result = $repository->fetch(
UserID::fromAuthUser()->value(),
UserId::fromAuthUser()->value(),
PaginationData::fromRequest($request),
UserFoldersSortCriteria::fromRequest($request)
);
Expand Down
2 changes: 0 additions & 2 deletions app/Repositories/Folder/FolderPermissionsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace App\Repositories\Folder;

use App\Models\BannedCollaborator;
use App\Models\FolderCollaboratorPermission;
use App\UAC;
use App\Models\FolderPermission;
use App\ValueObjects\UserID;
use Illuminate\Support\Collection;

final class FolderPermissionsRepository
Expand Down
4 changes: 2 additions & 2 deletions app/Services/CreateBookmarkService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace App\Services;

use App\ValueObjects\Url;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use App\Http\Requests\CreateOrUpdateBookmarkRequest;
use App\Jobs\UpdateBookmarkWithHttpResponse;
use App\Models\Bookmark;
Expand All @@ -29,7 +29,7 @@ public function fromRequest(CreateOrUpdateBookmarkRequest $request): void
$data = [
'url' => new Url($request->validated('url')),
'createdOn' => (string)now(),
'userID' => UserID::fromAuthUser()->value(),
'userID' => UserId::fromAuthUser()->value(),
'tags' => $request->validated('tags', new MissingValue()),
'title' => $request->validated('title', new MissingValue()),
'description' => $request->input('description', new MissingValue()),
Expand Down
4 changes: 2 additions & 2 deletions app/Services/CreateFavoriteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\Models\Bookmark;
use App\Repositories\FavoriteRepository;
use App\Repositories\BookmarkRepository;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;

final class CreateFavoriteService
{
Expand All @@ -25,7 +25,7 @@ public function __construct(
*/
public function create(array $bookmarkIDs): void
{
$userId = UserID::fromAuthUser();
$userId = UserId::fromAuthUser();

$bookmarks = $this->bookmarkRepository->findManyById($bookmarkIDs, ['user_id', 'id', 'url']);

Expand Down
4 changes: 2 additions & 2 deletions app/Services/FetchUserBookmarksService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Models\Bookmark as Model;
use App\Models\Favorite;
use App\PaginationData;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\Paginator;
use App\Http\Requests\FetchUserBookmarksRequest as Request;
Expand All @@ -23,7 +23,7 @@ public function fromRequest(Request $request): Paginator
$model = new Model;

$query = Model::WithQueryOptions()
->where('user_id', UserID::fromAuthUser()->value())
->where('user_id', UserId::fromAuthUser()->value())
->addSelect([
'isUserFavorite' => Favorite::query()
->select('id')
Expand Down
6 changes: 3 additions & 3 deletions app/Services/Folder/AddBookmarksToFolderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\Exceptions\BookmarkNotFoundException;
use App\Exceptions\FolderNotFoundException;
use App\Repositories\BookmarkRepository;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use App\Exceptions\HttpException as HttpException;
use App\Http\Requests\AddBookmarksToFolderRequest as Request;
use App\Jobs\CheckBookmarksHealth;
Expand All @@ -34,7 +34,7 @@ public function __construct(

public function fromRequest(Request $request): void
{
$authUserId = UserID::fromAuthUser()->value();
$authUserId = UserId::fromAuthUser()->value();
$folderId = $request->integer('folder');
$bookmarkIds = $request->collect('bookmarks')->map(fn (string $id) => (int) $id)->all();

Expand Down Expand Up @@ -142,7 +142,7 @@ private function ensureFolderDoesNotContainBookmarks(int $folderID, array $bookm

private function notifyFolderOwner(array $bookmarkIDs, Folder $folder): void
{
$collaboratorID = UserID::fromAuthUser()->value();
$collaboratorID = UserId::fromAuthUser()->value();

$settings = FolderSettings::fromQuery($folder->settings);

Expand Down
4 changes: 2 additions & 2 deletions app/Services/Folder/CreateFolderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\Http\Requests\CreateOrUpdateFolderRequest as Request;
use App\Models\Folder;
use App\Models\FolderSetting;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use Illuminate\Support\Collection;

final class CreateFolderService
Expand All @@ -20,7 +20,7 @@ public function __invoke(Request $request): void
$folder = Folder::create([
'description' => $request->validated('description'),
'name' => $request->validated('name'),
'user_id' => UserID::fromAuthUser()->value(),
'user_id' => UserId::fromAuthUser()->value(),
'visibility' => (string) FolderVisibility::fromRequest($request)->value,
]);

Expand Down
4 changes: 2 additions & 2 deletions app/Services/Folder/GrantPermissionsToCollaboratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\Exceptions\HttpException;
use App\Repositories\Folder\FolderPermissionsRepository;
use App\UAC;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;

final class GrantPermissionsToCollaboratorService
{
Expand All @@ -26,7 +26,7 @@ public function grant(int $collaboratorId, int $folderId, UAC $permissions): voi

FolderNotFoundException::throwIfDoesNotBelongToAuthUser($folder);

$this->ensureIsNotGrantingPermissionsToSelf($collaboratorId, UserID::fromAuthUser()->value());
$this->ensureIsNotGrantingPermissionsToSelf($collaboratorId, UserId::fromAuthUser()->value());

$this->ensureUserIsCurrentlyACollaborator($currentPermissions);

Expand Down
4 changes: 2 additions & 2 deletions app/Services/Folder/LeaveFolderCollaborationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use App\Repositories\Folder\FolderPermissionsRepository;
use App\Repositories\NotificationRepository;
use App\UAC;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;

final class LeaveFolderCollaborationService
{
Expand All @@ -28,7 +28,7 @@ public function leave(int $folderID): void
$folder = $this->folderRepository->find($folderID, ['id', 'user_id', 'settings']);

$collaboratorPermissions = $this->permissionsRepository->getUserAccessControls(
$collaboratorID = UserID::fromAuthUser()->value(),
$collaboratorID = UserId::fromAuthUser()->value(),
$folderID
);

Expand Down
4 changes: 2 additions & 2 deletions app/Services/Folder/RemoveBookmarksFromFolderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use App\Models\Folder;
use App\Models\FolderBookmark;
use App\Repositories\Folder\FolderPermissionsRepository;
use App\ValueObjects\UserID;
use App\ValueObjects\UserId;
use App\Notifications\BookmarksRemovedFromFolderNotification as Notification;
use App\Repositories\NotificationRepository;
use Illuminate\Database\Eloquent\Collection;
Expand All @@ -28,7 +28,7 @@ public function __construct(

public function remove(array $bookmarkIDs, int $folderID): void
{
$authUserId = UserID::fromAuthUser()->value();
$authUserId = UserId::fromAuthUser()->value();

$folder = $this->repository->find($folderID, ['id', 'user_id', 'settings', 'updated_at']);

Expand Down
Loading

0 comments on commit 3d0eb9a

Please sign in to comment.