Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add predictions #28

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
650a1d2
Add beserious logo
Simoneu01 Apr 29, 2022
0b91a9a
Add username and about to user model
Simoneu01 Apr 29, 2022
aa05ff4
Update profile information form with new style
Simoneu01 Apr 29, 2022
90c1b25
Update set and update passwords
Simoneu01 Apr 29, 2022
67aa1c0
Update name
Simoneu01 Apr 29, 2022
29f3d4e
Create GameshardApi.php
Simoneu01 Apr 29, 2022
9658877
Create predictions page
Simoneu01 Apr 29, 2022
c32f651
Restyled by php-cs-fixer (#29)
restyled-io[bot] May 5, 2022
b267a34
Create game resesource
Simoneu01 May 5, 2022
647c614
Create Game.php
Simoneu01 May 5, 2022
49f675b
Remove billing
Simoneu01 May 5, 2022
bbfc40c
Create 2022_04_29_212358_create_games_table.php
Simoneu01 May 5, 2022
92563a3
Install filament-code-editor
Simoneu01 May 5, 2022
c5922f6
Merge branch 'predictions' of https://github.com/Simoneu01/BeSerious.…
Simoneu01 May 5, 2022
bce76d7
Update composer.lock
Simoneu01 May 5, 2022
26f369c
Update button
Simoneu01 May 5, 2022
d034fce
Update PasswordMiddleware.php
Simoneu01 May 5, 2022
5d45305
Set username to nullable
Simoneu01 May 5, 2022
7ed570e
Update phpstan-baseline.neon
Simoneu01 May 5, 2022
4ba4226
Install laravel-ide-helper
Simoneu01 May 5, 2022
7515743
Add phpdocs
Simoneu01 May 5, 2022
7aaeccc
Update UpdatePasswordTest.php
Simoneu01 May 5, 2022
f584e80
Restyle feat: add predictions (#30)
restyled-io[bot] May 17, 2022
73e0615
wip
Simoneu01 May 17, 2022
af54ede
Create SetPasswordTest.php
Simoneu01 May 17, 2022
9728b3a
Update BrowserSessionsTest.php
Simoneu01 May 17, 2022
1cc0e45
Restyle feat: add predictions (#31)
restyled-io[bot] May 17, 2022
1175c35
Merge branch 'main' into predictions
Simoneu01 Jan 26, 2023
cddc5d9
Update composer.lock
Simoneu01 Jan 26, 2023
ee67ef0
Update laravel.yml
Simoneu01 Jan 26, 2023
5e6f639
chore: compile assets
Simoneu01 Jan 26, 2023
1f26899
bump npm deps
Simoneu01 Jan 26, 2023
16984b4
Update filament shield
Simoneu01 Jan 26, 2023
0f578ae
Follow upgrade guide
Simoneu01 Jan 26, 2023
04b33ea
Merge branch 'predictions' of https://github.com/Simoneu01/BeSerious.…
Simoneu01 Jan 26, 2023
7ed8a03
Create filament-shield.php
Simoneu01 Jan 26, 2023
6fa24bc
Install laravel telescope
Simoneu01 Jan 26, 2023
e0b6e22
Update rankings
Simoneu01 Jan 27, 2023
687452b
add scripts
Simoneu01 Jan 27, 2023
d4e327d
Publish paginations
Simoneu01 Jan 27, 2023
8781511
Update css
Simoneu01 Jan 27, 2023
e28963b
Update tailwind.config.js
Simoneu01 Jan 27, 2023
efd478a
Update Rankings.php
Simoneu01 Jan 27, 2023
ef73834
Stet deafult photo
Simoneu01 Jan 27, 2023
8865540
Create other staffs
Simoneu01 Jan 27, 2023
dcaef5e
fix
Simoneu01 Jan 27, 2023
8052334
Update testimonials.blade.php
Simoneu01 Jan 27, 2023
d1127dd
wip
Simoneu01 Jan 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/Actions/Fortify/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function update($user, array $input)
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
'username' => ['required', 'string', 'max:255', Rule::unique('users')->ignore($user->id)],
'about' => ['nullable', 'string'],
'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
])->validateWithBag('updateProfileInformation');

Expand All @@ -35,6 +37,8 @@ public function update($user, array $input)
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'username' => $input['username'],
'about' => $input['about'],
])->save();
}
}
Expand Down
83 changes: 83 additions & 0 deletions app/Filament/Resources/GameResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\GameResource\Pages;
use App\Filament\Resources\GameResource\RelationManagers;
use App\Models\Game;
use App\Models\Team;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use SebastiaanKloos\FilamentCodeEditor\Components\CodeEditor;

