SyntaxSquad/DADProject#15 fix: Merge Conflicts Fixed.
This commit is contained in:
@@ -17,15 +17,12 @@ class GameController extends Controller
|
||||
$user = Auth::user();
|
||||
$query = Game::query()->with(["winner", "player1", "player2"]);
|
||||
|
||||
// Filter games based on user type
|
||||
if ($user->type !== 'A') {
|
||||
// Players can only see games they participate in
|
||||
$query->where(function ($q) use ($user) {
|
||||
$q->where('player1_user_id', $user->id)
|
||||
->orWhere('player2_user_id', $user->id);
|
||||
});
|
||||
}
|
||||
// Admins see all games (no filter needed)
|
||||
|
||||
if ($request->has("type") && in_array($request->type, ["3", "9"])) {
|
||||
$query->where("type", $request->type);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\CoinTransaction;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TransactionController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
||||
$this->authorize('viewAny', CoinTransaction::class);
|
||||
|
||||
$query = CoinTransaction::with('user:id,nickname,email', 'type:id,name');
|
||||
|
||||
if ($request->has('sort_coins')) {
|
||||
$direction = $request->get('sort_coins') === 'asc' ? 'asc' : 'desc';
|
||||
$query->orderBy('coins', $direction);
|
||||
}
|
||||
|
||||
$dateDirection = $request->get('sort_datetime') === 'asc' ? 'asc' : 'desc';
|
||||
$query->orderBy('transaction_datetime', $dateDirection);
|
||||
|
||||
|
||||
$transactions = $query->paginate(15);
|
||||
|
||||
return response()->json($transactions);
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,14 @@ class UserController extends Controller
|
||||
|
||||
$query = User::query();
|
||||
|
||||
// Filtros úteis para o Backoffice
|
||||
if ($request->has('type')) {
|
||||
$query->where('type', $request->type);
|
||||
}
|
||||
|
||||
if ($request->has('blocked')) {
|
||||
$query->where('blocked', $request->type);
|
||||
}
|
||||
|
||||
if ($request->has('search')) {
|
||||
$query->where(function ($q) use ($request) {
|
||||
$q->where('name', 'like', '%'.$request->search.'%')
|
||||
@@ -47,7 +50,6 @@ class UserController extends Controller
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'nickname' => 'required|string|max:20|unique:users,nickname',
|
||||
'email' => 'required|email|unique:users,email',
|
||||
'password' => 'required|string|min:3',
|
||||
'type' => 'required|in:A,U',
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\CoinTransaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class CoinTransactionPolicy
|
||||
{
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->type === 'A' ? true : false;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class GamePolicy
|
||||
*/
|
||||
public function view(User $user, Game $game): bool
|
||||
{
|
||||
if ($user->type === 'A') {
|
||||
if ($user->type === "A") {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ class GamePolicy
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($game->status === "Pending") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -39,7 +43,7 @@ class GamePolicy
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
if ($user->type === 'A') {
|
||||
if ($user->type === "A") {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -48,28 +52,32 @@ class GamePolicy
|
||||
|
||||
public function join(User $user, Game $game): bool
|
||||
{
|
||||
if ($user->type === 'A') {
|
||||
if ($user->type === "A") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
$game->status !== 'waiting' ||
|
||||
$game->status !== "Pending" ||
|
||||
$game->player1_user_id === $user->id
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($game->player2_user_id !== null && $game->player2_user_id !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function resign(User $user, Game $game): bool
|
||||
{
|
||||
if ($user->type === 'A') {
|
||||
if ($user->type === "A") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
$game->status !== 'ongoing' ||
|
||||
$game->status !== "Playing" ||
|
||||
($game->player1_user_id !== $user->id &&
|
||||
$game->player2_user_id !== $user->id)
|
||||
) {
|
||||
@@ -84,12 +92,12 @@ class GamePolicy
|
||||
*/
|
||||
public function update(User $user, Game $game): bool
|
||||
{
|
||||
if ($user->type === 'A') {
|
||||
if ($user->type === "A") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
$game->status !== 'ongoing' ||
|
||||
$game->status !== "Playing" ||
|
||||
($game->player1_user_id !== $user->id &&
|
||||
$game->player2_user_id !== $user->id)
|
||||
) {
|
||||
@@ -105,7 +113,7 @@ class GamePolicy
|
||||
public function delete(User $user, Game $game): bool
|
||||
{
|
||||
// Only admins can delete games
|
||||
return $user->type === 'A';
|
||||
return $user->type === "A";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Http\Controllers\ProfileController;
|
||||
use App\Http\Controllers\StatisticsController;
|
||||
use App\Http\Controllers\UserController;
|
||||
use App\Http\Controllers\CoinPurchaseController;
|
||||
use App\Http\Controllers\TransactionController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::prefix('v1')->group(function () {
|
||||
@@ -97,6 +98,7 @@ Route::prefix('v1')->group(function () {
|
||||
->prefix('admin')
|
||||
->group(function () {
|
||||
Route::get('/statistics', [StatisticsController::class, 'getAdminStats']);
|
||||
Route::get('/transactions', [TransactionController::class, 'index']);
|
||||
Route::prefix('users')->group(function () {
|
||||
Route::get('/', [UserController::class, 'index']);
|
||||
Route::post('/', [UserController::class, 'store']);
|
||||
|
||||
@@ -5,7 +5,7 @@ Content-Type: application/json
|
||||
Accept: application/json
|
||||
|
||||
{
|
||||
"email": "p[email protected]",
|
||||
"email": "a1@mail.pt",
|
||||
"password": "123"
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ Accept: application/json
|
||||
@id = {{login.response.body.user.id}}
|
||||
|
||||
### Get All matches
|
||||
GET http://localhost:8000/api/v1/matches
|
||||
GET http://localhost:8000/api/v1/games
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
Authorization: Bearer {{token}}
|
||||
@@ -55,7 +55,7 @@ Authorization: Bearer {{token}}
|
||||
"payment_reference": "912345678"
|
||||
}
|
||||
|
||||
### Get public stats
|
||||
### Get leaderboard
|
||||
GET http://localhost:8000/api/v1/leaderboard
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
@@ -64,4 +64,21 @@ Accept: application/json
|
||||
GET http://localhost:8000/api/v1/statistics/me
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
### Get public stats
|
||||
GET http://localhost:8000/api/v1/statistics/public
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
|
||||
### Get admin stats
|
||||
GET http://localhost:8000/api/v1/admin/statistics
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
### Get admin stats
|
||||
GET http://localhost:8000/api/v1/admin/users
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
Authorization: Bearer {{token}}
|
||||
Reference in New Issue
Block a user