-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from romo4ko/dev
Dev
- Loading branch information
Showing
18 changed files
with
354 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\DTO\Api\Challenge\Request; | ||
|
||
use App\Models\Enums\Challenge\ChallengeType; | ||
use Spatie\LaravelData\Data; | ||
|
||
class ChallengeFilterDTO extends Data | ||
{ | ||
public function __construct( | ||
public ?ChallengeType $challengeType, | ||
public ?string $startDate, | ||
public ?string $endDate, | ||
){ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DTO\Api\Challenge\Response; | ||
|
||
use App\Models\Challenge; | ||
use App\Models\User; | ||
use Illuminate\Database\Eloquent\Collection; | ||
use Spatie\LaravelData\Data; | ||
|
||
class ChallengeShowDTO extends Data | ||
{ | ||
public function __construct( | ||
public Challenge $challenge, | ||
public Collection $members, | ||
) { | ||
} | ||
|
||
public static function fromModel(Challenge $challenge): self | ||
{ | ||
return new self( | ||
$challenge, | ||
$challenge->users()->get(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\DTO\Api\User\Response; | ||
|
||
use App\Models\User; | ||
use Spatie\LaravelData\Data; | ||
|
||
class UserShowDTO extends Data | ||
{ | ||
public function __construct( | ||
public User $user, | ||
public bool $isEditor | ||
){ | ||
} | ||
|
||
public static function fromModel(User $user): self | ||
{ | ||
return new self( | ||
$user, | ||
$user->id === auth()->id() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DTO\Api\User\Response; | ||
|
||
use App\Models\Team; | ||
use Illuminate\Database\Eloquent\Collection; | ||
use Spatie\LaravelData\Data; | ||
|
||
class UserTeamIsCaptainDTO extends Data | ||
{ | ||
public function __construct( | ||
public int $id, | ||
public ?string $image, | ||
public string $name, | ||
public ?int $countMembers | ||
) { | ||
} | ||
|
||
public static function fromModal(Team $team): self | ||
{ | ||
return new self( | ||
$team->id, | ||
$team->image, | ||
$team->name, | ||
$team->users->count(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\Filament\Pages; | ||
|
||
use Filament\Pages\BasePage; | ||
use Filament\Panel; | ||
|
||
class Dashboard extends BasePage | ||
{ | ||
public function panel(Panel $panel): Panel | ||
{ | ||
return $panel->pages([]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Filament\Widgets; | ||
|
||
use App\Models\User; | ||
use Carbon\Carbon; | ||
use Filament\Widgets\StatsOverviewWidget as BaseWidget; | ||
use Filament\Widgets\StatsOverviewWidget\Stat; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class StatsOverview extends BaseWidget | ||
{ | ||
protected function getStats(): array | ||
{ | ||
return [ | ||
Stat::make('Новых пользователей за этот месяц', | ||
User::query()->where('created_at', '>=', Carbon::now()->startOfMonth())->count()) | ||
->chart(self::getCountUsersRegisteredForLastMonth()) | ||
->color('success'), | ||
Stat::make( | ||
'Активных пользователей', | ||
User::query()->where('is_confirmed', true)->count() | ||
), | ||
Stat::make( | ||
'Всего пользователей', | ||
User::query()->count() | ||
), | ||
]; | ||
} | ||
|
||
private function getCountUsersRegisteredForLastMonth(): array | ||
{ | ||
$results = []; | ||
$startTime = Carbon::now()->startOfMonth(); | ||
$daysLeft = $startTime->diffInDays(Carbon::now()); | ||
|
||
for ($i = 0; $i < $daysLeft; $i++) { | ||
$endTime = $startTime->copy()->addDay(); | ||
$count = DB::table('users') | ||
->whereBetween('created_at', [ | ||
$startTime, | ||
$endTime, | ||
]) | ||
->count(); | ||
$results[] = $count; | ||
$startTime = $endTime; | ||
} | ||
|
||
return $results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\DTO\Api\Challenge\Request\ChallengeFilterDTO; | ||
use App\Models\Challenge; | ||
use App\Services\Api\ChallengeService; | ||
|
||
class ChallengeController extends Controller | ||
{ | ||
public function __construct( | ||
protected ChallengeService $challengeService | ||
){ | ||
} | ||
|
||
public function index(ChallengeFilterDTO $challengeFilterDTO): array | ||
{ | ||
return $this->challengeService->index($challengeFilterDTO); | ||
} | ||
|
||
public function show(int $id): array | ||
{ | ||
$challenge = Challenge::query()->findOrFail($id); | ||
|
||
return $this->challengeService->show($challenge); | ||
} | ||
|
||
public function joinPersonal(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function joinTeam(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\Services\Api; | ||
|
||
use App\DTO\Api\Challenge\Request\ChallengeFilterDTO; | ||
use App\DTO\Api\Challenge\Response\ChallengeShowDTO; | ||
use App\Models\Challenge; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
class ChallengeService | ||
{ | ||
public function index(ChallengeFilterDTO $challengeFilterDTO): array | ||
{ | ||
$games = Challenge::query() | ||
->when($challengeFilterDTO->challengeType, function (Builder $query) use ($challengeFilterDTO) { | ||
$query->where('type', '=', $challengeFilterDTO->challengeType->value); | ||
}) | ||
->when($challengeFilterDTO->startDate, function (Builder $query) use ($challengeFilterDTO) { | ||
$query->where('start_date', '>=', $challengeFilterDTO->startDate); | ||
}) | ||
->when($challengeFilterDTO->endDate, function (Builder $query) use ($challengeFilterDTO) { | ||
$query->where('end_date', '<=', $challengeFilterDTO->endDate); | ||
}) | ||
->orderBy('end_date', 'desc') | ||
->get(); | ||
|
||
return $games->toArray(); | ||
} | ||
|
||
public function show(Challenge $challenge): array | ||
{ | ||
return ChallengeShowDTO::from($challenge)->toArray(); | ||
} | ||
} |
Oops, something went wrong.