class GameResource extends Resource
{
protected static ?string $model = Game::class;

protected static ?string $navigationIcon = 'heroicon-o-collection';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\BelongsToSelect::make('home_team_id')
->placeholder("Seleziona un'opzione")
->relationship('homeTeam', 'name')
->getOptionLabelFromRecordUsing(fn (Team $record) => "{$record->name} - ID: {$record->id}")
->searchable()
->default(fn ($livewire) => $livewire instanceof Pages\EditGame ? $livewire->record->homeTeam : null),
Forms\Components\BelongsToSelect::make('away_team_id')
->placeholder("Seleziona un'opzione")
->relationship('awayTeam', 'name')
->getOptionLabelFromRecordUsing(fn (Team $record) => "{$record->name} - ID: {$record->id}")
->searchable()
->default(fn ($livewire) => $livewire instanceof Pages\EditGame ? $livewire->record->awayTeam : null),

Forms\Components\TextInput::make('gameshard_match_id')
->required()
->maxLength(255),
CodeEditor::make('data')
->afterStateHydrated(function ($state, $set) {
$set('data', json_encode($state));
})
->dehydrateStateUsing(fn ($state) => (array) json_decode($state))
->required(),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('home_team_id'),
Tables\Columns\TextColumn::make('away_team_id'),
Tables\Columns\TextColumn::make('gameshard_match_id'),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
Tables\Columns\TextColumn::make('updated_at')
->dateTime(),
])
->filters([
//
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListGames::route('/'),
'create' => Pages\CreateGame::route('/create'),
'edit' => Pages\EditGame::route('/{record}/edit'),
];
}
}
11 changes: 11 additions & 0 deletions app/Filament/Resources/GameResource/Pages/CreateGame.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Filament\Resources\GameResource\Pages;

use App\Filament\Resources\GameResource;
use Filament\Resources\Pages\CreateRecord;

class CreateGame extends CreateRecord
{
protected static string $resource = GameResource::class;
}
11 changes: 11 additions & 0 deletions app/Filament/Resources/GameResource/Pages/EditGame.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Filament\Resources\GameResource\Pages;

use App\Filament\Resources\GameResource;
use Filament\Resources\Pages\EditRecord;

class EditGame extends EditRecord
{
protected static string $resource = GameResource::class;
}
11 changes: 11 additions & 0 deletions app/Filament/Resources/GameResource/Pages/ListGames.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Filament\Resources\GameResource\Pages;

use App\Filament\Resources\GameResource;
use Filament\Resources\Pages\ListRecords;

class ListGames extends ListRecords
{
protected static string $resource = GameResource::class;
}
51 changes: 51 additions & 0 deletions app/Http/ExternalApi/GameshardApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Http\ExternalApi;

use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;

class GameshardApi
{
private string $gameshardToken;

public function __construct()
{
$this->gameshardToken = config('services.gameshard.api_key');
}

/**
* @throws RequestException
*/
public function pullPlaydays(int $tournamentId, int $phaseId): Collection
{
$playdays = Http::withToken($this->gameshardToken)
->get("https://gameshard.io/api/tournaments/$tournamentId/phases/$phaseId/rounds")
->throw()
->json('data');

return collect($playdays)->pluck('id');
}

/**
* @throws RequestException
*/
public function pullMatchesFromPlayday(string $playday)
{
return Http::withToken($this->gameshardToken)
->get("https://gameshard.io/api/matches?filter[round_id]=$playday")
->throw()
->json('data');
}

/**
* @throws RequestException
*/
public function pullMatchesIdsFromPlayday(string $playday)
{
$matches = $this->pullMatchesFromPlayday($playday);

return collect($matches)->pluck('id');
}
}
20 changes: 20 additions & 0 deletions app/Http/Livewire/Profile/ConnectedAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Livewire\Profile;

