All but deletion implemented

This commit is contained in:
2024-09-27 16:34:22 +02:00
parent 06ebef2a44
commit 147c15afe2
6 changed files with 97 additions and 3 deletions

9
.dockerignore Normal file
View File

@ -0,0 +1,9 @@
/Dockerfile
/.git
/.gitea
/var/*
/config/*
/.env
/data/*.db
/wrench.yaml
/.junk

21
Dockerfile Normal file
View File

@ -0,0 +1,21 @@
FROM php:8.3-alpine
ENV TZ=Europe/Stockholm
ARG USERNAME=app
RUN apk add --update tini
ENTRYPOINT [ "/sbin/tini", "--" ]
RUN addgroup -S $USERNAME && adduser -S $USERNAME -G $USERNAME
RUN docker-php-ext-install pcntl
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN printf "[PHP]\ndate.timezone = \"%s\"\n" $TZ > /usr/local/etc/php/conf.d/tzone.ini
WORKDIR /application
COPY . /application
RUN chown app:app /application/data
USER $USERNAME
CMD [ "php", "/application/bin/paramdb" ]

32
Makefile Normal file
View File

@ -0,0 +1,32 @@
.SILENT:
.PHONY: help
COLOR_RESET = \033[0m
COLOR_INFO = \033[32m
COLOR_COMMENT = \033[33m
### Help
help:
printf "${COLOR_COMMENT}Usage:${COLOR_RESET}\n"
printf " make [target]\n\n"
printf "${COLOR_COMMENT}Available targets:${COLOR_RESET}\n"
awk '/^[a-zA-Z\-_0-9\.@]+:/ { \
helpMessage = match(lastLine, /^### (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${COLOR_INFO}%-16s${COLOR_RESET} %s\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
### Build docker image
build:
docker build --rm \
-t dev.noccylabs.info/paramdb/paramdb \
.
### Push the image
push:
docker push dev.noccylabs.info/paramdb/paramdb

View File

@ -130,7 +130,7 @@ class Daemon
foreach ((array)$body as $change) {
echo "Applying change (collection={$collectionName}): ".json_encode($change)."\n";
// echo "Applying change (collection={$collectionName}): ".json_encode($change)."\n";
$id = $change->id??null;
$name = $change->key;
$value = $change->value;

View File

@ -5,5 +5,14 @@ require_once __DIR__."/../vendor/autoload.php";
define("APP_ROOT", dirname(__DIR__));
define("APP_DATA", APP_ROOT."/var");
echo "ParamDB v0.0.0 (c) 2024, NoccyLabs\n";
echo "Licensed under GNU GPL v3 or later\n\n";
echo "Application root: ".APP_ROOT."\n";
echo "Data directory: ".APP_DATA."\n";
echo "Listen address: 0.0.0.0:8000\n";
$daemon = new NoccyLabs\ParamDb\Daemon(APP_DATA."/data.db");
$daemon->start();

View File

@ -42,12 +42,35 @@ class DaemonTest extends \PHPUnit\Framework\TestCase
public function testHandlingSetRequest()
{
$this->markTestSkipped();
$body = json_encode([
[ 'key' => 'third', 'value' => 'd' ]
]);
$request = new ServerRequest("POST", "/test", [ "content-type"=>"application/json" ], $body);
$response = $this->daemon->onRequest($request);
$this->assertEquals(200, $response->getStatusCode());
$request = new ServerRequest("GET", "/test");
$response = $this->daemon->onRequest($request);
$resolved = json_decode($response->getBody()->getContents(), true);
$expect = [
'first' => 'c',
'second' => 'c',
'third' => 'd',
];
$this->assertEquals($expect, $resolved);
}
public function testHandlingGetAllRequest()
{
$this->markTestSkipped();
$request = new ServerRequest("GET", "/test/all");
$response = $this->daemon->onRequest($request);
$this->assertEquals(200, $response->getStatusCode());
}
public function testHandlingDeleteRequest()