|
@@ -17,6 +17,8 @@ use Psr\Http\Message\{
|
|
|
use RS\DummyData;
|
|
use RS\DummyData;
|
|
|
use RS\Application\AppPattern;
|
|
use RS\Application\AppPattern;
|
|
|
|
|
|
|
|
|
|
+use RS\DB\DatabasePool;
|
|
|
|
|
+
|
|
|
class MyHandler extends Handler {
|
|
class MyHandler extends Handler {
|
|
|
public function soos(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
|
|
public function soos(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
|
|
|
$lel[] = 'A';
|
|
$lel[] = 'A';
|
|
@@ -134,6 +136,44 @@ class MyHandler extends Handler {
|
|
|
return $response->withJson($obj);
|
|
return $response->withJson($obj);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function applicationPost(ServerRequestInterface $request, ResponseInterface $response, \stdClass $args): ResponseInterface {
|
|
|
|
|
+
|
|
|
|
|
+ //TODO: Backend
|
|
|
|
|
+ // Validate struct, expected is:
|
|
|
|
|
+ // (token) + pattern Version + array of answers
|
|
|
|
|
+ // Validate the amount of answers ~ pattern amount
|
|
|
|
|
+ // Validate correct version of pattern
|
|
|
|
|
+ // Validate with regex
|
|
|
|
|
+
|
|
|
|
|
+ //TODO: Frontend
|
|
|
|
|
+ // Escape?
|
|
|
|
|
+ // Convert characters?
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ $response->write('Input:{');
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($request->getParsedBody() as $key => $value) {
|
|
|
|
|
+ $response->write('[' . $key . ':' . $value . ']');
|
|
|
|
|
+ }
|
|
|
|
|
+ return $response->write("}");
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ $db = DatabasePool::getDB();
|
|
|
|
|
+
|
|
|
|
|
+ $parsed = $request->getParsedBody();
|
|
|
|
|
+
|
|
|
|
|
+ $username = $parsed['creator'];
|
|
|
|
|
+ $answers = $parsed['answers'];
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ $db->query('INSERT INTO `dev_applications` (`creator`, `date`, `answers`) VALUES (:creator, now(), :answers)', [$username, json_encode($answers)]);
|
|
|
|
|
+ } catch (Exception $e) {
|
|
|
|
|
+ //return $response->write($e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $response;//->write('Lol.');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static function getRoutes(): array {
|
|
public static function getRoutes(): array {
|
|
|
return [
|
|
return [
|
|
|
new Route('GET', '/soos', 'soos'),
|
|
new Route('GET', '/soos', 'soos'),
|
|
@@ -143,6 +183,7 @@ class MyHandler extends Handler {
|
|
|
new Route('GET', '/dummies', 'dummies'),
|
|
new Route('GET', '/dummies', 'dummies'),
|
|
|
new Route('GET', '/application/{id:[0-9]+}', 'application'),
|
|
new Route('GET', '/application/{id:[0-9]+}', 'application'),
|
|
|
new Route('GET', '/app-pattern', 'appPattern'),
|
|
new Route('GET', '/app-pattern', 'appPattern'),
|
|
|
|
|
+ new Route('POST', '/application', 'applicationPost'),
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|