Skip to content

Commit

Permalink
Merge pull request #40 from workshopapps/add_user_score
Browse files Browse the repository at this point in the history
feat: added the add user score route, controller, request, and service
  • Loading branch information
Benrobo authored Nov 17, 2022
2 parents 4e9b955 + 1e5ad26 commit 9d1b275
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
19 changes: 19 additions & 0 deletions backend/app/Http/Controllers/UserScoreController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\UserScoreStoreRequest;

class UserScoreController extends Controller
{
/**
* Store a newly created resource in storage.
*
* @param @param \App\Http\Requests\UserStoreRequest $request
* @return \Illuminate\Http\Response
*/
public function store(UserScoreStoreRequest $request)
{

}
}
30 changes: 30 additions & 0 deletions backend/app/Http/Requests/UserScoreStoreRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserScoreStoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
"category_id" => 'required|exists:categories,id',
];
}
}
19 changes: 19 additions & 0 deletions backend/app/Services/UserScoreService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Services;

use App\Models\UserScore;
use Illuminate\Http\JsonResponse;

class UserScoreService
{
public static function addUserScore($userId): array
{
return UserScore::where('id', $userId)->where('isVerified', true)->first();
}

function sendResponse($error = false, $code = 200, $msg = "", $data = ["" => ""]): JsonResponse
{
return response()->json(["error" => $error, "code" => $code, "message" => $msg, "data" => $data], $code);
}
}
17 changes: 13 additions & 4 deletions backend/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
use App\Http\Controllers\UserScoreController;

// util functions
require_once "../util/sendResponse.php";
// require_once "../util/sendResponse.php";

/*
|--------------------------------------------------------------------------
Expand All @@ -23,11 +24,19 @@
});

// other route functions here
Route::get("/test", function(){
Route::get("/test", function () {
// execute the function
return sendResponse(false, 200, "Test case pass", null);
return sendResponse(false, 200, "Test case pass", null);
});

Route::prefix("users")->group(function(){
Route::prefix("users")->group(function () {
Route::get('verified/{userId}', [UserController::class, 'getVerifiedUserById']);
});

//USERSCORE
Route::prefix("UserScorce")->group(function () {
Route::controller(UserScoreController::class)->group(function () {
Route::get('permissions', 'index');
Route::post('new_permission', 'store');
});
});

0 comments on commit 9d1b275

Please sign in to comment.