Compare commits
5 Commits
master
..
d8022ab205
| Author | SHA1 | Date | |
|---|---|---|---|
| d8022ab205 | |||
| 71c14b0625 | |||
| d9bf86598b | |||
| 4388a7ec93 | |||
| 22da85872d |
@@ -17,4 +17,4 @@
|
||||
###> symfony/framework-bundle ###
|
||||
APP_ENV=dev
|
||||
APP_SECRET=dedf3be48f625398ad5f330ddde1d072
|
||||
###< symfony/framework-bundle ###
|
||||
###< symfony/framework-bundle ###
|
||||
@@ -0,0 +1,51 @@
|
||||
name: Build and Deploy Docker
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- masterApi
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Log in to GHCR
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.rhost.ovh
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./services/www/Dockerfile
|
||||
push: true
|
||||
tags: git.rhost.ovh/${{ github.repository }}:latest
|
||||
deploy:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Deploy via SSH
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.SERVER_HOST }}
|
||||
port: ${{ secrets.SERVER_PORT }}
|
||||
username: ${{ secrets.SERVER_USER }}
|
||||
key: ${{ secrets.SERVER_SSH_KEY }}
|
||||
script: |
|
||||
cd /home/ryjek/docker/sprawozdania
|
||||
docker compose pull backend
|
||||
docker compose up -d backend
|
||||
docker compose exec --workdir /var/www/html backend APP_RUNTIME_ENV=prod php bin/console secrets:decrypt-to-local --force
|
||||
docker compose exec --workdir /var/www/html backend php ./bin/console doctrine:migration:migrate --dry-run
|
||||
docker compose exec --workdir /var/www/html backend php ./bin/console cache:clear
|
||||
@@ -38,16 +38,6 @@ services:
|
||||
- internal
|
||||
volumes:
|
||||
- ./storage/redis:/data
|
||||
|
||||
# wait_for_it:
|
||||
# build:
|
||||
# context: .
|
||||
# dockerfile: services/wait_for_it/Dockerfile
|
||||
# networks:
|
||||
# - internal
|
||||
# depends_on:
|
||||
# - database
|
||||
# command: sh -c "/wait -t 30 database:5432 -- echo 123;"
|
||||
networks:
|
||||
internal:
|
||||
internal: true
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# In all environments, the following files are loaded if they exist,
|
||||
# the latter taking precedence over the former:
|
||||
#
|
||||
# * .env contains default values for the environment variables needed by the app
|
||||
# * .env.local uncommitted file with local overrides
|
||||
# * .env.$APP_ENV committed environment-specific defaults
|
||||
# * .env.$APP_ENV.local uncommitted environment-specific overrides
|
||||
#
|
||||
# Real environment variables win over .env files.
|
||||
#
|
||||
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
|
||||
# https://symfony.com/doc/current/configuration/secrets.html
|
||||
#
|
||||
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
|
||||
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
|
||||
|
||||
###> symfony/framework-bundle ###
|
||||
APP_ENV=prod
|
||||
APP_SECRET=$env(APP_SECRET)$
|
||||
###< symfony/framework-bundle ###
|
||||
|
||||
###> doctrine/doctrine-bundle ###
|
||||
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
|
||||
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
|
||||
#
|
||||
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
|
||||
DATABASE_URL="mysql://app:%env(DATABASE_PASSWORD)%@mariadb:3306/app?serverVersion=8.0.32&charset=utf8mb4"
|
||||
#DATABASE_URL="mysql://app:%env(DATABASE_PASSWORD)%@mysql:3306/app?serverVersion=8.0.32&charset=utf8mb4"
|
||||
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
|
||||
#DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8"
|
||||
###< doctrine/doctrine-bundle ###
|
||||
REDIS_URL=redis://redis:6379?timeout=5
|
||||
+2
-1
@@ -1,11 +1,12 @@
|
||||
|
||||
###> symfony/framework-bundle ###
|
||||
.env
|
||||
.env.prod
|
||||
/.env.local
|
||||
/.env.local.php
|
||||
/.env.*.local
|
||||
/config/secrets/prod/prod.decrypt.private.php
|
||||
config/jwt
|
||||
!config/jwt/.gitkeep
|
||||
/public/bundles/
|
||||
/var/
|
||||
/vendor/
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
"doctrine/doctrine-migrations-bundle": "^3.3",
|
||||
"doctrine/orm": "^3.2",
|
||||
"league/commonmark": "^2.4",
|
||||
"lexik/jwt-authentication-bundle": "^3.2",
|
||||
"nelmio/cors-bundle": "^2.6",
|
||||
"predis/predis": "^2.2",
|
||||
"symfony/console": "6.4.*",
|
||||
"symfony/dotenv": "6.4.*",
|
||||
@@ -20,6 +22,7 @@
|
||||
"symfony/http-client": "^7.1",
|
||||
"symfony/runtime": "6.4.*",
|
||||
"symfony/security-bundle": "6.4.*",
|
||||
"symfony/serializer-pack": "^1.3",
|
||||
"symfony/stimulus-bundle": "^2.18",
|
||||
"symfony/twig-bundle": "6.4.*",
|
||||
"symfony/ux-turbo": "^2.18",
|
||||
|
||||
Generated
+1716
-637
File diff suppressed because it is too large
Load Diff
@@ -12,4 +12,6 @@ return [
|
||||
Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true],
|
||||
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
|
||||
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
|
||||
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
|
||||
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
|
||||
];
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
lexik_jwt_authentication:
|
||||
secret_key: '%env(resolve:JWT_SECRET_KEY)%'
|
||||
public_key: '%env(resolve:JWT_PUBLIC_KEY)%'
|
||||
pass_phrase: '%env(JWT_PASSPHRASE)%'
|
||||
clock_skew: 0
|
||||
@@ -0,0 +1,8 @@
|
||||
nelmio_cors:
|
||||
defaults:
|
||||
allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
|
||||
allow_headers: ['Content-Type', 'Authorization']
|
||||
allow_methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']
|
||||
max_age: 3600
|
||||
paths:
|
||||
'^/api/': ~
|
||||
@@ -13,6 +13,20 @@ security:
|
||||
dev:
|
||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||
security: false
|
||||
login:
|
||||
pattern: ^/api/auth/login
|
||||
stateless: true
|
||||
json_login:
|
||||
check_path: /api/auth/login
|
||||
username_path: username
|
||||
password_path: password
|
||||
success_handler: lexik_jwt_authentication.handler.authentication_success
|
||||
failure_handler: lexik_jwt_authentication.handler.authentication_failure
|
||||
|
||||
api:
|
||||
pattern: ^/api
|
||||
stateless: true
|
||||
jwt: ~
|
||||
main:
|
||||
lazy: true
|
||||
provider: app_user_provider
|
||||
@@ -24,22 +38,13 @@ security:
|
||||
always_use_default_target_path: true
|
||||
logout:
|
||||
path: app_logout
|
||||
# where to redirect after logout
|
||||
# target: app_any_route
|
||||
|
||||
# activate different ways to authenticate
|
||||
# https://symfony.com/doc/current/security.html#the-firewall
|
||||
|
||||
# https://symfony.com/doc/current/security/impersonating_user.html
|
||||
# switch_user: true
|
||||
|
||||
# Easy way to control access for large sections of your site
|
||||
# Note: Only the *first* access control that matches will be used
|
||||
access_control:
|
||||
- { path: ^/login, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/user/activate, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/admin, roles: ROLE_ADMIN }
|
||||
- { path: ^/, roles: ROLE_USER }
|
||||
- { path: ^/api/auth, roles: PUBLIC_ACCESS }
|
||||
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
|
||||
|
||||
when@test:
|
||||
security:
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260507143656 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('CREATE UNIQUE INDEX report_todo ON reports_todo (report_id, name)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('DROP INDEX report_todo ON reports_todo');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
|
||||
class AuthController extends AbstractController
|
||||
{
|
||||
#[Route('/api/auth/login', name: 'api_login', methods: ['POST'])]
|
||||
public function login(): JsonResponse
|
||||
{
|
||||
throw new \LogicException('Intercepted by firewall.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use App\Entity\Clients;
|
||||
use App\Repository\ClientsRepository;
|
||||
use App\Services\AddReports;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
#[Route('/api/clients', name: 'api_')]
|
||||
class ClientsController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private ClientsRepository $repo,
|
||||
private SerializerInterface $serializer,
|
||||
) {}
|
||||
|
||||
#[Route('', name: 'list', methods: ['GET'])]
|
||||
public function list(): JsonResponse
|
||||
{
|
||||
$products = $this->repo->findAll();
|
||||
$prepare = [];
|
||||
foreach ($products as $product) {
|
||||
$prepare[] = [
|
||||
'id' => $product->getId(),
|
||||
'strName' => $product->getStrName(),
|
||||
'strAddress' => $product->getStrAddress(),
|
||||
'dateLegitimacy' => $product->getDateLegitimacy()->format('Y-m-d'),
|
||||
'dateProclamation' => $product->getDateProclamation()->format('Y-m-d'),
|
||||
'extendInfo' => [
|
||||
'intNip' => $product->getIntNIP(),
|
||||
'intPhone' => $product->getIntPhone(),
|
||||
'strEmail' => $product->getStrEmail(),
|
||||
]
|
||||
];
|
||||
}
|
||||
return $this->json($prepare, context: ['groups' => ['client:read']]);
|
||||
}
|
||||
|
||||
#[Route('/add', name: 'add_client', methods: ['POST'])]
|
||||
public function add(Request $request, EntityManagerInterface $entityManager, AddReports $addReports): JsonResponse
|
||||
{
|
||||
$need = [
|
||||
"strName" => $request->getPayload()->get('name'),
|
||||
"strAddress" => $request->getPayload()->get('address'),
|
||||
"dateLegitimacy" => $request->getPayload()->get('legitimacy'),
|
||||
"dateProclamation" => $request->getPayload()->get('proclamation'),
|
||||
"intNIP" => $request->getPayload()->get('nip'),
|
||||
"intPhone" => $request->getPayload()->get('phone'),
|
||||
"strEmail" => $request->getPayload()->get('email'),
|
||||
];
|
||||
$newClient = new Clients();
|
||||
foreach ($need as $key => $value) {
|
||||
$cleared = $this->clearType($key, $value);
|
||||
$method = 'set'.ucfirst($key);
|
||||
$newClient->{$method}($cleared);
|
||||
}
|
||||
|
||||
|
||||
$entityManager->persist($newClient);
|
||||
$entityManager->flush();
|
||||
$entityManager->getCache()->evictEntityRegion(Clients::class);
|
||||
$addReports->setClient($newClient);
|
||||
$addReports->init();
|
||||
|
||||
return $this->json(['success' => true]);
|
||||
}
|
||||
|
||||
private function clearType(string $key, mixed $value)
|
||||
{
|
||||
if (str_contains($key, 'str')) {
|
||||
return addslashes($value);
|
||||
}
|
||||
if (str_contains($key, 'int')) {
|
||||
return intval($value);
|
||||
}
|
||||
if (str_contains($key, 'date')) {
|
||||
return new \DateTime($value);
|
||||
}
|
||||
}
|
||||
|
||||
// #[Route('/{id}', name: 'show', methods: ['GET'])]
|
||||
// public function show(Product $product): JsonResponse
|
||||
// {
|
||||
// return $this->json($product, context: ['groups' => ['product:read']]);
|
||||
// }
|
||||
//
|
||||
// #[Route('', name: 'create', methods: ['POST'])]
|
||||
// public function create(Request $request): JsonResponse
|
||||
// {
|
||||
// $data = $request->toArray();
|
||||
// // walidacja + zapis...
|
||||
// return $this->json($product, 201, context: ['groups' => ['product:read']]);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use App\Entity\Reports;
|
||||
use App\Entity\ReportsTodo;
|
||||
use App\Enum\ReportStatus;
|
||||
use App\Enum\ReportTodoEnum;
|
||||
use App\Helper\MonthHelper;
|
||||
use App\Repository\ReportsRepository;
|
||||
use App\Services\AddReports;
|
||||
use App\Services\OverdueReports;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
#[Route('/api/reports', name: 'api_reports')]
|
||||
class ReportsController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ReportsRepository $repo,
|
||||
private readonly OverdueReports $overdueReports
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
#[Route('/{monthId}', name: 'api_reports_all', methods: ['GET'])]
|
||||
public function getReports(int $monthId): JsonResponse
|
||||
{
|
||||
$monthHelper = new MonthHelper($this->overdueReports);
|
||||
$clientId=0;
|
||||
$monthCurrentDate = $monthHelper->getCurrentMonthDate($monthId);
|
||||
|
||||
$reportsAll = $this->repo->findAllInMonth($monthCurrentDate,$clientId);
|
||||
return $this->json($reportsAll, context: ['groups' => ['reportsAll:read','reportstodo:read']]);
|
||||
}
|
||||
|
||||
#[Route('/todo', name: 'api_reports_todo', methods: ['POST'])]
|
||||
public function updateReportTodo(Request $request, AddReports $reportsService, EntityManagerInterface $entityManager): JsonResponse
|
||||
{
|
||||
$reportId = $request->toArray()['reportId'];
|
||||
$todoName = $request->toArray()['todoName'];
|
||||
$nameObj = ReportTodoEnum::tryFromNameStatic($todoName);
|
||||
if (!$nameObj) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
$reportReference = $entityManager->getReference(Reports::class, $reportId);
|
||||
$todo = $entityManager->getRepository(ReportsTodo::class)->findOneBy(['name' => $nameObj, 'report' => $reportReference]);
|
||||
if($todo){
|
||||
$todo->setDeleted(!$todo->isDeleted());
|
||||
} else {
|
||||
$todo = new ReportsTodo();
|
||||
$todo->setName($nameObj);
|
||||
$todo->setReport($reportReference);
|
||||
}
|
||||
|
||||
$reportReference->addReportsTodo($todo);
|
||||
|
||||
$entityManager->persist($todo);
|
||||
$entityManager->flush();
|
||||
$entityManager->getCache()->evictCollection(Reports::class,"reportsTodos",$reportReference->getId());
|
||||
|
||||
|
||||
|
||||
return $this->json([
|
||||
'reportId' => $reportId,
|
||||
'reportStatusTodo' => $reportReference->getStatusTodo(),
|
||||
'todoItem' => $todo
|
||||
], context: ['groups' => ['reportstodo:read']]);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
|
||||
#[ORM\Entity(repositoryClass: ClientsRepository::class)]
|
||||
#[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'client_cache')]
|
||||
@@ -16,41 +18,53 @@ class Clients
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['client:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['client:read','reportsAll:read'])]
|
||||
private ?string $strName = null;
|
||||
|
||||
#[ORM\Column(type: Types::BIGINT)]
|
||||
#[Groups(['client:read'])]
|
||||
private ?int $intNIP = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['client:read'])]
|
||||
private ?string $strAddress = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['client:read'])]
|
||||
private ?string $strEmail = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||
#[Groups(['client:read'])]
|
||||
private ?\DateTimeInterface $dateLegitimacy = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||
#[Groups(['client:read'])]
|
||||
private ?\DateTimeInterface $dateProclamation = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Schedule>
|
||||
*/
|
||||
#[Groups(['client:read'])]
|
||||
#[ORM\OneToMany(targetEntity: Schedule::class, mappedBy: 'client')]
|
||||
private Collection $schedules;
|
||||
|
||||
#[Groups(['client:read'])]
|
||||
#[ORM\Column(options: ["default" => "0"])]
|
||||
private bool $isDeleted = false;
|
||||
|
||||
#[Groups(['client:read'])]
|
||||
#[ORM\Column(options: ["default" => "0"])]
|
||||
private bool $isComplete = false;
|
||||
|
||||
#[Groups(['client:read'])]
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $intPhone = null;
|
||||
|
||||
#[Groups(['client:read'])]
|
||||
#[ORM\Column(enumType: ReportHighlight::class, options: ["default" => "0"])]
|
||||
private ReportHighlight $highlight = ReportHighlight::STANDARD;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ReportsRepository::class)]
|
||||
#[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'report_cache')]
|
||||
@@ -22,13 +23,16 @@ class Reports
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['report:read','reportsAll:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(referencedColumnName: "id", nullable: false)]
|
||||
#[Groups(['report:read','reportsAll:read'])]
|
||||
private ?Clients $client = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE)]
|
||||
#[Groups(['report:read'])]
|
||||
private ?\DateTimeInterface $dateStart = null;
|
||||
|
||||
/**
|
||||
@@ -36,21 +40,26 @@ class Reports
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: ReportsTodo::class, mappedBy: 'report', orphanRemoval: true)]
|
||||
#[ORM\Cache(usage: 'READ_ONLY', region: 'report_cache')]
|
||||
#[Groups(['report:read','reportsAll:read'])]
|
||||
|
||||
private Collection $reportsTodos;
|
||||
|
||||
#[ORM\Column(options: ["default" => "0"])]
|
||||
#[Groups(['report:read'])]
|
||||
private bool $isDelete = false;
|
||||
|
||||
private int $numberOfReport = 0;
|
||||
|
||||
#[ORM\Column(options: ["default" => "0"])]
|
||||
#[Groups(['report:read'])]
|
||||
private bool $isDone = false;
|
||||
|
||||
#[ORM\Column]
|
||||
#[Groups(['report:read','reportsAll:read'])]
|
||||
private ?int $number = null;
|
||||
|
||||
#[ORM\Column(enumType: ReportHighlight::class, options: ["default" => "0"])]
|
||||
#[Groups(['report:read'])]
|
||||
private ReportHighlight $highlight = ReportHighlight::STANDARD;
|
||||
|
||||
public function __construct()
|
||||
@@ -150,6 +159,25 @@ class Reports
|
||||
return $count;
|
||||
}
|
||||
|
||||
#[Groups(['reportsAll:read'])]
|
||||
public function getStatusTodo(): ReportStatus
|
||||
{
|
||||
if ($this->countTodoReports() === 0) {
|
||||
return ReportStatus::INSERT;
|
||||
}
|
||||
$status = ReportStatus::WORKING;
|
||||
foreach ($this->getReportsTodos() as $reportsTodo) {
|
||||
if ($reportsTodo->isDeleted()) {
|
||||
continue;
|
||||
}
|
||||
if ($reportsTodo->getName() === ReportTodoEnum::COMPLETE) {
|
||||
$status = ReportStatus::COMPLETE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
public function takeStatusTodo(): ReportStatus
|
||||
{
|
||||
if ($this->countTodoReports() === 0) {
|
||||
|
||||
@@ -7,17 +7,29 @@ use App\Enum\ReportTodoEnum;
|
||||
use App\Repository\ReportsTodoRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ReportsTodoRepository::class)]
|
||||
#[ORM\Cache(usage: 'NONSTRICT_READ_WRITE', region: 'report_cache')]
|
||||
#[ORM\Table(
|
||||
name: 'reports_todo',
|
||||
uniqueConstraints: [
|
||||
new ORM\UniqueConstraint(
|
||||
name: 'report_todo',
|
||||
columns: ['report_id', 'name'],
|
||||
)
|
||||
]
|
||||
)]
|
||||
class ReportsTodo
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['reportstodo:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(type: Types::SMALLINT, enumType: ReportTodoEnum::class)]
|
||||
#[Groups(['reportstodo:read'])]
|
||||
private ?ReportTodoEnum $name = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'reportsTodos')]
|
||||
@@ -25,8 +37,12 @@ class ReportsTodo
|
||||
private ?Reports $report = null;
|
||||
|
||||
#[ORM\Column(options: ["default" => false])]
|
||||
#[Groups(['reportstodo:read'])]
|
||||
private ?bool $deleted = false;
|
||||
|
||||
#[Groups(['reportstodo:read'])]
|
||||
private ?string $nameString = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -67,4 +83,9 @@ class ReportsTodo
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNameString(): ?string
|
||||
{
|
||||
return $this->name->name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ enum ReportTodoEnum: int {
|
||||
}
|
||||
|
||||
public function tryFromName(string $name): ?ReportTodoEnum
|
||||
{
|
||||
return self::tryFromNameStatic($name);
|
||||
}
|
||||
public static function tryFromNameStatic(string $name): ?ReportTodoEnum
|
||||
{
|
||||
$name = strtoupper($name);
|
||||
foreach (self::cases() as $v) {
|
||||
|
||||
Reference in New Issue
Block a user