Skip to content

Commit

Permalink
Merge pull request #1442 from bakaphp/KA-207
Browse files Browse the repository at this point in the history
feat: tag
  • Loading branch information
kaioken authored Jun 8, 2024
2 parents ba1b8c7 + 792a41f commit 63390c7
Show file tree
Hide file tree
Showing 20 changed files with 836 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use Kanvas\Apps\Repositories\AppsRepository;
use Kanvas\Connectors\Notifications\Jobs\MailCaddieLabJob;
use Kanvas\Guild\Customers\Repositories\PeoplesRepository;

class MailCaddieLabCommand extends Command
{
Expand All @@ -13,9 +14,21 @@ class MailCaddieLabCommand extends Command
public function handle()
{
$this->info('Sending internal mail to Caddie Lab');
//dump($this->argument('email'));

$app = AppsRepository::findFirstByKey($this->argument('apps_id'));
$email = $this->argument('email');
MailCaddieLabJob::dispatch($app, $email);

$peoplesIn7Days = PeoplesRepository::getByDaysCreated(7, $app);
$peoplesIn28Days = PeoplesRepository::getByDaysCreated(28, $app);

$this->info('We will be sending email to ' . count($peoplesIn7Days) . ' people that have been created in the last 7 days');
$this->info('We will be sending email to ' . count($peoplesIn28Days) . ' people that have been created in the last 28 days');

if ($this->confirm('Are you sure you want to send this email?')) {
MailCaddieLabJob::dispatch($app, $email);
$this->info('Emails have been dispatched.');
} else {
$this->info('Email sending has been canceled.');
}
}
}
101 changes: 101 additions & 0 deletions app/GraphQL/Social/Mutations/Tags/TagsManagement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare(strict_types=1);

namespace App\GraphQL\Social\Mutations\Tags;

use Kanvas\Apps\Models\Apps;
use Kanvas\Social\Follows\Actions\FollowAction;
use Kanvas\Social\Follows\Actions\UnFollowAction;
use Kanvas\Social\Follows\Repositories\UsersFollowsRepository;
use Kanvas\Social\Tags\Actions\CreateTagAction;
use Kanvas\Social\Tags\DataTransferObjects\Tag as TagData;
use Kanvas\Social\Tags\Models\Tag;
use Kanvas\SystemModules\DataTransferObject\SystemModuleEntityInput;
use Kanvas\SystemModules\Models\SystemModules;
use Kanvas\SystemModules\Repositories\SystemModulesRepository;

class TagsManagement
{
public function create(mixed $root, array $request): Tag
{
$request['input']['app'] = app(Apps::class);
$request['input']['user'] = auth()->user();
$request['input']['company'] = auth()->user()->getCurrentCompany();

$dto = TagData::from($request['input']);

return (new CreateTagAction($dto))->execute();
}

public function update(mixed $root, array $request): Tag
{
$app = app(Apps::class);

$tag = Tag::when(! auth()->user()->isAdmin(), function ($query) {
return $query->where('users_id', auth()->user()->getId());
})->where('id', $request['id'])
->fromApp($app)
->firstOrFail();

$tag->update($request['input']);

return $tag;
}

public function delete(mixed $root, array $request): bool
{
$app = app(Apps::class);
$tag = Tag::when(! auth()->user()->isAdmin(), function ($query) {
return $query->where('users_id', auth()->user()->getId());
})
->where('id', $request['id'])
->fromApp($app)
->firstOrFail();


return $tag->delete();
}

public function follow(mixed $root, array $request): bool
{
$app = app(Apps::class);
$tag = Tag::getById($request['id'], $app);
$isFollowing = UsersFollowsRepository::isFollowing(auth()->user(), $tag);
if ($isFollowing) {
return (new UnFollowAction(auth()->user(), $tag))->execute();
} else {
return (bool)(new FollowAction(auth()->user(), $tag))->execute();
}
}

public function attachTagToEntity(mixed $root, array $request): bool
{
$app = app(Apps::class);
$tag = Tag::getById($request['input']['tag_id'], $app);
$user = auth()->user();

$systemModule = SystemModules::getByUuid($request['input']['system_module_uuid'], $app);

//$entity = $systemModule->model_name::getById((int)$request['input']['entity_id'], $app);
$entity = SystemModulesRepository::getEntityFromInput(
new SystemModuleEntityInput(
$systemModule->name,
$systemModule->uuid,
$request['input']['entity_id']
),
$user,
useCompanyReference: false
);

$tag->entities()->attach($entity->getId(), [
'entity_namespace' => $systemModule->model_name,
'apps_id' => $tag->apps_id,
'companies_id' => $user->getCurrentCompany()->getId(),
'users_id' => $user->getId(),
'taggable_type' => $systemModule->model_name,
]);

return true;
}
}
25 changes: 25 additions & 0 deletions app/GraphQL/Social/Queries/Tags/TagsQueries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\GraphQL\Social\Queries\Tags;

use Baka\Enums\StateEnums;
use Kanvas\Apps\Models\Apps;
use Kanvas\Social\Tags\Models\Tag;
use Kanvas\SystemModules\Repositories\SystemModulesRepository;