use Illuminate\Contracts\View\View;
use JoelButcher\Socialstream\Http\Livewire\ConnectedAccountsForm;

class ConnectedAccount extends ConnectedAccountsForm
{
/**
* Render the component.
*
* @return View
*/
public function render(): View
{
return view('profile.connected-accounts-form')
->layout('profile.show');
}
}
20 changes: 20 additions & 0 deletions app/Http/Livewire/Profile/SetPassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Livewire\Profile;

use Illuminate\Contracts\View\View;
use JoelButcher\Socialstream\Http\Livewire\SetPasswordForm;

class SetPassword extends SetPasswordForm
{
/**
* Render the component.
*
* @return View
*/
public function render(): View
{
return view('profile.set-password-form')
->layout('profile.show');
}
}
20 changes: 20 additions & 0 deletions app/Http/Livewire/Profile/UpdatePassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Livewire\Profile;

use Illuminate\Contracts\View\View;
use Laravel\Jetstream\Http\Livewire\UpdatePasswordForm;

class UpdatePassword extends UpdatePasswordForm
{
/**
* Render the component.
*
* @return View
*/
public function render(): View
{
return view('profile.update-password-form')
->layout('profile.show');
}
}
20 changes: 20 additions & 0 deletions app/Http/Livewire/Profile/UpdateProfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Livewire\Profile;

use Illuminate\Contracts\View\View;
use Laravel\Jetstream\Http\Livewire\UpdateProfileInformationForm;

class UpdateProfile extends UpdateProfileInformationForm
{
/**
* Render the component.
*
* @return View
*/
public function render(): View
{
return view('profile.update-profile-information-form')
->layout('profile.show');
}
}
18 changes: 18 additions & 0 deletions app/Http/Middleware/HavePasswordMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class HavePasswordMiddleware
{
public function handle(Request $request, Closure $next)
{
if (is_null(auth()->user()->password)) {
return to_route('profile.new-password');
}

return $next($request);
}
}
18 changes: 18 additions & 0 deletions app/Http/Middleware/PasswordMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class PasswordMiddleware
{
public function handle(Request $request, Closure $next)
{
if (auth()->user()->password) {
return to_route('profile.show.password');
}

return $next($request);
}
}
35 changes: 35 additions & 0 deletions app/Models/Game.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Game extends Model
{
/** @inheritdoc */
protected $fillable = [
'gameshard_match_id',
'home_team_id',
'away_team_id',
'data'
];

protected $casts = [
'data' => 'json'
];

public function homeTeam()
{
return $this->belongsTo(Team::class, 'home_team_id');
}

public function awayTeam()
{
return $this->belongsTo(Team::class, 'away_team_id');
}

public function teams()
{
return collect([$this->homeTeam])->add($this->awayTeam);
}
}
4 changes: 3 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasAvatar;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
Expand All @@ -12,7 +13,6 @@
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
use Laravel\Sanctum\HasApiTokens;
use Filament\Models\Contracts\FilamentUser;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable implements FilamentUser, HasAvatar
Expand All @@ -33,6 +33,8 @@ class User extends Authenticatable implements FilamentUser, HasAvatar
'name',
'email',
'password',
'about',
'username',
];

/**
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"livewire/livewire": "^2.4",
"owenvoke/blade-fontawesome": "^2.0",
"ralphjsmit/laravel-filament-seo": "^0.7.0",
"sebastiaankloos/filament-code-editor": "^1.0",
"socialiteproviders/discord": "^4.1",
"spatie/data-transfer-object": "^3.7",
"symfony/http-client": "^6.0",
Expand Down
Loading