feat/user-reg-api #18

Merged
llama merged 6 commits from feat/user-reg-api into master 2023-10-10 03:19:17 -04:00
Owner

All the endpoints I should need to get the user reg stuff done

All the endpoints I should need to get the user reg stuff done
benjamyn added 5 commits 2023-10-10 00:43:53 -04:00
Author
Owner

pls review @llama

pls review @llama
Author
Owner

This satisfies #10

This satisfies https://git.lovelynet.net/PriceyBot/PriceyBotPanel/issues/10
benjamyn added a new dependency 2023-10-10 00:52:11 -04:00
llama requested changes 2023-10-10 01:13:09 -04:00
@ -0,0 +20,4 @@
$validated['status'] = true;
try {
$user = User::create($validated);
}catch (\Illuminate\Database\QueryException $exception){

This probably can just be "Throwable" instead of a specific catch

This probably can just be "Throwable" instead of a specific catch
@ -0,0 +32,4 @@
public function getUser(Request $request, $id)
{
if (!empty($id)){

Normally it's a good idea to reduce if statement nesting so you'd want to do something like

if (empty($id)) {
return response()
                ->json(["status" => "false", "message" => "Please specify UUID"]);
}

...

This removes the need for else's everywhere and removes nesting so it's easier to read

Normally it's a good idea to reduce if statement nesting so you'd want to do something like ``` if (empty($id)) { return response() ->json(["status" => "false", "message" => "Please specify UUID"]); } ... ``` This removes the need for else's everywhere and removes nesting so it's easier to read
@ -0,0 +38,4 @@
$user = User::where('uuid', $id)->firstOrfail();
return response()
->json(["status" => true]);
} catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {

same thing, probably can be just Throwable instead of a specific thing,

same thing, probably can be just Throwable instead of a specific thing,
llama marked this conversation as resolved
routes/api.php Outdated
@ -19,2 +20,4 @@
Route::post('/sendQuote', [WebHookController::class, 'sendQuote']);
Route::post('/randomQuote', [WebHookController::class, 'sendRandomQuote']);
Route::post('/registerUser', [UserController::class, 'registerUser']);
Route::get('/getUser/{id}', [UserController::class, 'getUser']);

https://laravel.com/docs/10.x/routing#implicit-model-binding-scoping

We can do something called model binding, this will allow us to automatically map this to a model without us needing to fetch it afterwards.

Route::get('/getUser/{user:uuid}', [UserController::class, 'getUser']);

and then inside the controller you'd do

public function getUser(Request $request, User $user)

and if you dumb out $user it should be the model already, I think this also handles invalid uuids too with a response

https://laravel.com/docs/10.x/routing#implicit-model-binding-scoping We can do something called model binding, this will allow us to automatically map this to a model without us needing to fetch it afterwards. ``` Route::get('/getUser/{user:uuid}', [UserController::class, 'getUser']); ``` and then inside the controller you'd do ``` public function getUser(Request $request, User $user) ``` and if you dumb out $user it should be the model already, I think this also handles invalid uuids too with a response
llama requested changes 2023-10-10 01:19:21 -04:00
routes/api.php Outdated
@ -18,4 +19,6 @@ Route::middleware(['header.auth', 'throttle:api'])->group(function () {
Route::get('/test', [WebHookController::class, 'test']);
Route::post('/sendQuote', [WebHookController::class, 'sendQuote']);
Route::post('/randomQuote', [WebHookController::class, 'sendRandomQuote']);
Route::post('/registerUser', [UserController::class, 'registerUser']);

we can probably also put this under /user/register and /user since that'll be closer to how standard crud stuff works

https://laravel.com/docs/10.x/controllers#actions-handled-by-resource-controller

This way we'd have consistency once we start adding more models like quotes and stuff to the endpoints

we can probably also put this under /user/register and /user since that'll be closer to how standard crud stuff works https://laravel.com/docs/10.x/controllers#actions-handled-by-resource-controller This way we'd have consistency once we start adding more models like quotes and stuff to the endpoints
benjamyn added 1 commit 2023-10-10 01:34:03 -04:00
llama merged commit d49c43f209 into master 2023-10-10 03:19:17 -04:00
benjamyn removed a dependency 2023-10-11 00:58:14 -04:00
benjamyn deleted branch feat/user-reg-api 2023-10-11 21:36:52 -04:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: PriceyBot/PriceyBotPanel#18
No description provided.