class TagsQueries
{
public function getTagsBuilder(mixed $root, array $args): mixed
{
$app = app(Apps::class);
$systemModule = SystemModulesRepository::getByModelName($root::class, $app);

return Tag::whereHas('taggables', function ($query) use ($root, $systemModule) {
$query->where('entity_id', $root->getKey());
$query->where('entity_namespace', $systemModule->model_name);
$query->where('apps_id', $systemModule->apps_id);
})->where('is_deleted', StateEnums::NO->getValue());
}
}
37 changes: 37 additions & 0 deletions database/migrations/Social/2024_06_05_154618_tags_entities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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('tags_entities', function (Blueprint $table) {
$table->id();
$table->integer('tags_id')->index();
$table->integer('entity_id')->index();
$table->string('entity_namespace')->index();
$table->integer('companies_id')->index();
$table->integer('apps_id')->index();
$table->integer('users_id')->index();
$table->boolean('is_deleted')->default(0);
$table->timestamp('created_at')->index()->useCurrent();
$table->datetime('updated_at')->nullable()->index();
$table->index(['tags_id', 'entity_id', 'is_deleted'], 'tags_entities_index_tag');
$table->index(['tags_id', 'entity_id', 'apps_id', 'is_deleted'], 'tags_entities_app_index');
$table->index(['tags_id', 'entity_id', 'companies_id', 'apps_id', 'is_deleted'], 'tags_entities_index');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tags_entities');
}
};
27 changes: 27 additions & 0 deletions database/migrations/Social/2024_06_05_172750_taggable_type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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::table('tags_entities', function (Blueprint $table) {
$table->string('taggable_type')->nullable()->after('entity_id');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('tags_entities', function (Blueprint $table) {
$table->dropColumn('taggable_type');
});
}
};
2 changes: 1 addition & 1 deletion database/seeders/SystemModuleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function run()
[
'name' => 'Companies',
'slug' => 'companies',
'model_name' => 'Kanvas\\Models\\Companies',
'model_name' => 'Kanvas\\Companies\\Models\\Companies',
'uuid' => (string) Str::uuid(),
'apps_id' => '1',
'parents_id' => '0',
Expand Down
5 changes: 5 additions & 0 deletions graphql/schemas/Guild/lead.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ type Lead {
participants: [LeadsParticipants!]! @hasMany
channels: [SocialChannel]! @hasMany(relation: "socialChannels")
systemModule: SystemModule
tags: [Tag!]
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Social\\Queries\\Tags\\TagsQueries@getTagsBuilder"
)
files: [Filesystem!]!
@paginate(
defaultCount: 25
Expand Down
30 changes: 18 additions & 12 deletions graphql/schemas/Guild/organization.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ type Organization {
user: User! @belongsTo
name: String!
address: String
tags: [Tag!]
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Social\\Queries\\Tags\\TagsQueries@getTagsBuilder"
)
}

input OrganizationInput {
Expand All @@ -19,13 +24,21 @@ input OrganizationPeopleInput {

extend type Mutation @guard {
createOrganization(input: OrganizationInput!): Organization
@field(resolver: "App\\GraphQL\\Guild\\Mutations\\Organizations\\OrganizationManagementMutation@create")
@field(
resolver: "App\\GraphQL\\Guild\\Mutations\\Organizations\\OrganizationManagementMutation@create"
)
updateOrganization(id: ID!, input: OrganizationInput!): Organization
@field(resolver: "App\\GraphQL\\Guild\\Mutations\\Organizations\\OrganizationManagementMutation@update")
@field(
resolver: "App\\GraphQL\\Guild\\Mutations\\Organizations\\OrganizationManagementMutation@update"
)
deleteOrganization(id: ID!): Boolean
@field(resolver: "App\\GraphQL\\Guild\\Mutations\\Organizations\\OrganizationManagementMutation@delete")
@field(
resolver: "App\\GraphQL\\Guild\\Mutations\\Organizations\\OrganizationManagementMutation@delete"
)
restoreOrganization(id: ID!): Boolean
@field(resolver: "App\\GraphQL\\Guild\\Mutations\\Organizations\\OrganizationManagementMutation@restore")
@field(
resolver: "App\\GraphQL\\Guild\\Mutations\\Organizations\\OrganizationManagementMutation@restore"
)
addPeopleToOrganization(input: OrganizationPeopleInput!): Boolean!
@field(
resolver: "App\\GraphQL\\Guild\\Mutations\\Organizations\\PeopleOrganizationMutation@add"
Expand All @@ -38,14 +51,7 @@ extend type Mutation @guard {

extend type Query @guard {
organizations(
where: _
@whereConditions(
columns: [
"id"
"name"
"uuid"
]
)
where: _ @whereConditions(columns: ["id", "name", "uuid"])
orderBy: _ @orderBy(columns: ["id", "created_at", "updated_at", "name"])
): [Organization!]!
@paginate(
Expand Down
5 changes: 5 additions & 0 deletions graphql/schemas/Guild/people.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ type People {
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\CustomFields\\CustomFieldQuery@getAllByGraphType"
)
tags: [Tag!]
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Social\\Queries\\Tags\\TagsQueries@getTagsBuilder"
)
}

type PeopleRelationship {
Expand Down
5 changes: 5 additions & 0 deletions graphql/schemas/Inventory/product.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ type Product {
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\CustomFields\\CustomFieldQuery@getAllByGraphType"
)
tags: [Tag!]
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Social\\Queries\\Tags\\TagsQueries@getTagsBuilder"
)
}

input ProductInput {
Expand Down
2 changes: 1 addition & 1 deletion graphql/schemas/Social/channels.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type SocialChannel {
last_message_id: ID
messages: [Message!]! @belongsToMany
users: [User!]! @belongsToMany
systemModule: SystemModule!
systemModule: SystemModule! @belongsTo
}

input SocialChannelInput {
Expand Down
6 changes: 6 additions & 0 deletions graphql/schemas/Social/message.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ type Message {
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\CustomFields\\CustomFieldQuery@getAllByGraphType"
)
tags: [Tag!]
@paginate
(
defaultCount: 25
builder: "App\\GraphQL\\Social\\Queries\\Tags\\TagsQueries@getTagsBuilder"
)
}

type AppModuleMessage {
Expand Down
Loading

0 comments on commit 63390c7

Please sign in to comment.