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
14 changes: 7 additions & 7 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/app/Common/Application/Dto/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Pagination
public function __construct(
private array $data,
private ?int $currentPage = null,
private ?string $from = null,
private ?string $to = null,
private ?int $from = null,
private ?int $to = null,
private ?int $perPage = null,
private ?string $path = null,
private ?int $lastPage = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace App\Post\Application\ApplicationTest;

use Tests\TestCase;
use App\Post\Application\Dto\GetAllUserPostDtoCollection;

class GetAllUserPostDtoCollectionTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
}

protected function tearDown(): void
{
parent::tearDown();
}

private function arrayRequestData(): array
{
return [
[
'id' => 1,
'userId' => 2,
'content' => 'Sample post content',
'mediaPath' => 'path/to/media.jpg',
'visibility' => 'public',
],
[
'id' => 2,
'userId' => 3,
'content' => 'Another post content',
'mediaPath' => 'path/to/another_media.jpg',
'visibility' => 'private',
],
];
}

public function test_get_all_user_post_dto_collection(): void
{
$data = $this->arrayRequestData();
$dtoCollection = GetAllUserPostDtoCollection::build($data);

$this->assertInstanceOf(GetAllUserPostDtoCollection::class, $dtoCollection);
}

public function test_get_all_user_post_dto_collection_values(): void
{
$data = $this->arrayRequestData();
$dtoCollection = GetAllUserPostDtoCollection::build($data);

$this->assertCount(count($data), $dtoCollection->getPosts());

foreach ($data as $index => $item) {
$dto = $dtoCollection->getPosts()[$index];
$this->assertEquals($dto->id, $item['id']);
$this->assertEquals($dto->userId, $item['userId']);
$this->assertEquals($dto->content, $item['content']);
$this->assertEquals($dto->mediaPath, $item['mediaPath']);
$this->assertEquals($dto->visibility, $item['visibility']);
}
}
}
50 changes: 50 additions & 0 deletions src/app/Post/Application/ApplicationTest/GetAllUserPostDtoTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Post\Application\ApplicationTest;

use Tests\TestCase;
use App\Post\Application\Dto\GetAllUserPostDto;

class GetAllUserPostDtoTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
}

protected function tearDown(): void
{
parent::tearDown();
}

private function arrayRequestData(): array
{
return [
'id' => 1,
'userId' => 2,
'content' => 'Sample post content',
'mediaPath' => 'path/to/media.jpg',
'visibility' => 'public',
];
}

public function test_get_all_user_post_dto() : void
{
$data = $this->arrayRequestData();
$dto = GetAllUserPostDto::build($data);

$this->assertInstanceOf(GetAllUserPostDto::class, $dto);
}

public function test_get_all_user_post_dto_values() : void
{
$data = $this->arrayRequestData();
$dto = GetAllUserPostDto::build($data);

$this->assertEquals($dto->id, $data['id']);
$this->assertEquals($dto->userId, $data['userId']);
$this->assertEquals($dto->content, $data['content']);
$this->assertEquals($dto->mediaPath, $data['mediaPath']);
$this->assertEquals($dto->visibility, $data['visibility']);
}
}
36 changes: 36 additions & 0 deletions src/app/Post/Application/Dto/GetAllUserPostDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Post\Application\Dto;

class GetAllUserPostDto
{
public function __construct(
public readonly int $id,
public readonly int $userId,
public readonly string $content,
public readonly ?string $mediaPath,
public readonly string $visibility,
) {}

public static function build(array $data): self
{
return new self(
id: $data['id'],
userId: $data['userId'],
content: $data['content'],
mediaPath: $data['mediaPath'] ?? null,
visibility: $data['visibility'],
);
}

public function toArray(): array
{
return [
'id' => $this->id,
'userId' => $this->userId,
'content' => $this->content,
'mediaPath' => $this->mediaPath,
'visibility' => $this->visibility
];
}
}
35 changes: 35 additions & 0 deletions src/app/Post/Application/Dto/GetAllUserPostDtoCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Post\Application\Dto;

use App\Post\Application\Dto\GetAllUserPostDto as PostDto;

class GetAllUserPostDtoCollection
{
/**
* @param PostDto[] $items
*/
public function __construct(
public readonly array $items
) {}

public static function build(array $items): self
{
$postDtos = array_map(
fn($item) => PostDto::build($item),
$items
);

return new self($postDtos);
}

/**
* Convert the collection to an array of DTOs.
*
* @return PostDto[]
*/
public function getPosts(): array
{
return $this->items;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
namespace App\Post\Application\QueryServiceInterface;

use App\Post\Domain\Entity\PostEntityCollection;
use App\Common\Application\Dto\Pagination as PaginationDto;

interface GetAllUserPostQueryServiceInterface
{
public function getAllUserPosts(
int $userId
): PostEntityCollection;
int $userId,
int $perPage,
int $currentPage
): PaginationDto;
}
Loading