-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
74 changed files
with
69,559 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,8 @@ yarn-error.log | |
/.fleet | ||
/.idea | ||
/.vscode | ||
composer.lock | ||
|
||
# ignore .http file | ||
|
||
/.http |
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,96 @@ | ||
<?php | ||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Models\Assessment; | ||
use Exception; | ||
use Illuminate\Http\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class AssessmentController extends Controller | ||
{ | ||
|
||
|
||
public function create_assessment(Request $request) | ||
{ | ||
$result = $request->validate([ | ||
'user_id' => 'required', | ||
'name' => 'required', | ||
'start_date' => 'required', | ||
'start_time' => 'required', | ||
]); | ||
|
||
if ($result) { | ||
try { | ||
$data = file_get_contents("php://input"); | ||
$assessment = new Assessment(); | ||
$assessment->user_id = $data->user_id; | ||
$assessment->name = $data->name; | ||
$assessment->start_date = $data->start_date; | ||
$assessment->start_time = $data->start_time; | ||
$assessment->save(); | ||
return $this->successResponse(true, 'Assessment created successfully', Response::HTTP_CREATED); | ||
|
||
} catch (Exception $e) { | ||
return $this->errorResponse('Assessment could not be created', $e->getMessage()); | ||
} | ||
|
||
} | ||
} | ||
|
||
// @dreywandowski ---- delete an assessment | ||
public function deleteAss($ass_id): JsonResponse | ||
{ | ||
try{ | ||
$assessment = Assessment::findorFail($ass_id); | ||
|
||
if( !$assessment) { | ||
return $this->errorResponse( | ||
'Assessment does not exist', | ||
'Assessment not found', | ||
Response::HTTP_NOT_FOUND | ||
); | ||
} | ||
$assessment->delete(); | ||
|
||
return $this->successResponse(true, 'Assessment deleted successfully', Response::HTTP_OK); | ||
} catch (Exception $e) { | ||
return $this->errorResponse('Assessment not fetched', $e->getMessage()); | ||
} | ||
|
||
} | ||
|
||
public function update(Request $request, $id){ | ||
try { | ||
// $user = auth('sanctum')->user()->id; | ||
$this->validate($request, [ | ||
'name' =>'required', | ||
'start_date' =>'required', | ||
'start_time' =>'required', | ||
]); | ||
$assessment = Assessment::findorFail($id); | ||
if( !$assessment) { | ||
return $this->errorResponse( | ||
'Assessment does not exist', | ||
'Assessment not found', | ||
Response::HTTP_NOT_FOUND | ||
); | ||
} | ||
$assessment->name = $request->input['name']; | ||
$assessment->start_date = $request->input['start_date']; | ||
$assessment->start_date = $request->input['start_date']; | ||
$assessment->save(); | ||
return response()->json([ | ||
'status' => 'Assessment Successfully Updated', | ||
'Data' => $assessment | ||
]); | ||
} catch (Exception $e) { | ||
return $this->errorResponse('Assessment not fetched', $e->getMessage()); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
} | ||
|
134 changes: 134 additions & 0 deletions
134
backend/app/Http/Controllers/AuthenticationController.php
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,134 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Hash; | ||
|
||
class AuthenticationController extends Controller | ||
{ | ||
/** | ||
* Create a new AuthController instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth:api', ['except' => ['register', 'login']]); | ||
} | ||
|
||
/** | ||
* Get a JWT via given credentials. | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function register(Request $request){ | ||
$request->validate([ | ||
'full_name' => 'required|string|max:255', | ||
'username' => 'required|string|max:255|unique:users', | ||
'email' => 'required|string|email|max:255|unique:users', | ||
'password' => 'required|string|min:6', | ||
]); | ||
|
||
$user = User::create([ | ||
'full_name' => $request->full_name, | ||
'username' => $request->username, | ||
'email' => $request->email, | ||
'password' => Hash::make($request->password), | ||
]); | ||
|
||
return response()->json([ | ||
"error" => false, | ||
"code" => 200, | ||
"message" => "User Registration successfull" | ||
]); | ||
} | ||
|
||
/** | ||
* Get a JWT via given credentials. | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function login(Request $request) | ||
{ | ||
$request->validate([ | ||
'email' => 'required|string|email', | ||
'password' => 'required|string', | ||
]); | ||
|
||
$credentials = $request->only('email', 'password'); | ||
|
||
if (!auth()->validate($credentials)) { | ||
return response()->json([ | ||
"error" => true, | ||
"code" => 400, | ||
"message" => "Invalid email or Password" | ||
], 400); | ||
} | ||
|
||
$token = auth()->attempt($credentials); | ||
if (!$token) { | ||
return response()->json([ | ||
'error' => 'true', | ||
"code" => 401, | ||
'message' => 'Unauthorized, Log in to continue', | ||
], 401); | ||
} | ||
|
||
$user = auth()->user(); | ||
return response()->json([ | ||
"error" => false, | ||
"code" => 200, | ||
"message" => "User Logged in", | ||
"data" => [ | ||
'user' => $user, | ||
'authorisation' => [ | ||
'token' => $token, | ||
'type' => 'bearer', | ||
] | ||
] | ||
]); | ||
} | ||
|
||
|
||
/** | ||
* Log the user out (Invalidate the token). | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function logout() | ||
{ | ||
auth()->logout(); | ||
|
||
return response()->json([ | ||
"error" => false, | ||
"code" => 200, | ||
"message" => "User Logged out" | ||
]); | ||
} | ||
|
||
/** | ||
* Refresh a token. | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function refresh() | ||
{ | ||
return response()->json([ | ||
"error" => false, | ||
"code" => 200, | ||
"message" => "User token refreshed", | ||
"data" => [ | ||
'user' => auth()->user(), | ||
'authorisation' => [ | ||
'token' => auth()->refresh(), | ||
'type' => 'bearer', | ||
] | ||
] | ||
]); | ||
} | ||
|
||
} |
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.