Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/Components/HttpClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ interface HttpClientInterface
* @param string $uri
* @return array
*/
public function request(string $method, string $uri):array;
public function request(string $method, string $uri): array;
}
61 changes: 61 additions & 0 deletions src/Domains/Schedule/ScheduleItemEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Tymeshift\PhpTest\Domains\Schedule;

use Tymeshift\PhpTest\Domains\Schedule\ScheduleItemInterface;
use Tymeshift\PhpTest\Interfaces\EntityInterface;

class ScheduleItemEntity implements EntityInterface, ScheduleItemInterface
{
private int $scheduleId;

private int $startTime;

private int $endTime;

private string $type;

public function getScheduleId(): int
{
return $this->scheduleId;
}

public function setScheduleId(int $scheduleId): ScheduleItemEntity
{
$this->scheduleId = $scheduleId;
return $this;
}

public function getStartTime(): int
{
return $this->startTime;
}

public function setStartTime(int $startTime): ScheduleItemEntity
{
$this->startTime = $startTime;
return $this;
}

public function getEndTime(): int
{
return $this->endTime;
}

public function setEndTime(int $endTime): ScheduleItemEntity
{
$this->endTime = $endTime;
return $this;
}

public function getType(): string
{
return $this->type;
}

public function setType(string $type): ScheduleItemEntity
{
$this->type = $type;
return $this;
}
}
8 changes: 4 additions & 4 deletions src/Domains/Schedule/ScheduleItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ interface ScheduleItemInterface
/**
* @return int
*/
public function getScheduleId():int;
public function getScheduleId(): int;

/**
* @return int
*/
public function getStartTime():int;
public function getStartTime(): int;

/**
* @return int
*/
public function getEndTime():int;
public function getEndTime(): int;

/**
* @return string
*/
public function getType():string;
public function getType(): string;
}
22 changes: 19 additions & 3 deletions src/Domains/Schedule/ScheduleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,41 @@

namespace Tymeshift\PhpTest\Domains\Schedule;

use Tymeshift\PhpTest\Domains\Schedule\ScheduleStorage;
use Tymeshift\PhpTest\Exceptions\StorageDataMissingException;
use Tymeshift\PhpTest\Interfaces\EntityInterface;
use Tymeshift\PhpTest\Interfaces\FactoryInterface;

class ScheduleRepository
{
private const SCHEDULE_DOES_NOT_EXIST = 'Schedule with id %s does not exist.';

/**
* @var ScheduleStorage
*/
private $storage;

/**
* @var ScheduleFactory
*/
private $factory;

public function __construct(ScheduleStorage $storage, FactoryInterface $factory)
public function __construct(ScheduleStorage $storage, ScheduleFactory $factory)
{
$this->storage = $storage;
$this->factory = $factory;
}

public function getById(int $id):EntityInterface
/**
* @throws StorageDataMissingException
*/
public function getById(int $id): EntityInterface
{
$data = $this->storage->getById($id);
if (empty($data)) {
throw new StorageDataMissingException(
sprintf(self::SCHEDULE_DOES_NOT_EXIST, $id)
);
}
return $this->factory->createEntity($data);
}
}
42 changes: 42 additions & 0 deletions src/Domains/Schedule/ScheduleService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Tymeshift\PhpTest\Domains\Schedule;

use Tymeshift\PhpTest\Domains\Task\TaskRepository;
use Tymeshift\PhpTest\Exceptions\InvalidCollectionDataProvidedException;
use Tymeshift\PhpTest\Exceptions\StorageDataMissingException;

class ScheduleService
{
/**
* @var ScheduleRepository
*/
private $scheduleRepository;

/**
* @var TaskRepository
*/
private $taskRepository;

public function __construct(
ScheduleRepository $scheduleRepository,
TaskRepository $taskRepository
) {
$this->scheduleRepository = $scheduleRepository;
$this->taskRepository = $taskRepository;
}

/**
* @return ScheduleItemInterface[]
* @throws StorageDataMissingException
* @throws InvalidCollectionDataProvidedException
*/
public function setTasks(int $scheduleId): array
{
$schedule = $this->scheduleRepository->getById($scheduleId);
$taskCollection = $this->taskRepository->getByScheduleId($scheduleId);
foreach ($taskCollection as $task) {

}
}
}
91 changes: 91 additions & 0 deletions src/Domains/Task/TaskEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,99 @@
namespace Tymeshift\PhpTest\Domains\Task;

