-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEloquentUserStoryRepository.php
47 lines (39 loc) · 1.3 KB
/
EloquentUserStoryRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Scrum\EloquentInfrastructure\Persistence\UserStories;
use Scrum\Domain\Models\User\UserId;
use Scrum\Domain\Models\UserStories\UserStory;
use Scrum\Domain\Models\UserStories\UserStoryId;
use Scrum\Domain\Models\UserStories\UserStoryRepositoryInterface;
use Scrum\EloquentInfrastructure\Models\UserStoryDataModel;
class EloquentUserStoryRepository implements UserStoryRepositoryInterface
{
public function find(UserStoryId $id): ?UserStory
{
$data = UserStoryDataModel::where("id", $id->getValue())
->first();
if (is_null($data)) {
return null;
}
return new UserStory(
new UserStoryId($data->id),
$data->story,
new UserId($data->author),
$data->demo,
$data->estimation,
$data->seq
);
}
public function save(UserStory $userStory): void
{
UserStoryDataModel::updateOrCreate(
["id" => $userStory->getId()->getValue()],
[
"story" => $userStory->getStory(),
"author" => $userStory->getAuthor()->getValue(),
"demo" => $userStory->getDemo(),
"estimation" => $userStory->getEstimation(),
"seq" => $userStory->getSeq()
]
);
}
}