Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ede7decaa7 | ||
| 2cfb05e5de | |||
|
|
0a8399a950 | ||
| 6a64cb4c58 |
@@ -1,2 +1,2 @@
|
||||
parameters:
|
||||
app.version: '0.1.51'
|
||||
app.version: '0.1.53'
|
||||
|
||||
@@ -12,7 +12,7 @@ use App\State\EmployeeLeaveSummaryProvider;
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/employees/{id}/leave-summary',
|
||||
security: "is_granted('ROLE_USER')",
|
||||
security: "is_granted('ROLE_ADMIN')",
|
||||
provider: EmployeeLeaveSummaryProvider::class
|
||||
),
|
||||
],
|
||||
|
||||
@@ -14,7 +14,7 @@ use App\State\EmployeeRttSummaryProvider;
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/employees/{id}/rtt-summary',
|
||||
security: "is_granted('ROLE_USER')",
|
||||
security: "is_granted('ROLE_ADMIN')",
|
||||
provider: EmployeeRttSummaryProvider::class
|
||||
),
|
||||
],
|
||||
|
||||
@@ -21,10 +21,10 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
security: "is_granted('ROLE_USER')"
|
||||
security: "is_granted('ROLE_ADMIN')"
|
||||
),
|
||||
new GetCollection(
|
||||
security: "is_granted('ROLE_USER')"
|
||||
security: "is_granted('ROLE_ADMIN')"
|
||||
),
|
||||
new Post(
|
||||
security: "is_granted('ROLE_ADMIN')"
|
||||
|
||||
@@ -24,10 +24,10 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
security: "is_granted('ROLE_USER')"
|
||||
security: "is_granted('ROLE_ADMIN')"
|
||||
),
|
||||
new GetCollection(
|
||||
security: "is_granted('ROLE_USER')"
|
||||
security: "is_granted('ROLE_ADMIN')"
|
||||
),
|
||||
new Post(
|
||||
security: "is_granted('ROLE_ADMIN')"
|
||||
@@ -47,7 +47,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
||||
),
|
||||
new Get(
|
||||
uriTemplate: '/mileage_allowances/{id}/receipt',
|
||||
security: "is_granted('ROLE_USER')",
|
||||
security: "is_granted('ROLE_ADMIN')",
|
||||
provider: MileageAllowanceReceiptDownloadProvider::class,
|
||||
),
|
||||
],
|
||||
|
||||
@@ -6,6 +6,8 @@ namespace App\Service;
|
||||
|
||||
use Exception;
|
||||
use RuntimeException;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
@@ -17,7 +19,8 @@ final readonly class PublicHolidayService implements PublicHolidayServiceInterfa
|
||||
{
|
||||
public function __construct(
|
||||
private HttpClientInterface $client,
|
||||
private string $holidayUrl
|
||||
private string $holidayUrl,
|
||||
private CacheInterface $cache,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -30,24 +33,29 @@ final readonly class PublicHolidayService implements PublicHolidayServiceInterfa
|
||||
public function getHolidaysDay(string $zone): array
|
||||
{
|
||||
$zone = strtolower(trim($zone));
|
||||
$url = $this->holidayUrl."{$zone}.json";
|
||||
$key = "public_holidays_{$zone}_all";
|
||||
|
||||
try {
|
||||
$response = $this->client->request(
|
||||
'GET',
|
||||
$url
|
||||
);
|
||||
} catch (TransportExceptionInterface) {
|
||||
throw new RuntimeException('Unable to reach public holidays API.');
|
||||
} catch (ClientExceptionInterface) {
|
||||
throw new RuntimeException('Invalid zone provided for public holidays.');
|
||||
} catch (ServerExceptionInterface) {
|
||||
throw new RuntimeException('Public holidays API is temporarily unavailable.');
|
||||
} catch (Throwable) {
|
||||
throw new RuntimeException('Unexpected error while fetching public holidays.');
|
||||
}
|
||||
return $this->cache->get($key, function (ItemInterface $item) use ($zone): array {
|
||||
$item->expiresAfter(30 * 86400);
|
||||
$url = $this->holidayUrl."{$zone}.json";
|
||||
|
||||
return json_decode($response->getContent(), true);
|
||||
try {
|
||||
$response = $this->client->request(
|
||||
'GET',
|
||||
$url
|
||||
);
|
||||
} catch (TransportExceptionInterface) {
|
||||
throw new RuntimeException('Unable to reach public holidays API.');
|
||||
} catch (ClientExceptionInterface) {
|
||||
throw new RuntimeException('Invalid zone provided for public holidays.');
|
||||
} catch (ServerExceptionInterface) {
|
||||
throw new RuntimeException('Public holidays API is temporarily unavailable.');
|
||||
} catch (Throwable) {
|
||||
throw new RuntimeException('Unexpected error while fetching public holidays.');
|
||||
}
|
||||
|
||||
return json_decode($response->getContent(), true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,20 +68,25 @@ final readonly class PublicHolidayService implements PublicHolidayServiceInterfa
|
||||
{
|
||||
$zone = strtolower(trim($zone));
|
||||
$years = trim($years);
|
||||
$url = $this->holidayUrl."{$zone}/{$years}.json";
|
||||
$key = "public_holidays_{$zone}_{$years}";
|
||||
|
||||
try {
|
||||
$response = $this->client->request('GET', $url);
|
||||
} catch (TransportExceptionInterface) {
|
||||
throw new RuntimeException('Unable to reach public holidays API.');
|
||||
} catch (ClientExceptionInterface) {
|
||||
throw new RuntimeException('Invalid zone or year provided for public holidays.');
|
||||
} catch (ServerExceptionInterface) {
|
||||
throw new RuntimeException('Public holidays API is temporarily unavailable.');
|
||||
} catch (Throwable) {
|
||||
throw new RuntimeException('Unexpected error while fetching public holidays.');
|
||||
}
|
||||
return $this->cache->get($key, function (ItemInterface $item) use ($zone, $years): array {
|
||||
$item->expiresAfter(30 * 86400);
|
||||
$url = $this->holidayUrl."{$zone}/{$years}.json";
|
||||
|
||||
return json_decode($response->getContent(), true);
|
||||
try {
|
||||
$response = $this->client->request('GET', $url);
|
||||
} catch (TransportExceptionInterface) {
|
||||
throw new RuntimeException('Unable to reach public holidays API.');
|
||||
} catch (ClientExceptionInterface) {
|
||||
throw new RuntimeException('Invalid zone or year provided for public holidays.');
|
||||
} catch (ServerExceptionInterface) {
|
||||
throw new RuntimeException('Public holidays API is temporarily unavailable.');
|
||||
} catch (Throwable) {
|
||||
throw new RuntimeException('Unexpected error while fetching public holidays.');
|
||||
}
|
||||
|
||||
return json_decode($response->getContent(), true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user