Feat: Implement entities for user and teamer, finalize login process

This commit is contained in:
Björn Fromme
2023-09-12 16:35:06 +02:00
parent 3739decab8
commit 35ca61d21b
27 changed files with 1008 additions and 442 deletions
+77
View File
@@ -0,0 +1,77 @@
<?php
namespace App\Entity\Embeddable;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Embeddable]
class BankAccount
{
#[ORM\Column(nullable: true)]
private ?string $iban = null;
#[ORM\Column(nullable: true)]
private ?string $bic = null;
#[ORM\Column(nullable: true)]
private ?string $bank = null;
#[ORM\Column(nullable: true)]
private ?string $holder = null;
public function getIban(bool $obfuscated = false): ?string
{
if (false === $obfuscated) {
return $this->iban;
}
if (null === $iban = $this->getIban()) {
return '';
}
return sprintf('%s*****%s', substr($iban, 0, 6), substr($iban, -4));
}
public function setIban(?string $iban): static
{
$this->iban = $iban;
return $this;
}
public function getBic(): ?string
{
return $this->bic;
}
public function setBic(?string $bic): static
{
$this->bic = $bic;
return $this;
}
public function getBank(): ?string
{
return $this->bank;
}
public function setBank(?string $bank): static
{
$this->bank = $bank;
return $this;
}
public function getHolder(): ?string
{
return $this->holder;
}
public function setHolder(?string $holder): static
{
$this->holder = $holder;
return $this;
}
}
-149
View File
@@ -1,149 +0,0 @@
<?php
namespace App\Entity\Embeddable;
use App\BusProNet\Model\ProfileResponse;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Embeddable]
class Profile
{
#[ORM\Column]
private ?int $busProAddressId = null;
#[ORM\Column]
private ?int $busProPersonId = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\Column(length: 255)]
private ?string $salutation = null;
#[ORM\Column(length: 255)]
private ?string $firstName = null;
#[ORM\Column(length: 255)]
private ?string $lastName = null;
#[ORM\Column(length: 1, nullable: true)]
private ?string $gender = null;
#[ORM\Column(type: 'date_immutable', nullable: true)]
private ?\DateTimeImmutable $dateOfBirth = null;
public static function fromApiResponse(ProfileResponse $profileResponse): static
{
$instance = new static();
$instance
->setBusProAddressId($profileResponse->getAddressId())
->setBusProPersonId($profileResponse->getPersonId())
->setTitle($profileResponse->getTitle())
->setSalutation($profileResponse->getSalutation())
->setFirstName($profileResponse->getFirstName())
->setLastName($profileResponse->getName())
->setGender($profileResponse->getGender())
->setDateOfBirth($profileResponse->getDateOfBirth())
;
return $instance;
}
public function getBusProAddressId(): ?int
{
return $this->busProAddressId;
}
public function setBusProAddressId(int $busProAddressId): static
{
$this->busProAddressId = $busProAddressId;
return $this;
}
public function getBusProPersonId(): ?int
{
return $this->busProPersonId;
}
public function setBusProPersonId(int $busProPersonId): static
{
$this->busProPersonId = $busProPersonId;
return $this;
}
public function getSalutation(): ?string
{
return $this->salutation;
}
public function setSalutation(?string $salutation): static
{
$this->salutation = $salutation;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): static
{
$this->title = $title;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): static
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): static
{
$this->lastName = $lastName;
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(?string $gender): static
{
$this->gender = $gender;
return $this;
}
public function getDateOfBirth(): ?\DateTimeImmutable
{
return $this->dateOfBirth;
}
public function setDateOfBirth(?\DateTimeImmutable $dateOfBirth): static
{
$this->dateOfBirth = $dateOfBirth;
return $this;
}
}
+284
View File
@@ -0,0 +1,284 @@
<?php
namespace App\Entity;
use App\BusProNet\Model\ProfileResponse;
use App\Entity\Embeddable\Address;
use App\Entity\Embeddable\BankAccount;
use App\Entity\Embeddable\Communication;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\TeamerRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: TeamerRepository::class)]
class Teamer implements TimestampableEntityInterface
{
use TimestampableEntity;
public const STATUS_NEW = 'new';
public const STATUS_EXISTING = 'existing';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 36, unique: true)]
private string $uuid;
#[ORM\Column(length: 255)]
private ?string $firstName = null;
#[ORM\Column(length: 255)]
private ?string $lastName = null;
#[ORM\Column(length: 1)]
private ?string $gender = null;
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
private ?\DateTimeImmutable $dateOfBirth = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $academicTitle = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $salutation = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $nationality = null;
#[ORM\Embedded(class: Address::class)]
#[Assert\Valid()]
private ?Address $address = null;
#[ORM\Embedded(class: Communication::class)]
#[Assert\Valid()]
private ?Communication $communication = null;
#[ORM\Embedded(class: BankAccount::class)]
#[Assert\Valid()]
private ?BankAccount $bankAccount = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $taxId = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $healthInsuranceCompany = null;
#[ORM\Column(length: 32)]
private ?string $status = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $remarks = null;
public function __construct()
{
$this->uuid = Uuid::v4();
$this->status = static::STATUS_NEW;
}
public static function fromApiResponse(ProfileResponse $profileResponse): static
{
$instance = new static();
$instance
->setAcademicTitle($profileResponse->getTitle())
->setSalutation($profileResponse->getSalutation())
->setFirstName($profileResponse->getFirstName())
->setLastName($profileResponse->getName())
->setGender($profileResponse->getGender())
->setDateOfBirth($profileResponse->getDateOfBirth())
;
$address = Address::fromApiResponse($profileResponse);
$communication = Communication::fromApiResponse($profileResponse);
$instance
->setAddress($address)
->setCommunication($communication)
;
return $instance;
}
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): string
{
return $this->uuid;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): static
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): static
{
$this->lastName = $lastName;
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(string $gender): static
{
$this->gender = $gender;
return $this;
}
public function getDateOfBirth(): ?\DateTimeImmutable
{
return $this->dateOfBirth;
}
public function setDateOfBirth(\DateTimeImmutable $dateOfBirth): static
{
$this->dateOfBirth = $dateOfBirth;
return $this;
}
public function getAcademicTitle(): ?string
{
return $this->academicTitle;
}
public function setAcademicTitle(?string $academicTitle): static
{
$this->academicTitle = $academicTitle;
return $this;
}
public function getSalutation(): ?string
{
return $this->salutation;
}
public function setSalutation(?string $salutation): static
{
$this->salutation = $salutation;
return $this;
}
public function getNationality(): ?string
{
return $this->nationality;
}
public function setNationality(string $nationality): static
{
$this->nationality = $nationality;
return $this;
}
public function getAddress(): ?Address
{
return $this->address;
}
public function setAddress(?Address $address): static
{
$this->address = $address;
return $this;
}
public function getCommunication(): ?Communication
{
return $this->communication;
}
public function setCommunication(?Communication $communication): static
{
$this->communication = $communication;
return $this;
}
public function getBankAccount(): ?BankAccount
{
return $this->bankAccount;
}
public function setBankAccount(?BankAccount $bankAccount): static
{
$this->bankAccount = $bankAccount;
return $this;
}
public function getTaxId(): ?string
{
return $this->taxId;
}
public function setTaxId(?string $taxId): static
{
$this->taxId = $taxId;
return $this;
}
public function getHealthInsuranceCompany(): ?string
{
return $this->healthInsuranceCompany;
}
public function setHealthInsuranceCompany(?string $healthInsuranceCompany): static
{
$this->healthInsuranceCompany = $healthInsuranceCompany;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): static
{
$this->status = $status;
return $this;
}
public function getRemarks(): ?string
{
return $this->remarks;
}
public function setRemarks(?string $remarks): static
{
$this->remarks = $remarks;
return $this;
}
}
@@ -0,0 +1,14 @@
<?php
namespace App\Entity;
interface TimestampableEntityInterface
{
public function getCreatedAt();
public function setCreatedAt(\DateTimeImmutable $createdAt);
public function getUpdatedAt();
public function setUpdatedAt(\DateTimeImmutable $updatedAt);
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace App\Entity\Traits;
use Doctrine\ORM\Mapping as ORM;
trait TimestampableEntity
{
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): static
{
$this->updatedAt = $updatedAt;
return $this;
}
}
+63 -53
View File
@@ -2,48 +2,82 @@
namespace App\Entity;
use App\Entity\Embeddable\Address;
use App\Entity\Embeddable\Communication;
use App\Entity\Embeddable\Profile;
use App\Entity\Traits\TimestampableEntity;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: UserRepository::class)]
class User implements UserInterface
class User implements UserInterface, TimestampableEntityInterface
{
use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 36, unique: true)]
private string $uuid;
#[ORM\Column]
private ?int $busProAddressId = null;
#[ORM\Column]
private ?int $busProPersonId = null;
#[ORM\Column(length: 255)]
private ?string $email = null;
#[ORM\Embedded(class: Profile::class)]
#[Assert\Valid()]
private ?Profile $profile = null;
#[ORM\Embedded(class: Address::class)]
#[Assert\Valid()]
private ?Address $address = null;
#[ORM\Embedded(class: Communication::class)]
#[Assert\Valid()]
private ?Communication $communication = null;
#[ORM\Column(type: 'json')]
private array $roles = [];
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $lastLoginAt = null;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
private ?Teamer $teamer = null;
public function __construct()
{
$this->uuid = Uuid::v4();
}
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): string
{
return $this->uuid;
}
public function getBusProAddressId(): ?int
{
return $this->busProAddressId;
}
public function setBusProAddressId(int $busProAddressId): static
{
$this->busProAddressId = $busProAddressId;
return $this;
}
public function getBusProPersonId(): ?int
{
return $this->busProPersonId;
}
public function setBusProPersonId(int $busProPersonId): static
{
$this->busProPersonId = $busProPersonId;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
@@ -56,42 +90,6 @@ class User implements UserInterface
return $this;
}
public function getProfile(): ?Profile
{
return $this->profile;
}
public function setProfile(?Profile $profile): static
{
$this->profile = $profile;
return $this;
}
public function getAddress(): ?Address
{
return $this->address;
}
public function setAddress(?Address $address): static
{
$this->address = $address;
return $this;
}
public function getCommunication(): ?Communication
{
return $this->communication;
}
public function setCommunication(?Communication $communication): static
{
$this->communication = $communication;
return $this;
}
public function getRoles(): array
{
$roles = ['ROLE_USER', ...$this->roles];
@@ -142,4 +140,16 @@ class User implements UserInterface
{
return $this->email;
}
public function getTeamer(): ?Teamer
{
return $this->teamer;
}
public function setTeamer(?Teamer $teamer): static
{
$this->teamer = $teamer;
return $this;
}
}