use Tymeshift\PhpTest\Interfaces\EntityInterface;
use DateTime;

class TaskEntity implements EntityInterface
{
/**
* @var int
*/
private int $id;

/**
* @var int
*/
private int $scheduleId;

/**
* @var DateTime
*/
private DateTime $startTime;

/**
* @var int
*/
private int $duration;

/**
* @return int
*/
public function getId(): int
{
return $this->id;
}

/**
* @param int $id
* @return TaskEntity
*/
public function setId(int $id): TaskEntity
{
$this->id = $id;
return $this;
}

/**
* @return int
*/
public function getScheduleId(): int
{
return $this->scheduleId;
}

/**
* @param int $scheduleId
* @return TaskEntity
*/
public function setScheduleId(int $scheduleId): TaskEntity
{
$this->scheduleId = $scheduleId;
return $this;
}

/**
* @return DateTime
*/
public function getStartTime(): DateTime
{
return $this->startTime;
}

/**
* @param DateTime $startTime
* @return TaskEntity
*/
public function setStartTime(DateTime $startTime): TaskEntity
{
$this->startTime = $startTime;
return $this;
}

/**
* @return int
*/
public function getDuration(): int
{
return $this->duration;
}

/**
* @param int $duration
* @return TaskEntity
*/
public function setDuration(int $duration): TaskEntity
{
$this->duration = $duration;
return $this;
}
}
21 changes: 19 additions & 2 deletions src/Domains/Task/TaskFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,30 @@ class TaskFactory implements FactoryInterface

public function createEntity(array $data): EntityInterface
{
// TODO: Implement createEntity() method.
$entity = new TaskEntity();
if (isset($data['id']) && is_int($data['id'])) {
$entity->setId($data['id']);
}

if (isset($data['schedule_id']) && is_int($data['schedule_id'])) {
$entity->setScheduleId($data['schedule_id']);
}

if (isset($data['start_time']) && is_int($data['start_time'])) {
$entity->setStartTime((new \DateTime())->setTimestamp($data['start_time']));
}

if (isset($data['duration']) && is_int($data['duration'])) {
$entity->setDuration($data['duration']);
}

return $entity;
}

/**
* @throws InvalidCollectionDataProvidedException
*/
public function createCollection(array $data):CollectionInterface
public function createCollection(array $data): CollectionInterface
{
return (new TaskCollection())->createFromArray($data, $this);
}
Expand Down
10 changes: 8 additions & 2 deletions src/Domains/Task/TaskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Tymeshift\PhpTest\Domains\Task;

use Tymeshift\PhpTest\Exceptions\InvalidCollectionDataProvidedException;
use Tymeshift\PhpTest\Interfaces\EntityCollection;
use Tymeshift\PhpTest\Interfaces\EntityInterface;
use Tymeshift\PhpTest\Interfaces\RepositoryInterface;
Expand Down Expand Up @@ -30,9 +31,14 @@ public function getById(int $id): EntityInterface
// TODO: Implement getById() method.
}

public function getByScheduleId(int $scheduleId):TaskCollection
/**
* @throws InvalidCollectionDataProvidedException
*/
public function getByScheduleId(int $scheduleId): TaskCollection
{

return $this->factory->createCollection(
$this->storage->getByScheduleId($scheduleId)
);
}

public function getByIds(array $ids): TaskCollection
Expand Down
5 changes: 4 additions & 1 deletion src/Domains/Task/TaskStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public function __construct(HttpClientInterface $httpClient)

public function getByScheduleId(int $id): array
{

return $this->client->request(
'GET',
'https://tymeshift.com/get-by-schedule-id/' . $id
);
}

public function getByIds(array $ids): array
Expand Down
Loading