mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 19:12:10 +00:00
migrations and models adjusted
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class RoomController extends Controller
|
||||
{
|
||||
public function create(){
|
||||
return Inertia::render('rooms/CreateRoom');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class VoteController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
+29
-1
@@ -5,7 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use phpDocumentor\Reflection\Types\Boolean;
|
||||
|
||||
class Player extends Model
|
||||
{
|
||||
@@ -13,12 +13,14 @@ class Player extends Model
|
||||
'room_id',
|
||||
'name',
|
||||
'is_moderator',
|
||||
'last_seen_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_moderator' => 'boolean',
|
||||
'last_seen_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -36,4 +38,30 @@ class Player extends Model
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function currentVote(): ?Vote
|
||||
{
|
||||
return $this->votes()
|
||||
->where('round', $this->room->current_round)
|
||||
->first();
|
||||
}
|
||||
|
||||
public function hasVoted(): bool
|
||||
{
|
||||
return $this->votes()
|
||||
->where('round', $this->room->current_round)
|
||||
->exists();
|
||||
}
|
||||
|
||||
public function isModerator(): bool
|
||||
{
|
||||
return $this->is_moderator;
|
||||
}
|
||||
|
||||
public function markAsSeen(): void
|
||||
{
|
||||
$this->update([
|
||||
'last_seen_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Override;
|
||||
|
||||
class Room extends Model
|
||||
{
|
||||
@@ -29,10 +30,38 @@ class Room extends Model
|
||||
];
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function (Room $room) {
|
||||
$room->join_code ??= static::generateJoinCode();
|
||||
});
|
||||
}
|
||||
|
||||
private static function generateJoinCode(): string
|
||||
{
|
||||
$alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
||||
|
||||
do {
|
||||
$code = '';
|
||||
|
||||
for($i = 0; $i < 6; $i++) {
|
||||
$code .= $alphabet[random_int(0,strlen($alphabet)-1)];
|
||||
}
|
||||
} while (static::where('join_code', $code)->exists());
|
||||
|
||||
return $code;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function players(): HasMany
|
||||
{
|
||||
return $this->hasMany(Player::class);
|
||||
|
||||
}
|
||||
|
||||
public function vote(): HasMany
|
||||
{
|
||||
return $this->hasMany(Vote::class);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -9,7 +9,9 @@ class Vote extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'round',
|
||||
'value',
|
||||
'value',
|
||||
'room_id',
|
||||
'player_id'
|
||||
];
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user