Skip to content
Merged
6 changes: 1 addition & 5 deletions app/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace App;

use App\Cron\UpdateBotActivity;
use App\Modules\GooseBoards\Http\Controllers\GooseBoardController;
use Illuminate\Support\Facades\Route;
use Laracord\Laracord;

class Bot extends Laracord
Expand All @@ -20,8 +18,6 @@ protected function bootServices(): self

public function routes(): void
{
Route::middleware('api')->group(function () {
Route::post('goose-board', [GooseBoardController::class, 'create']);
});
//
}
}
5 changes: 2 additions & 3 deletions app/Laracord/SlashCommands/ValidatableCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ class ValidatableCallback
{
protected $callback;

public function __construct(
callable $callback
) {
public function __construct(callable $callback)
{
$this->callback = $callback;
}

Expand Down
29 changes: 0 additions & 29 deletions app/Modules/GooseBoards/Http/Controllers/GooseBoardController.php

This file was deleted.

89 changes: 0 additions & 89 deletions app/Modules/GooseBoards/Http/Requests/GooseBoardRequest.php

This file was deleted.

20 changes: 0 additions & 20 deletions app/Modules/GooseBoards/Http/Resources/AccountResource.php

This file was deleted.

26 changes: 0 additions & 26 deletions app/Modules/GooseBoards/Http/Resources/GooseBoardResource.php

This file was deleted.

22 changes: 0 additions & 22 deletions app/Modules/GooseBoards/Http/Resources/TeamResource.php

This file was deleted.

22 changes: 0 additions & 22 deletions app/Modules/GooseBoards/Http/Resources/TileResource.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GooseBoardBoardGenerator
{
protected const TILE_SIZE = 250;

protected const HORIZONTAL_RUN = 6;
protected const HORIZONTAL_RUN = 4;

protected const VERTICAL_RUN = 2;

Expand Down
33 changes: 31 additions & 2 deletions app/Modules/GooseBoards/Library/Repository/TeamRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,42 @@
use App\Modules\GooseBoards\Models\GooseBoard;
use App\Modules\GooseBoards\Models\Team;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;

class TeamRepository
{
public function findTeam(Account $account, GooseBoard $board): Team|null
public function findTeamByAccount(Account $account, GooseBoard $board): Team|null
{
return $board->teams()
return $board
->teams()
->whereHas('accounts', fn (Builder $query) => $query->whereKey($account->getKey()))
->first();
}

public function alreadyAssigned(Account $account, GooseBoard $board): bool
{
return $account
->teams()
->whereHas('gooseBoard', fn (Builder $query) => $query->whereKey($board->getKey()))
->exists();
}

public function searchByName(string $value): Collection
{
return Team::query()
->whereLike('name', $value)
->get();
}

public function get(): Collection
{
return Team::query()->get();
}

public function find(string $name): Team|null
{
return Team::query()
->whereLike('name', $name)
->first();
}
Comment thread
Opblaasmaatje marked this conversation as resolved.
}
30 changes: 30 additions & 0 deletions app/Modules/GooseBoards/Library/Repository/TileRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Modules\GooseBoards\Library\Repository;

use App\Modules\GooseBoards\Models\Queries\TileQuery;
use App\Modules\GooseBoards\Models\Tile;
use Illuminate\Database\Eloquent\Collection;

class TileRepository
{
public readonly TileQuery $query;

public function __construct()
{
$this->query = Tile::query();
}

public function find($name): ?Tile
{
return $this
->query
->whereLike('name', $name)
->first();
}

public function search(mixed $value): Collection
{
return $this->query->whereLike('name', $value)->get();
}
}
25 changes: 10 additions & 15 deletions app/Modules/GooseBoards/Library/Services/GooseBoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use App\Modules\GooseBoards\Library\Repository\GooseBoardRepository;
use App\Modules\GooseBoards\Library\Services\Leaderboard\Leaderboard;
use App\Modules\GooseBoards\Models\GooseBoard;
use Illuminate\Support\Arr;
use Carbon\CarbonPeriodImmutable;

class GooseBoardService
{
Expand All @@ -17,23 +17,18 @@ public function __construct(
) {
}

public function create(array $data): GooseBoard
public function create(string $name, CarbonPeriodImmutable $period): GooseBoard
{
$board = GooseBoard::query()->create(
Arr::only($data['goose_board'], (new GooseBoard)->getFillable())
);
$board = new GooseBoard()->fill([
'name' => $name,
'starts_at' => $period->start,
'ends_at' => $period->end,
'image' => null,
]);

collect($data['tiles'])->each(function (array $tile) use ($board) {
return $this->tileService->create($board, $tile);
});
$board->save();

collect($data['teams'])->each(function (array $team) use ($board) {
return $this->teamService->create($board, $team);
});

$board = $this->generateBoard($board);

return $board->load(['teams', 'tiles']);
return $board;
}

public function leaderboard(GooseBoard $gooseBoard): Leaderboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public function getIcon(): ?string

public function getPosition(): string
{
return "{$this->team->position}/{$this->team->gooseBoard->tiles->count()}";
return $this->team->current_position;
}
}
Loading