-
Notifications
You must be signed in to change notification settings - Fork 387
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 #11563 from nanaya/team-backend
Add basic team backend
- Loading branch information
Showing
20 changed files
with
514 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Team; | ||
use App\Transformers\UserCompactTransformer; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class TeamsController extends Controller | ||
{ | ||
public function show(string $id): Response | ||
{ | ||
$team = Team | ||
::with(array_map( | ||
fn (string $preload): string => "members.user.{$preload}", | ||
UserCompactTransformer::CARD_INCLUDES_PRELOAD, | ||
))->findOrFail($id); | ||
|
||
return ext_view('teams.show', compact('team')); | ||
} | ||
} |
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,82 @@ | ||
<?php | ||
|
||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use App\Libraries\BBCodeForDB; | ||
use App\Libraries\Uploader; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
||
class Team extends Model | ||
{ | ||
protected $casts = ['is_open' => 'bool']; | ||
|
||
private Uploader $header; | ||
private Uploader $logo; | ||
|
||
public function applications(): HasMany | ||
{ | ||
return $this->hasMany(TeamApplication::class); | ||
} | ||
|
||
public function leader(): BelongsTo | ||
{ | ||
return $this->belongsTo(User::class, 'leader_id'); | ||
} | ||
|
||
public function members(): HasMany | ||
{ | ||
return $this->hasMany(TeamMember::class); | ||
} | ||
|
||
public function setHeaderAttribute(?string $value): void | ||
{ | ||
if ($value === null) { | ||
$this->header()->delete(); | ||
} else { | ||
$this->header()->store($value); | ||
} | ||
} | ||
|
||
public function setLogoAttribute(?string $value): void | ||
{ | ||
if ($value === null) { | ||
$this->logo()->delete(); | ||
} else { | ||
$this->logo()->store($value); | ||
} | ||
} | ||
|
||
public function descriptionHtml(): string | ||
{ | ||
$description = presence($this->description); | ||
|
||
return $description === null | ||
? '' | ||
: bbcode((new BBCodeForDB($description))->generate()); | ||
} | ||
|
||
public function header(): Uploader | ||
{ | ||
return $this->header ??= new Uploader( | ||
'teams/header', | ||
$this, | ||
'header_file', | ||
['image' => ['maxDimensions' => [1000, 250]]], | ||
); | ||
} | ||
|
||
public function logo(): Uploader | ||
{ | ||
return $this->logo ??= new Uploader( | ||
'teams/logo', | ||
$this, | ||
'logo_file', | ||
['image' => ['maxDimensions' => [256, 128]]], | ||
); | ||
} | ||
} |
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 | ||
|
||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
class TeamMember extends Model | ||
{ | ||
public $incrementing = false; | ||
|
||
protected $primaryKey = 'user_id'; | ||
|
||
public function team(): BelongsTo | ||
{ | ||
return $this->belongsTo(Team::class); | ||
} | ||
|
||
public function user(): BelongsTo | ||
{ | ||
return $this->belongsTo(User::class, 'user_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
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,32 @@ | ||
<?php | ||
|
||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Team; | ||
use App\Models\User; | ||
|
||
class TeamFactory extends Factory | ||
{ | ||
protected $model = Team::class; | ||
|
||
public function configure(): static | ||
{ | ||
return $this->afterCreating(function (Team $team): void { | ||
$team->members()->create(['user_id' => $team->leader_id]); | ||
}); | ||
} | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'name' => fn () => $this->faker->name(), | ||
'short_name' => fn () => $this->faker->domainWord(), | ||
'leader_id' => User::factory(), | ||
]; | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::create('teams', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('name')->nullable(false); | ||
$table->string('short_name')->nullable(false); | ||
$table->string('logo_file')->nullable(true); | ||
$table->string('header_file')->nullable(true); | ||
$table->string('url')->nullable(true); | ||
$table->text('description')->nullable(true); | ||
$table->boolean('is_open')->nullable(false)->default(true); | ||
$table->smallInteger('default_ruleset_id')->nullable(false)->default(0); | ||
$table->bigInteger('leader_id')->nullable(false); | ||
$table->timestampTz('created_at')->useCurrent(); | ||
$table->timestampTz('updated_at')->useCurrent(); | ||
|
||
$table->unique('name'); | ||
$table->unique('short_name'); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists('teams'); | ||
} | ||
}; |
30 changes: 30 additions & 0 deletions
30
database/migrations/2024_11_30_000001_create_team_members.php
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 | ||
|
||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::create('team_members', function (Blueprint $table) { | ||
$table->unsignedBigInteger('user_id')->primary(); | ||
$table->unsignedBigInteger('team_id')->nullable(false); | ||
$table->timestampTz('created_at')->useCurrent(); | ||
$table->timestampTz('updated_at')->useCurrent(); | ||
|
||
$table->index('team_id'); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists('team_members'); | ||
} | ||
}; |
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,8 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
.team-info-entries { | ||
display: grid; | ||
gap: 10px; | ||
margin-bottom: 20px; | ||
} |
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,12 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
.team-info-entry { | ||
display: grid; | ||
|
||
&__value { | ||
color: hsl(var(--hsl-c2)); | ||
display: grid; | ||
min-width: 0; | ||
} | ||
} |
Oops, something went wrong.