Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions shared/Commands/CommentCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Shared\Services\CommentService;
use Quantum\Console\QtCommand;
use Quantum\Validation\Rule;
use Shared\DTOs\CommentDTO;
use ReflectionException;

/**
Expand Down Expand Up @@ -76,11 +77,13 @@ public function exec(): void
return;
}

service(CommentService::class)->addComment([
'post_uuid' => $this->getArgument('post_uuid'),
'user_uuid' => $this->getArgument('user_uuid'),
'content' => $this->getArgument('content'),
]);
$commentDto = new CommentDTO(
$this->getArgument('post_uuid'),
$this->getArgument('user_uuid'),
trim($this->getArgument('content'))
);

service(CommentService::class)->addComment($commentDto);

$this->info('Comment created successfully');
}
Expand Down
17 changes: 10 additions & 7 deletions shared/Commands/PostCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Shared\Services\PostService;
use Quantum\Console\QtCommand;
use Quantum\Validation\Rule;
use Shared\DTOs\PostDTO;
use ReflectionException;

/**
Expand Down Expand Up @@ -79,13 +80,15 @@ public function exec(): void
return;
}

service(PostService::class)->addPost([
'uuid' => $this->getArgument('uuid'),
'user_uuid' => $this->getArgument('user_uuid'),
'title' => $this->getArgument('title'),
'content' => $this->getArgument('description'),
'image' => $this->getArgument('image'),
]);
$postDto = new PostDTO(
$this->getArgument('title'),
$this->getArgument('description'),
$this->getArgument('user_uuid'),
$this->getArgument('image') ?? '',
$this->getArgument('uuid')
);

service(PostService::class)->addPost($postDto);

$this->info('Post created successfully');
}
Expand Down
15 changes: 8 additions & 7 deletions shared/Commands/PostUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Shared\Services\PostService;
use Quantum\Console\QtCommand;
use Quantum\Validation\Rule;
use Shared\DTOs\PostDTO;
use ReflectionException;

/**
Expand Down Expand Up @@ -96,14 +97,14 @@ public function exec(): void
return;
}

$postData = [
'title' => $this->getOption('title') ?: $post->title,
'content' => $this->getOption('description') ?: $post->content,
'image' => $this->getOption('image') ?: $post->image ?? '',
'updated_at' => date('Y-m-d H:i:s')
];
$postDto = new PostDTO(
$this->getOption('title') ?: $post->title,
$this->getOption('description') ?: $post->content,
null,
$this->getOption('image') ?: $post->image ?? ''
);

$postService->updatePost($postId, $postData);
$postService->updatePost($postId, $postDto);

$this->info('Post updated successfully');
}
Expand Down
21 changes: 12 additions & 9 deletions shared/Commands/UserCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Quantum\Console\QtCommand;
use Quantum\Validation\Rule;
use Quantum\Hasher\Hasher;
use Shared\DTOs\UserDTO;
use ReflectionException;
use Shared\Models\User;

Expand Down Expand Up @@ -88,15 +89,17 @@ public function exec(): void
return;
}

service(AuthService::class)->add([
'uuid' => $this->getArgument('uuid'),
'firstname' => $this->getArgument('firstname'),
'lastname' => $this->getArgument('lastname'),
'role' => $this->getArgument('role'),
'email' => $this->getArgument('email'),
'password' => (new Hasher())->hash($this->getArgument('password')),
'image' => $this->getArgument('image'),
]);
$userDto = new UserDTO(
$this->getArgument('email'),
(new Hasher())->hash($this->getArgument('password')),
$this->getArgument('firstname'),
$this->getArgument('lastname'),
$this->getArgument('role') ?? '',
$this->getArgument('uuid'),
$this->getArgument('image') ?? ''
);

service(AuthService::class)->add($userDto->toArray());

$this->info('User created successfully');
}
Expand Down
92 changes: 92 additions & 0 deletions shared/DTOs/CommentDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

/**
* Quantum PHP Framework
*
* An open source software development framework for PHP
*
* @package Quantum
* @author Arman Ag. <arman.ag@softberg.org>
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
* @link http://quantum.softberg.org/
* @since 3.0.0
*/

namespace Shared\DTOs;

use Quantum\Http\Request;

/**
* Class CommentDTO
* @package Shared\DTOs
*/
class CommentDTO
{
/**
* @var string
*/
private string $postUuid;

/**
* @var string
*/
private string $userUuid;

/**
* @var string
*/
private string $content;

/**
* @param string $postUuid
* @param string $userUuid
* @param string $content
*/
public function __construct(
string $postUuid,
string $userUuid,
string $content
) {
$this->postUuid = $postUuid;
$this->userUuid = $userUuid;
$this->content = $content;
}

/**
* @param Request $request
* @param string $postUuid
* @param string $userUuid
* @return self
*/
public static function fromRequest(Request $request, string $postUuid, string $userUuid): self
{
return new self($postUuid, $userUuid, trim((string)$request->get('content')));
}

public function getPostUuid(): string
{
return $this->postUuid;
}

public function getUserUuid(): string
{
return $this->userUuid;
}

public function getContent(): string
{
return $this->content;
}

/**
* @return array
*/
public function toArray(): array
{
return [
'post_uuid' => $this->postUuid,
'user_uuid' => $this->userUuid,
'content' => $this->content,
];
}
}
127 changes: 127 additions & 0 deletions shared/DTOs/PostDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

/**
* Quantum PHP Framework
*
* An open source software development framework for PHP
*
* @package Quantum
* @author Arman Ag. <arman.ag@softberg.org>
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
* @link http://quantum.softberg.org/
* @since 3.0.0
*/

namespace Shared\DTOs;

use Quantum\Http\Request;

/**
* Class PostDTO
* @package Shared\DTOs
*/
class PostDTO
{
/**
* @var string
*/
private string $title;

/**
* @var string
*/
private string $content;

/**
* @var string|null
*/
private ?string $userUuid;

/**
* @var string|null
*/
private ?string $image;

/**
* @var string|null
*/
private ?string $uuid;

/**
* @param string $title
* @param string $content
* @param string|null $userUuid
* @param string|null $image
* @param string|null $uuid
*/
public function __construct(
string $title,
string $content,
?string $userUuid = null,
?string $image = null,
?string $uuid = null
) {
$this->title = $title;
$this->content = $content;
$this->userUuid = $userUuid;
$this->image = $image;
$this->uuid = $uuid;
}

/**
* @param Request $request
* @param string|null $userUuid
* @param string|null $image
* @return self
*/
public static function fromRequest(Request $request, ?string $userUuid = null, ?string $image = null): self
{
return new self(
$request->get('title', null, true),
$request->get('content', null, true),
$userUuid,
$image
);
}

public function getTitle(): string
{
return $this->title;
}

public function getContent(): string
{
return $this->content;
}

public function getUserUuid(): ?string
{
return $this->userUuid;
}

public function getImage(): ?string
{
return $this->image;
}

public function getUuid(): ?string
{
return $this->uuid;
}

/**
* @return array
*/
public function toArray(): array
{
return array_filter([
'uuid' => $this->uuid,
'user_uuid' => $this->userUuid,
'title' => $this->title,
'content' => $this->content,
'image' => $this->image,
], function ($value) {
return $value !== null;
});
}
}
Loading
Loading