Skip to content

Commit

Permalink
+ post to upload
Browse files Browse the repository at this point in the history
  • Loading branch information
James-jamames committed Sep 28, 2023
1 parent 6045a88 commit c0524ac
Show file tree
Hide file tree
Showing 11 changed files with 597 additions and 400 deletions.
5 changes: 3 additions & 2 deletions docker/development/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ ENV PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \
CURL_LIBS=-L/usr/lib/x86_64-linux-gnu-lcurl \
LIBXML_CFLAGS=-I/path/to/libxml2/include \
LIBXML_LIBS=-L/path/to/libxml2/lib-lxml2 \
COMPOSER_ALLOW_SUPERUSER=1 \
APP_ENV=development \
COMPOSER_ALLOW_SUPERUSER=1 \
APP_URL=http://localhost:8010 \
APP_ENV=local \
APP_DEBUG=true

# setup user as root
Expand Down
4 changes: 2 additions & 2 deletions docker/development/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ else
echo "Directory ./ssh does not exist!"
fi

docker-compose build
docker compose build

docker-compose up -d
docker compose up -d
50 changes: 50 additions & 0 deletions server/app/Http/Controllers/FormController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Http\Controllers;

use App\Models\Answer;
use App\Models\UserAuthorized;
use Exception;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class FormController extends Controller
{
public function store(Request $request)
{
$answer = new Answer;

if (!UserAuthorized::isAuthorized($request->input('email')))
return response()->json([
'mensage' => 'User not authorized.',
'state' => '401',
], Response::HTTP_UNAUTHORIZED);

$answer->answer = $request->input('answer');
$answer->form = $request->input('form');
$answer->date = $request->input('date');

try
{
if ($answer->save()) {
return response()->json([
'mensage' => 'Answer saved succefully.',
'state' => '201',
], Response::HTTP_CREATED);
}
else
{
return response()->json([
'mensage' => 'Answer not saved.',
'state' => '400',
], Response::HTTP_BAD_REQUEST);
}
} catch (Exception $e) {
//TODO: only return message when in dev mode;
return response()->json([
'mensage' => $e->getMessage(),
'state' => '422',
], Response::HTTP_UNPROCESSABLE_ENTITY);
}
}
}
2 changes: 1 addition & 1 deletion server/app/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class VerifyCsrfToken extends Middleware
* @var array<int, string>
*/
protected $except = [
//
'api/form/upload',
];
}
19 changes: 19 additions & 0 deletions server/app/Models/Answer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Answer extends Model
{
use HasFactory;

protected $table = "answers";

protected $fillable = [
'answer',
'form',
'date'
];
}
24 changes: 24 additions & 0 deletions server/app/Models/UserAuthorized.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class UserAuthorized extends Model
{
use HasFactory;

protected $table = "users_authorized";

protected $fillable = [
'email',
'authorized'
];

static public function isAuthorized(string $email) {
$list = UserAuthorized::where("email", $email)->first();

return !is_null($list) ? $list->value('authorized') : false;
}
}
1 change: 1 addition & 0 deletions server/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"require": {
"php": "^8.0.2",
"guzzlehttp/guzzle": "^7.2",
"intervention/image": "^2.7",
"laravel/framework": "^9.19",
"laravel/sanctum": "^3.0",
"laravel/tinker": "^2.7",
Expand Down
Loading

0 comments on commit c0524ac

Please sign in to comment.