Skip to content

Commit

Permalink
Merge pull request #54 from itk-dev/feature/je-403-exceptions-and-cle…
Browse files Browse the repository at this point in the history
…anup

Feature/je 403 exceptions and cleanup
  • Loading branch information
tuj authored Jan 3, 2024
2 parents 88d830e + b0ea91e commit dd78bcc
Show file tree
Hide file tree
Showing 28 changed files with 694 additions and 555 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added checks for errors before allowing putting project billing on record
* Added error check for invoice entries with 0 amounts
* Make sure all issues are selected in project billing period.
* Refactored error handling.


* RELEASE NOTES:
Expand Down
1 change: 1 addition & 0 deletions config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ framework:
secret: '%env(APP_SECRET)%'
#csrf_protection: true
http_method_override: false
error_controller: App\Controller\ErrorController::show

# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
Expand Down
6 changes: 3 additions & 3 deletions src/Command/MigrateCustomersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Command;

use App\Service\BillingService;
use App\Service\DataProviderService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -15,7 +15,7 @@
)]
class MigrateCustomersCommand extends Command
{
public function __construct(private readonly BillingService $billingService)
public function __construct(private readonly DataProviderService $dataProviderService)
{
parent::__construct($this->getName());
}
Expand All @@ -29,7 +29,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);

if ($io->confirm('Are you sure?')) {
$this->billingService->migrateCustomers();
$this->dataProviderService->migrateCustomers();
}

$io->success('invoice.customerAccountId migrated to invoice.client');
Expand Down
6 changes: 3 additions & 3 deletions src/Command/SyncAccountsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Command;

