I lowkey forgot to commit
This commit is contained in:
88
src/Entity/Review.php
Normal file
88
src/Entity/Review.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ReviewRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ReviewRepository::class)]
|
||||
#[ORM\Table(name: 'reviews')]
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
class Review
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: User::class)]
|
||||
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||
private ?User $author = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 64)]
|
||||
#[Assert\NotBlank]
|
||||
private string $spotifyAlbumId = '';
|
||||
|
||||
#[ORM\Column(type: 'string', length: 255)]
|
||||
#[Assert\NotBlank]
|
||||
private string $albumName = '';
|
||||
|
||||
#[ORM\Column(type: 'string', length: 255)]
|
||||
#[Assert\NotBlank]
|
||||
private string $albumArtist = '';
|
||||
|
||||
#[ORM\Column(type: 'string', length: 160)]
|
||||
#[Assert\NotBlank]
|
||||
#[Assert\Length(max: 160)]
|
||||
private string $title = '';
|
||||
|
||||
#[ORM\Column(type: 'text')]
|
||||
#[Assert\NotBlank]
|
||||
#[Assert\Length(min: 20, max: 5000)]
|
||||
private string $content = '';
|
||||
|
||||
#[ORM\Column(type: 'smallint')]
|
||||
#[Assert\Range(min: 1, max: 10)]
|
||||
private int $rating = 5;
|
||||
|
||||
#[ORM\Column(type: 'datetime_immutable')]
|
||||
private ?\DateTimeImmutable $createdAt = null;
|
||||
|
||||
#[ORM\Column(type: 'datetime_immutable')]
|
||||
private ?\DateTimeImmutable $updatedAt = null;
|
||||
|
||||
#[ORM\PrePersist]
|
||||
public function onPrePersist(): void
|
||||
{
|
||||
$now = new \DateTimeImmutable();
|
||||
$this->createdAt = $now;
|
||||
$this->updatedAt = $now;
|
||||
}
|
||||
|
||||
#[ORM\PreUpdate]
|
||||
public function onPreUpdate(): void
|
||||
{
|
||||
$this->updatedAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function getId(): ?int { return $this->id; }
|
||||
public function getAuthor(): ?User { return $this->author; }
|
||||
public function setAuthor(User $author): void { $this->author = $author; }
|
||||
public function getSpotifyAlbumId(): string { return $this->spotifyAlbumId; }
|
||||
public function setSpotifyAlbumId(string $spotifyAlbumId): void { $this->spotifyAlbumId = $spotifyAlbumId; }
|
||||
public function getAlbumName(): string { return $this->albumName; }
|
||||
public function setAlbumName(string $albumName): void { $this->albumName = $albumName; }
|
||||
public function getAlbumArtist(): string { return $this->albumArtist; }
|
||||
public function setAlbumArtist(string $albumArtist): void { $this->albumArtist = $albumArtist; }
|
||||
public function getTitle(): string { return $this->title; }
|
||||
public function setTitle(string $title): void { $this->title = $title; }
|
||||
public function getContent(): string { return $this->content; }
|
||||
public function setContent(string $content): void { $this->content = $content; }
|
||||
public function getRating(): int { return $this->rating; }
|
||||
public function setRating(int $rating): void { $this->rating = $rating; }
|
||||
public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; }
|
||||
public function getUpdatedAt(): ?\DateTimeImmutable { return $this->updatedAt; }
|
||||
}
|
||||
|
||||
|
||||
33
src/Entity/Setting.php
Normal file
33
src/Entity/Setting.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\SettingRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ORM\Entity(repositoryClass: SettingRepository::class)]
|
||||
#[ORM\Table(name: 'settings')]
|
||||
#[ORM\UniqueConstraint(name: 'uniq_setting_name', columns: ['name'])]
|
||||
class Setting
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 100)]
|
||||
#[Assert\NotBlank]
|
||||
private string $name = '';
|
||||
|
||||
#[ORM\Column(type: 'text', nullable: true)]
|
||||
private ?string $value = null;
|
||||
|
||||
public function getId(): ?int { return $this->id; }
|
||||
public function getName(): string { return $this->name; }
|
||||
public function setName(string $name): void { $this->name = $name; }
|
||||
public function getValue(): ?string { return $this->value; }
|
||||
public function setValue(?string $value): void { $this->value = $value; }
|
||||
}
|
||||
|
||||
|
||||
116
src/Entity/User.php
Normal file
116
src/Entity/User.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\UserRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||
#[ORM\Table(name: 'users')]
|
||||
#[UniqueEntity(fields: ['email'], message: 'This email is already registered.')]
|
||||
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 180, unique: true)]
|
||||
#[Assert\NotBlank]
|
||||
#[Assert\Email]
|
||||
private string $email = '';
|
||||
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
#[ORM\Column(type: 'json')]
|
||||
private array $roles = [];
|
||||
|
||||
/**
|
||||
* @var string The hashed password
|
||||
*/
|
||||
#[ORM\Column(type: 'string')]
|
||||
private string $password = '';
|
||||
|
||||
#[ORM\Column(type: 'string', length: 120, nullable: true)]
|
||||
#[Assert\Length(max: 120)]
|
||||
private ?string $displayName = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function setEmail(string $email): void
|
||||
{
|
||||
$this->email = strtolower($email);
|
||||
}
|
||||
|
||||
public function getUserIdentifier(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
$roles = $this->roles;
|
||||
// guarantee every user at least has ROLE_USER
|
||||
if (!in_array('ROLE_USER', $roles, true)) {
|
||||
$roles[] = 'ROLE_USER';
|
||||
}
|
||||
return array_values(array_unique($roles));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $roles
|
||||
*/
|
||||
public function setRoles(array $roles): void
|
||||
{
|
||||
$this->roles = array_values(array_unique($roles));
|
||||
}
|
||||
|
||||
public function addRole(string $role): void
|
||||
{
|
||||
$roles = $this->getRoles();
|
||||
if (!in_array($role, $roles, true)) {
|
||||
$roles[] = $role;
|
||||
}
|
||||
$this->roles = $roles;
|
||||
}
|
||||
|
||||
public function getPassword(): string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function setPassword(string $hashedPassword): void
|
||||
{
|
||||
$this->password = $hashedPassword;
|
||||
}
|
||||
|
||||
public function eraseCredentials(): void
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
public function getDisplayName(): ?string
|
||||
{
|
||||
return $this->displayName;
|
||||
}
|
||||
|
||||
public function setDisplayName(?string $displayName): void
|
||||
{
|
||||
$this->displayName = $displayName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user