Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/Models/User.php
  • Loading branch information
deniskorbakov committed Oct 26, 2024
2 parents ead0f6d + 21e5a4f commit 2842793
Show file tree
Hide file tree
Showing 18 changed files with 320 additions and 50 deletions.
14 changes: 14 additions & 0 deletions app/Enums/ChallengeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Enums;

enum ChallengeType: string
{
case PERSONAL = 'personal';
case TEAM = 'team';

public static function values(): array
{
return array_map(fn (self $case) => $case->value, self::cases());
}
}
22 changes: 18 additions & 4 deletions app/Models/Achievement.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,34 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class Achievement extends Model
{
use HasFactory;

public $timestamps = true;

protected $fillable = ['name', 'description', 'image_id'];

public function challenges()
public function challenges(): BelongsToMany
{
return $this->belongsToMany(Challenge::class);
}

public function users(): belongsToMany
{
return $this->belongsToMany(User::class);
}

public function images(): hasOne
{
return $this->hasMany(Challenge::class);
return $this->hasOne(Image::class);
}

public function image()
public function teams(): belongsToMany
{
return $this->belongsTo(Image::class);
return $this->belongsToMany(Team::class);
}
}
18 changes: 0 additions & 18 deletions app/Models/Category.php

This file was deleted.

23 changes: 14 additions & 9 deletions app/Models/Challenge.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,43 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class Challenge extends Model
{
use HasFactory;

public $timestamps = true;

protected $fillable = [
'name',
'description',
'category_id',
'start_date',
'end_date',
'result',
'achievement_id',
'image_id'
'image_id',
'type'
];

public function users()
public function users(): belongsToMany
{
return $this->belongsToMany(User::class, 'users_challenges');
}

public function image()
public function images(): hasOne
{
return $this->belongsTo(Image::class);
return $this->hasOne(Image::class);
}

public function category()
public function achievements(): belongsToMany
{
return $this->belongsTo(Category::class);
return $this->belongsToMany(Achievement::class);
}

public function achievement()
public function teams(): belongsToMany
{
return $this->belongsTo(Achievement::class);
return $this->belongsToMany(Team::class, 'teams_challenges');
}
}
8 changes: 5 additions & 3 deletions app/Models/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Image extends Model
{
use HasFactory;

public $timestamps = true;
protected $fillable = ['image_path'];

public function users()
public function users(): hasMany
{
return $this->hasMany(User::class);
}

public function challenges()
public function challenges(): hasMany
{
return $this->hasMany(Challenge::class);
}

public function achievements()
public function achievements(): hasMany
{
return $this->hasMany(Achievement::class);
}
Expand Down
35 changes: 35 additions & 0 deletions app/Models/Team.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Team extends Model
{
use HasFactory;

public $timestamps = true;

protected $fillable = [
'name',
'description',
'code'
];

public function users(): belongsToMany
{
return $this->belongsToMany(User::class, 'users_teams');
}

public function challenges(): belongsToMany
{
return $this->belongsToMany(Challenge::class, 'teams_challenges');
}

public function achievements(): belongsToMany
{
return $this->belongsToMany(Achievement::class, 'teams_achievements');
}
}
22 changes: 18 additions & 4 deletions app/Models/User.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
Expand All @@ -22,6 +21,9 @@ class User extends Authenticatable
*
* @var array<int, string>
*/

public $timestamps = true;

protected $fillable = [
'name',
'surname',
Expand All @@ -30,15 +32,27 @@ class User extends Authenticatable
'about',
'image_id',
'is_admin',
'is_confirmed',
'is_admin',
'patronymic',
];

public function challenges()
public function challenges(): BelongsToMany
{
return $this->belongsToMany(Challenge::class, 'users_challenges');
}

public function image()
public function achievements(): BelongsToMany
{
return $this->belongsToMany(Achievement::class, 'users_achievements');
}

public function teams()
{
return $this->belongsToMany(Team::class, 'users_teams');
}

public function images()
{
return $this->belongsTo(Image::class);
}
Expand Down
39 changes: 39 additions & 0 deletions config/base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

return [
'achievements' => [
[
'name' => 'Достижение 1',
'description' => 'Достижение 2',
'image_id' => null
],
[
'name' => 'Достижение 1',
'description' => 'Достижение 2',
'image_id' => null
],
[
'name' => 'Достижение 1',
'description' => 'Достижение 2',
'image_id' => null
],
],

'challenges' => [
[
'name' => 'Задание 1',
'description' => 'Задание 2',
'image_id' => null
],
[
'name' => 'Задание 1',
'description' => 'Задание 2',
'image_id' => null
],
[
'name' => 'Задание 1',
'description' => 'Задание 2',
'image_id' => null
],
],
];
31 changes: 31 additions & 0 deletions database/factories/ChallengeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Enums\ChallengeType;
use App\Models\Achievement;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\Factory;

class ChallengeFactory extends Factory
{
public function definition(): array
{
$now = Carbon::now();

return [
'name' => fake()->text(20),
'description' => fake()->text(),
'start_date' => $now,
'end_date' => $now->addDays(fake()->numberBetween(1, 30)),
'achievement_id' => Achievement::query()->inRandomOrder()->first(),
'image_id' => null,
'type' => fake()->randomElement([
ChallengeType::PERSONAL,
ChallengeType::TEAM
])
];
}
}
30 changes: 30 additions & 0 deletions database/factories/TeamFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\Team;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Team>
*/
class TeamFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
protected $model = Team::class;

public function definition(): array
{
return [
'name' => $this->faker->company,
'description' => $this->faker->sentence,
'code' => strtoupper($this->faker->unique()->lexify('??###')),
];
}
}
5 changes: 4 additions & 1 deletion database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ public function definition(): array
{
return [
'name' => fake()->name(),
'surname' => fake()->lastName(),
'about' => fake()->text(),
'is_confirmed' => true,
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'password' => Hash::make('password'),
'remember_token' => Str::random(10),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function up(): void
$table->id();
$table->string('name');
$table->string('surname');
$table->string('patronymic');
$table->string('patronymic')->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
Expand Down
20 changes: 20 additions & 0 deletions database/seeders/AchievementsSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Database\Seeders;

use App\Models\Achievement;
use Illuminate\Database\Seeder;

class AchievementsSeeder extends Seeder
{
public function run(): void
{
$achievements = config('base.achievements');

foreach ($achievements as $achievement) {
Achievement::query()->create($achievement);
}
}
}
Loading

0 comments on commit 2842793

Please sign in to comment.