Start on creating snipContent entities for the db content

This commit is contained in:
Tim
2023-04-20 23:23:04 +02:00
parent a405578f93
commit 506a0e8dec
11 changed files with 323 additions and 14 deletions

View File

@ -2,12 +2,60 @@
namespace App\Service\SnipContent;
use App\Entity\Snip;
use App\Entity\SnipContent;
use App\Entity\User;
use App\Repository\SnipContentRepository;
class SnipContentDB implements SnipContentInterface
{
public function __construct()
public function __construct(
private readonly Snip $snip,
private readonly User $user,
private readonly SnipContentRepository $repo,
)
{
}
public function update(string $snipContents): void
{
// Create new snipContent entity with previous one as parent
$content = new SnipContent();
$content->setText($snipContents);
$content->setSnip($this->snip);
if ($this->snip->getSnipContents()->count() > 0) {
$content->setParent($this->snip->getSnipContents()->last());
}
$this->repo->save($content);
}
public function get(): string
{
// Return the content of the latest snipContent entity
return $this->snip->getSnipContents()->last()->getText();
}
public function getHistory(): array
{
// Return all snipContent entities (by parent)
return array_map(fn(SnipContent $content) => $content->getId(), $this->snip->getSnipContents()->toArray());
}
public function setCommit(string $commit): void
{
// return to previous history commit
// maybe store the current commit in the snip content
}
public function getCommit(): string
{
// return the current commit
return '';
}
public function delete(): void
{
// Cleanup the history
}
}