use App\Service\BillingService;
use App\Service\DataProviderService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -15,7 +15,7 @@
)]
class SyncAccountsCommand extends Command
{
public function __construct(private readonly BillingService $billingService)
public function __construct(private readonly DataProviderService $dataProviderService)
{
parent::__construct($this->getName());
}
Expand All @@ -28,7 +28,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$this->billingService->syncAccounts(function ($i, $length) use ($io) {
$this->dataProviderService->syncAccounts(function ($i, $length) use ($io) {
if (0 == $i) {
$io->progressStart($length);
} elseif ($i >= $length - 1) {
Expand Down
15 changes: 8 additions & 7 deletions src/Command/SyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace App\Command;

use App\Exception\EconomicsException;
use App\Repository\ProjectRepository;
use App\Service\BillingService;
use App\Service\DataProviderService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -17,7 +18,7 @@
class SyncCommand extends Command
{
public function __construct(
private readonly BillingService $billingService,
private readonly DataProviderService $dataProviderService,
private readonly ProjectRepository $projectRepository,
) {
parent::__construct($this->getName());
Expand All @@ -28,7 +29,7 @@ protected function configure(): void
}

/**
* @throws \Exception
* @throws EconomicsException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
Expand All @@ -38,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io->info('Processing projects');

$this->billingService->syncProjects(function ($i, $length) use ($io) {
$this->dataProviderService->syncProjects(function ($i, $length) use ($io) {
if (0 == $i) {
$io->progressStart($length);
} elseif ($i >= $length - 1) {
Expand All @@ -50,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io->info('Processing accounts');

$this->billingService->syncAccounts(function ($i, $length) use ($io) {
$this->dataProviderService->syncAccounts(function ($i, $length) use ($io) {
if (0 == $i) {
$io->progressStart($length);
} elseif ($i >= $length - 1) {
Expand All @@ -65,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($projects as $project) {
$io->writeln("Processing issues for {$project->getName()}");

$this->billingService->syncIssuesForProject($project->getId(), function ($i, $length) use ($io) {
$this->dataProviderService->syncIssuesForProject($project->getId(), function ($i, $length) use ($io) {
if (0 == $i) {
$io->progressStart($length);
} elseif ($i >= $length - 1) {
Expand All @@ -83,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($projects as $project) {
$io->writeln("Processing worklogs for {$project->getName()}");

$this->billingService->syncWorklogsForProject($project->getId(), function ($i, $length) use ($io) {
$this->dataProviderService->syncWorklogsForProject($project->getId(), function ($i, $length) use ($io) {
if (0 == $i) {
$io->progressStart($length);
} elseif ($i >= $length - 1) {
Expand Down
9 changes: 5 additions & 4 deletions src/Command/SyncIssuesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace App\Command;

use App\Exception\EconomicsException;
use App\Repository\ProjectRepository;
use App\Service\BillingService;
use App\Service\DataProviderService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -17,7 +18,7 @@
class SyncIssuesCommand extends Command
{
public function __construct(
private readonly BillingService $billingService,
private readonly DataProviderService $dataProviderService,
private readonly ProjectRepository $projectRepository,
) {
parent::__construct($this->getName());
Expand All @@ -28,7 +29,7 @@ protected function configure(): void
}

/**
* @throws \Exception
* @throws EconomicsException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
Expand All @@ -43,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($projects as $project) {
$io->writeln("Processing issues for {$project->getName()}");

$this->billingService->syncIssuesForProject($project->getId(), function ($i, $length) use ($io) {
$this->dataProviderService->syncIssuesForProject($project->getId(), function ($i, $length) use ($io) {
if (0 == $i) {
$io->progressStart($length);
} elseif ($i >= $length - 1) {
Expand Down
6 changes: 3 additions & 3 deletions src/Command/SyncProjectsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Command;

use App\Service\BillingService;
use App\Service\DataProviderService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -15,7 +15,7 @@
)]
class SyncProjectsCommand extends Command
{
public function __construct(private readonly BillingService $billingService)
public function __construct(private readonly DataProviderService $dataProviderService)
{
parent::__construct($this->getName());
}
Expand All @@ -28,7 +28,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$this->billingService->syncProjects(function ($i, $length) use ($io) {
$this->dataProviderService->syncProjects(function ($i, $length) use ($io) {
if (0 == $i) {
$io->progressStart($length);
} elseif ($i >= $length - 1) {
Expand Down
9 changes: 5 additions & 4 deletions src/Command/SyncWorklogsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace App\Command;

use App\Exception\EconomicsException;
use App\Repository\ProjectRepository;
use App\Service\BillingService;
use App\Service\DataProviderService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -17,7 +18,7 @@
class SyncWorklogsCommand extends Command
{
public function __construct(
private readonly BillingService $billingService,
private readonly DataProviderService $dataProviderService,
private readonly ProjectRepository $projectRepository,
) {
parent::__construct($this->getName());
Expand All @@ -28,7 +29,7 @@ protected function configure(): void
}

/**
* @throws \Exception
* @throws EconomicsException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
Expand All @@ -43,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($projects as $project) {
$io->writeln("Processing worklogs for {$project->getName()}");

$this->billingService->syncWorklogsForProject($project->getId(), function ($i, $length) use ($io) {
$this->dataProviderService->syncWorklogsForProject($project->getId(), function ($i, $length) use ($io) {
if (0 == $i) {
$io->progressStart($length);
} elseif ($i >= $length - 1) {
Expand Down
29 changes: 29 additions & 0 deletions src/Controller/ErrorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Controller;

use App\Exception\EconomicsException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class ErrorController extends AbstractController
{
public function show(\Throwable $exception): Response
{
$code = $exception->getCode();

if ($exception instanceof NotFoundHttpException) {
$code = 404;
}

if ($exception instanceof EconomicsException) {
$message = $exception->getMessage();
}

return $this->render('error/error.html.twig', [
'code' => $code,
'message' => $message ?? null,
]);
}
}
5 changes: 2 additions & 3 deletions src/Controller/FrontpageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class FrontpageController extends AbstractController
{
#[Route('/', name: 'app_frontpage_index')]
public function index(Request $request): Response
public function index(): Response
{
return $this->render('index.html.twig', []);
return $this->render('index.html.twig');
}
}
5 changes: 2 additions & 3 deletions src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

#[Route('/admin')]
class HomeController extends AbstractController
{
#[Route('/', name: 'index')]
public function index(Request $request): Response
public function index(): Response
{
return $this->render('home/index.html.twig', []);
return $this->render('home/index.html.twig');
}
}
Loading

0 comments on commit dd78bcc

Please sign in to comment.