-
Notifications
You must be signed in to change notification settings - Fork 3
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
11 changed files
with
469 additions
and
72 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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\GraphQL\Social\Builders\UsersLists; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use Kanvas\Apps\Models\Apps; | ||
use Kanvas\Social\UsersLists\Models\UserList as ModelUserList; | ||
use Laravel\Scout\Builder as ScoutBuilder; | ||
|
||
class SearchBuilder | ||
{ | ||
/** | ||
* Build the search query. | ||
* | ||
* @param string $search | ||
*/ | ||
public function search(mixed $builder, mixed $req): Builder|ScoutBuilder | ||
{ | ||
$search = ModelUserList::search($req['search']) | ||
->where('is_public', 1) | ||
->where('apps_id', app(Apps::class)->id); | ||
|
||
return $search; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
app/GraphQL/Social/Mutations/UsersLists/UsersListsManagement.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,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\GraphQL\Social\Mutations\UsersLists; | ||
|
||
use Exception; | ||
use Kanvas\Apps\Models\Apps; | ||
use Kanvas\Social\Messages\Models\Message; | ||
use Kanvas\Social\UsersLists\Actions\CreateUserListAction; | ||
use Kanvas\Social\UsersLists\DataTransferObject\UserList; | ||
use Kanvas\Social\UsersLists\Models\UserList as ModelUserList; | ||
use Kanvas\Social\UsersLists\Repositories\UserListRepository; | ||
|
||
class UsersListsManagement | ||
{ | ||
public function create($rootValue, array $req): ModelUserList | ||
{ | ||
$userList = new UserList( | ||
app(Apps::class)->id, | ||
auth()->user()->getCurrentCompany()->id, | ||
auth()->user()->id, | ||
$req['input']['name'], | ||
$req['input']['description'], | ||
$req['input']['is_public'], | ||
$req['input']['is_default'] | ||
); | ||
|
||
$createUserList = new CreateUserListAction($userList); | ||
|
||
return $createUserList->execute(); | ||
} | ||
|
||
public function update(mixed $rootValue, array $req): ModelUserList | ||
{ | ||
$userList = UserListRepository::getById($req['id'], auth()->user()); | ||
|
||
$userList->update($req['input']); | ||
|
||
return $userList; | ||
} | ||
|
||
/** | ||
* delete | ||
*/ | ||
public function delete(mixed $rootValue, array $req): bool | ||
{ | ||
$userList = UserListRepository::getById($req['id'], auth()->user()); | ||
|
||
return $userList->delete(); | ||
} | ||
|
||
public function addToList(mixed $rootValue, array $req): bool | ||
{ | ||
$userList = UserListRepository::getById($req['users_lists_id'], auth()->user()); | ||
$message = Message::getById($req['messages_id']); | ||
|
||
try { | ||
$userList->items()->attach($message); | ||
|
||
return true; | ||
} catch (Exception $e) { | ||
throw new Exception($e->getMessage()); | ||
} | ||
|
||
|
||
return false; | ||
} | ||
|
||
public function removeFromList(mixed $rootValue, array $req): bool | ||
{ | ||
$userList = UserListRepository::getById($req['users_lists_id'], auth()->user()); | ||
$message = Message::getById($req['messages_id']); | ||
|
||
try { | ||
$userList->items()->detach($message); | ||
|
||
return true; | ||
} catch (Exception $e) { | ||
throw new Exception($e->getMessage()); | ||
} | ||
|
||
return false; | ||
} | ||
} |
Oops, something went wrong.