-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6045a88
commit c0524ac
Showing
11 changed files
with
597 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.