Skip to content

Commit

Permalink
feat: users lists messages
Browse files Browse the repository at this point in the history
  • Loading branch information
FredPeal committed Jun 16, 2023
1 parent 99730a4 commit 8604db9
Show file tree
Hide file tree
Showing 11 changed files with 469 additions and 72 deletions.
27 changes: 27 additions & 0 deletions app/GraphQL/Social/Builders/UsersLists/SearchBuilder.php
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 app/GraphQL/Social/Mutations/UsersLists/UsersListsManagement.php
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;
}
}
Loading

0 comments on commit 8604db9

Please sign in to comment.