Fixes
This commit is contained in:
@ -115,4 +115,19 @@ class Currencies {
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function latestValue(Request $request, Response $response, ModelFactory $factory, $currency_id): Response {
|
||||
$currency = $factory->find(Currency::class)->one($currency_id);
|
||||
$output = [
|
||||
'get_data' => compact('currency_id'),
|
||||
'currency' => null,
|
||||
'value' => null
|
||||
];
|
||||
if ($currency) {
|
||||
$output['currency'] = $currency->asArray();
|
||||
if ($currency->latest()) {
|
||||
$output['value'] = $currency->latest()->asArray();
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -89,10 +89,10 @@ class Values {
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(Request $request, Response $response, ModelFactory $factory, $currency_id, $base_id, $date_time = null): Response {
|
||||
$output = ['get_data' => compact('currency_id', 'date_time', 'base_id')];
|
||||
$output = ['get_data' => compact('currency_id', 'date_time', 'base_id'), 'value' => null, 'deleted' => false];
|
||||
if ($date_time !== null) {
|
||||
$value = $factory->find(Value::class)->where([['currency_id', $currency_id], ['base_id', $base_id], ['date_time', $date_time]])->one();
|
||||
if ($currency) {
|
||||
if ($value) {
|
||||
$output['value'] = $value->asArray();
|
||||
$status = $value->delete();
|
||||
$output['deleted'] = $status;
|
||||
|
@ -50,6 +50,8 @@ server {
|
||||
}
|
||||
|
||||
add_header 'Access-Control-Allow-Origin' 'http://localhost:8080';
|
||||
add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,OPTIONS';
|
||||
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
|
||||
|
||||
location ~ \.php {
|
||||
try_files $uri =404;
|
||||
|
@ -14,6 +14,7 @@ $app->group('/currency/{currency_id}', function($app) {
|
||||
$app->put('/edit[/]', [Currencies::class, 'edit']);
|
||||
$app->delete('/delete[/]', [Currencies::class, 'delete']);
|
||||
$app->group('/values', function($app) {
|
||||
$app->get('/latest[/]', [Currencies::class, 'latestValue']);
|
||||
$app->post('/add[/]', [Currencies::class, 'addValues']);
|
||||
$app->get('[/]', [Currencies::class, 'getValues']);
|
||||
$app->options('[/]', function (Request $request, Response $response): Response {
|
||||
|
@ -1,7 +1,15 @@
|
||||
<?php
|
||||
use Psr\Container\ContainerInterface as Container;
|
||||
use Dotenv\Dotenv;
|
||||
|
||||
if (file_exists(implode(DIRECTORY_SEPARATOR, [dirname(__DIR__, 2), '.env']))) {
|
||||
$dotenv = Dotenv::createImmutable(dirname(__DIR__, 2));
|
||||
$dotenv->load();
|
||||
}
|
||||
|
||||
return [
|
||||
'base_path' => $_ENV['BASE_PATH'] ?? null,
|
||||
'base_url' => $_ENV['BASE_URL'] ?? null,
|
||||
'locations' => DI\decorate(function($prev, Container $container) {
|
||||
$arr = (array) $prev;
|
||||
$arr['base'] = dirname(__DIR__, 2);
|
||||
|
@ -44,7 +44,7 @@ $container = $builder->build();
|
||||
$app = Bridge::create($container);
|
||||
include_once 'databases.php';
|
||||
|
||||
if ($container->has('base_url')) {
|
||||
if ($container->has('base_url') and $container->get('base_path') !== null) {
|
||||
$app->setBasePath($container->get('base_url'));
|
||||
}
|
||||
$app->add(new ProVM\Money\Common\Middleware\Cors());
|
||||
|
Reference in New Issue
Block a user