load video from database

This commit is contained in:
overflowerror 2021-01-06 22:46:46 +01:00
parent 677354d3ef
commit 28da454eae
6 changed files with 259 additions and 6 deletions

View file

@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210106214136 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX UNIQ_8D93D6495E237E06');
$this->addSql('CREATE TEMPORARY TABLE __temp__user AS SELECT id, password, name, roles FROM user');
$this->addSql('DROP TABLE user');
$this->addSql('CREATE TABLE user (id BLOB NOT NULL, password VARCHAR(255) NOT NULL COLLATE BINARY, name VARCHAR(180) NOT NULL COLLATE BINARY, roles CLOB NOT NULL COLLATE BINARY --(DC2Type:json)
, PRIMARY KEY(id))');
$this->addSql('INSERT INTO user (id, password, name, roles) SELECT id, password, name, roles FROM __temp__user');
$this->addSql('DROP TABLE __temp__user');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D6495E237E06 ON user (name)');
$this->addSql('DROP INDEX IDX_7CC7DA2C16678C77');
$this->addSql('CREATE TEMPORARY TABLE __temp__video AS SELECT id, uploader_id, uploaded, name, description, tags, state FROM video');
$this->addSql('DROP TABLE video');
$this->addSql('CREATE TABLE video (id BLOB NOT NULL, uploader_id BLOB NOT NULL, uploaded DATETIME NOT NULL --(DC2Type:datetime_immutable)
, name VARCHAR(255) NOT NULL COLLATE BINARY, description VARCHAR(1024) NOT NULL COLLATE BINARY, tags CLOB NOT NULL COLLATE BINARY --(DC2Type:array)
, state INTEGER NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_7CC7DA2C16678C77 FOREIGN KEY (uploader_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO video (id, uploader_id, uploaded, name, description, tags, state) SELECT id, uploader_id, uploaded, name, description, tags, state FROM __temp__video');
$this->addSql('DROP TABLE __temp__video');
$this->addSql('CREATE INDEX IDX_7CC7DA2C16678C77 ON video (uploader_id)');
$this->addSql('DROP INDEX IDX_313BC42D29C1004E');
$this->addSql('CREATE TEMPORARY TABLE __temp__video_link AS SELECT id, video_id, created FROM video_link');
$this->addSql('DROP TABLE video_link');
$this->addSql('CREATE TABLE video_link (id BLOB NOT NULL, video_id BLOB NOT NULL, creator_id BLOB NOT NULL, created DATETIME NOT NULL --(DC2Type:datetime_immutable)
, max_views INTEGER DEFAULT NULL, viewable_for INTEGER DEFAULT NULL, viewable_until DATETIME DEFAULT NULL, PRIMARY KEY(id), CONSTRAINT FK_313BC42D29C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_313BC42D61220EA6 FOREIGN KEY (creator_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO video_link (id, video_id, created) SELECT id, video_id, created FROM __temp__video_link');
$this->addSql('DROP TABLE __temp__video_link');
$this->addSql('CREATE INDEX IDX_313BC42D29C1004E ON video_link (video_id)');
$this->addSql('CREATE INDEX IDX_313BC42D61220EA6 ON video_link (creator_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX UNIQ_8D93D6495E237E06');
$this->addSql('CREATE TEMPORARY TABLE __temp__user AS SELECT id, name, roles, password FROM user');
$this->addSql('DROP TABLE user');
$this->addSql('CREATE TABLE user (id BLOB NOT NULL, name VARCHAR(180) NOT NULL, roles CLOB NOT NULL --(DC2Type:json)
, password VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
$this->addSql('INSERT INTO user (id, name, roles, password) SELECT id, name, roles, password FROM __temp__user');
$this->addSql('DROP TABLE __temp__user');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D6495E237E06 ON user (name)');
$this->addSql('DROP INDEX IDX_7CC7DA2C16678C77');
$this->addSql('CREATE TEMPORARY TABLE __temp__video AS SELECT id, uploader_id, uploaded, name, description, tags, state FROM video');
$this->addSql('DROP TABLE video');
$this->addSql('CREATE TABLE video (id BLOB NOT NULL, uploaded DATETIME NOT NULL --(DC2Type:datetime_immutable)
, name VARCHAR(255) NOT NULL, description VARCHAR(1024) NOT NULL, tags CLOB NOT NULL --(DC2Type:array)
, state INTEGER NOT NULL, uploader_id BLOB NOT NULL, PRIMARY KEY(id))');
$this->addSql('INSERT INTO video (id, uploader_id, uploaded, name, description, tags, state) SELECT id, uploader_id, uploaded, name, description, tags, state FROM __temp__video');
$this->addSql('DROP TABLE __temp__video');
$this->addSql('CREATE INDEX IDX_7CC7DA2C16678C77 ON video (uploader_id)');
$this->addSql('DROP INDEX IDX_313BC42D29C1004E');
$this->addSql('DROP INDEX IDX_313BC42D61220EA6');
$this->addSql('CREATE TEMPORARY TABLE __temp__video_link AS SELECT id, video_id, created FROM video_link');
$this->addSql('DROP TABLE video_link');
$this->addSql('CREATE TABLE video_link (id BLOB NOT NULL, created DATETIME NOT NULL --(DC2Type:datetime_immutable)
, video_id BLOB NOT NULL, mode INTEGER NOT NULL, PRIMARY KEY(id))');
$this->addSql('INSERT INTO video_link (id, video_id, created) SELECT id, video_id, created FROM __temp__video_link');
$this->addSql('DROP TABLE __temp__video_link');
$this->addSql('CREATE INDEX IDX_313BC42D29C1004E ON video_link (video_id)');
}
}

View file

@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210106214257 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX UNIQ_8D93D6495E237E06');
$this->addSql('CREATE TEMPORARY TABLE __temp__user AS SELECT id, password, name, roles FROM user');
$this->addSql('DROP TABLE user');
$this->addSql('CREATE TABLE user (id BLOB NOT NULL, password VARCHAR(255) NOT NULL COLLATE BINARY, name VARCHAR(180) NOT NULL COLLATE BINARY, roles CLOB NOT NULL COLLATE BINARY --(DC2Type:json)
, PRIMARY KEY(id))');
$this->addSql('INSERT INTO user (id, password, name, roles) SELECT id, password, name, roles FROM __temp__user');
$this->addSql('DROP TABLE __temp__user');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D6495E237E06 ON user (name)');
$this->addSql('DROP INDEX IDX_7CC7DA2C16678C77');
$this->addSql('CREATE TEMPORARY TABLE __temp__video AS SELECT id, uploader_id, uploaded, name, description, tags, state FROM video');
$this->addSql('DROP TABLE video');
$this->addSql('CREATE TABLE video (id BLOB NOT NULL, uploader_id BLOB NOT NULL, uploaded DATETIME NOT NULL --(DC2Type:datetime_immutable)
, name VARCHAR(255) NOT NULL COLLATE BINARY, description VARCHAR(1024) NOT NULL COLLATE BINARY, tags CLOB NOT NULL COLLATE BINARY --(DC2Type:array)
, state INTEGER NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_7CC7DA2C16678C77 FOREIGN KEY (uploader_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO video (id, uploader_id, uploaded, name, description, tags, state) SELECT id, uploader_id, uploaded, name, description, tags, state FROM __temp__video');
$this->addSql('DROP TABLE __temp__video');
$this->addSql('CREATE INDEX IDX_7CC7DA2C16678C77 ON video (uploader_id)');
$this->addSql('DROP INDEX IDX_313BC42D61220EA6');
$this->addSql('DROP INDEX IDX_313BC42D29C1004E');
$this->addSql('CREATE TEMPORARY TABLE __temp__video_link AS SELECT id, video_id, creator_id, created, max_views, viewable_for, viewable_until FROM video_link');
$this->addSql('DROP TABLE video_link');
$this->addSql('CREATE TABLE video_link (id BLOB NOT NULL, video_id BLOB NOT NULL, creator_id BLOB NOT NULL, created DATETIME NOT NULL --(DC2Type:datetime_immutable)
, max_views INTEGER DEFAULT NULL, viewable_for INTEGER DEFAULT NULL, viewable_until DATETIME DEFAULT NULL, comment VARCHAR(1024) DEFAULT NULL, PRIMARY KEY(id), CONSTRAINT FK_313BC42D29C1004E FOREIGN KEY (video_id) REFERENCES video (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_313BC42D61220EA6 FOREIGN KEY (creator_id) REFERENCES user (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO video_link (id, video_id, creator_id, created, max_views, viewable_for, viewable_until) SELECT id, video_id, creator_id, created, max_views, viewable_for, viewable_until FROM __temp__video_link');
$this->addSql('DROP TABLE __temp__video_link');
$this->addSql('CREATE INDEX IDX_313BC42D61220EA6 ON video_link (creator_id)');
$this->addSql('CREATE INDEX IDX_313BC42D29C1004E ON video_link (video_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX UNIQ_8D93D6495E237E06');
$this->addSql('CREATE TEMPORARY TABLE __temp__user AS SELECT id, name, roles, password FROM user');
$this->addSql('DROP TABLE user');
$this->addSql('CREATE TABLE user (id BLOB NOT NULL, name VARCHAR(180) NOT NULL, roles CLOB NOT NULL --(DC2Type:json)
, password VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
$this->addSql('INSERT INTO user (id, name, roles, password) SELECT id, name, roles, password FROM __temp__user');
$this->addSql('DROP TABLE __temp__user');
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D6495E237E06 ON user (name)');
$this->addSql('DROP INDEX IDX_7CC7DA2C16678C77');
$this->addSql('CREATE TEMPORARY TABLE __temp__video AS SELECT id, uploader_id, uploaded, name, description, tags, state FROM video');
$this->addSql('DROP TABLE video');
$this->addSql('CREATE TABLE video (id BLOB NOT NULL, uploaded DATETIME NOT NULL --(DC2Type:datetime_immutable)
, name VARCHAR(255) NOT NULL, description VARCHAR(1024) NOT NULL, tags CLOB NOT NULL --(DC2Type:array)
, state INTEGER NOT NULL, uploader_id BLOB NOT NULL, PRIMARY KEY(id))');
$this->addSql('INSERT INTO video (id, uploader_id, uploaded, name, description, tags, state) SELECT id, uploader_id, uploaded, name, description, tags, state FROM __temp__video');
$this->addSql('DROP TABLE __temp__video');
$this->addSql('CREATE INDEX IDX_7CC7DA2C16678C77 ON video (uploader_id)');
$this->addSql('DROP INDEX IDX_313BC42D29C1004E');
$this->addSql('DROP INDEX IDX_313BC42D61220EA6');
$this->addSql('CREATE TEMPORARY TABLE __temp__video_link AS SELECT id, video_id, creator_id, created, max_views, viewable_for, viewable_until FROM video_link');
$this->addSql('DROP TABLE video_link');
$this->addSql('CREATE TABLE video_link (id BLOB NOT NULL, created DATETIME NOT NULL --(DC2Type:datetime_immutable)
, max_views INTEGER DEFAULT NULL, viewable_for INTEGER DEFAULT NULL, viewable_until DATETIME DEFAULT NULL, video_id BLOB NOT NULL, creator_id BLOB NOT NULL, PRIMARY KEY(id))');
$this->addSql('INSERT INTO video_link (id, video_id, creator_id, created, max_views, viewable_for, viewable_until) SELECT id, video_id, creator_id, created, max_views, viewable_for, viewable_until FROM __temp__video_link');
$this->addSql('DROP TABLE __temp__video_link');
$this->addSql('CREATE INDEX IDX_313BC42D29C1004E ON video_link (video_id)');
$this->addSql('CREATE INDEX IDX_313BC42D61220EA6 ON video_link (creator_id)');
}
}

View file

@ -5,9 +5,10 @@ namespace App\Controller;
use App\Entity\Video;
use App\Form\VideoType;
use App\Form\VideoLinkType;
use App\Mapper\CustomUuidMapper;
use App\Service\UserService;
use App\Service\VideoLinkService;
use App\Service\VideoService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormError;
@ -19,12 +20,20 @@ class DashboardController extends AbstractController
{
private $userService;
private $videoService;
private $videoLinkService;
private $uuidMapper;
public function __construct(UserService $userService, VideoService $videoService, CustomUuidMapper $uuidMapper)
public function __construct(
UserService $userService,
VideoService $videoService,
VideoLinkService $videoLinkService,
CustomUuidMapper $uuidMapper
)
{
$this->userService = $userService;
$this->videoService = $videoService;
$this->videoLinkService = $videoLinkService;
$this->uuidMapper = $uuidMapper;
}
@ -55,8 +64,13 @@ class DashboardController extends AbstractController
*/
public function upload(Request $request): Response
{
if (!$this->isGranted("ROLE_USER")) {
// not logged in
return $this->redirectToRoute("app_login");
}
$video = new Video();
$form = $this->createForm(VideoType::class, $video);
$form = $this->createForm(VideoLinkType::class, $video);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
@ -80,9 +94,16 @@ class DashboardController extends AbstractController
*/
public function links(): Response
{
if (!$this->isGranted("ROLE_USER")) {
// not logged in
return $this->redirectToRoute("app_login");
}
$user = $this->userService->getLoggedInUser();
$links = $this->videoLinkService->getAll($user);
return $this->render("dashboard/links.html.twig", [
"links" => ["1", "2", "3"]
"links" => $links
]);
}
}

View file

@ -50,6 +50,17 @@ class VideoLink
*/
private $viewableUntil;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false)
*/
private $creator;
/**
* @ORM\Column(type="string", length=1024, nullable=true)
*/
private $comment;
public function getId(): ?UuidInterface
{
return $this->id;
@ -112,4 +123,28 @@ class VideoLink
$this->viewableFor = $viewableFor;
return $this;
}
public function getCreator(): ?User
{
return $this->creator;
}
public function setCreator(?User $creator): self
{
$this->creator = $creator;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
return $this;
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace App\Form;
use App\Entity\VideoLink;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class VideoLinkType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, $options): void
{
$builder
->add("submit", SubmitType::class);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => VideoLink::class,
]);
}
}

View file

@ -4,21 +4,26 @@
namespace App\Service;
use App\Entity\User;
use App\Entity\VideoLink;
use App\Repository\VideoLinkRepository;
class VideoLinkService
{
private $videoLinkRepository;
public function __construct(VideoLinkRepository $videoLinkRepository)
{
$this->videoLinkRepository;
$this->videoLinkRepository = $videoLinkRepository;
}
public function get($linkId): ?VideoLink
{
return $this->videoLinkRepository->findOneById($linkId);
}
public function getAll(User $user): array
{
return $this->videoLinkRepository->findByCreator($user);
}
}