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());
|
||||
|
@ -9,6 +9,8 @@ services:
|
||||
volumes:
|
||||
- .:/code
|
||||
- ./app/docker/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
depends_on:
|
||||
- app-php
|
||||
|
||||
app-php:
|
||||
container_name: money_app_php
|
||||
@ -28,6 +30,8 @@ services:
|
||||
volumes:
|
||||
- .:/code
|
||||
- ./ui/docker/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||
depends_on:
|
||||
- ui-php
|
||||
|
||||
ui-php:
|
||||
container_name: money_ui_php
|
||||
@ -39,14 +43,6 @@ services:
|
||||
ports:
|
||||
- 9124:9000
|
||||
|
||||
ui-gulp:
|
||||
container_name: money_ui_gulp
|
||||
build:
|
||||
context: ./ui/docker
|
||||
dockerfile: GULP.Dockerfile
|
||||
volumes:
|
||||
- ./ui:/app
|
||||
|
||||
db:
|
||||
container_name: money_db
|
||||
image: mariadb:latest
|
||||
|
@ -16,9 +16,21 @@ class Currency extends Model {
|
||||
public function values(): ?array {
|
||||
if ($this->values === null) {
|
||||
$this->values = $this->parentOf(Value::class, [Model::CHILD_KEY => 'currency_id']);
|
||||
if ($this->values) {
|
||||
usort($this->values, function($a, $b) {
|
||||
return $b->dateTime()->timestamp - $a->dateTime()->timestamp;
|
||||
});
|
||||
}
|
||||
}
|
||||
return $this->values;
|
||||
}
|
||||
protected $latest;
|
||||
public function latest(): ?Value {
|
||||
if ($this->latest === null) {
|
||||
$this->latest = $this->values()[0];
|
||||
}
|
||||
return $this->latest;
|
||||
}
|
||||
|
||||
protected static $fields = ['code', 'name'];
|
||||
public static function add(ModelFactory $factory, $info) {
|
||||
|
Reference in New Issue
Block a user