Skip to content

Commit

Permalink
#8 - cr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilpiech97 committed Sep 26, 2023
1 parent ce19eb7 commit 8839aba
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @blumilksoftware/blumilk
* @blumilksoftware/keating
5 changes: 2 additions & 3 deletions app/Actions/ActivateSemesterAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace App\Actions;

use App\Enums\SemesterStatus;
use App\Models\Semester;
use Exception;
use Illuminate\Database\ConnectionInterface;
Expand All @@ -23,8 +22,8 @@ public function execute(Semester $semester): void
try {
$this->db->beginTransaction();

Semester::getActive()?->update(["status" => SemesterStatus::INACTIVE]);
$semester->update(["status" => SemesterStatus::ACTIVE]);
Semester::getActive()?->update(["active" => 0]);
$semester->update(["active" => 1]);

$this->db->commit();
} catch (Exception $exception) {
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/Dashboard/SemesterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Actions\ActivateSemesterAction;
use App\Http\Controllers\Controller;
use App\Http\Requests\SemesterRequest;
use App\Http\Resources\SemesterResource;
use App\Models\Semester;
use Exception;
use Illuminate\Http\RedirectResponse;
Expand All @@ -20,7 +19,7 @@ public function index(): Response
$semesters = Semester::query()->orderByDesc("created_at")->get();

return inertia("Dashboard/Semester/Index", [
"semesters" => SemesterResource::collection($semesters),
"semesters" => $semesters,
]);
}

Expand Down
25 changes: 0 additions & 25 deletions app/Http/Resources/SemesterResource.php

This file was deleted.

9 changes: 4 additions & 5 deletions app/Models/Semester.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace App\Models;

use App\Enums\SemesterStatus;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
Expand All @@ -14,7 +13,7 @@
/**
* @property string $id
* @property string $name
* @property SemesterStatus $status
* @property boolean $active
* @property Carbon $created_at
* @property Carbon $updated_at
*/
Expand All @@ -25,15 +24,15 @@ class Semester extends Model

protected $fillable = [
"name",
"status",
"active",
];
protected $casts = [
"status" => SemesterStatus::class,
"active" => "boolean",
];

public function scopeActive(Builder $query): Builder
{
return $query->where("status", SemesterStatus::ACTIVE->value);
return $query->where("active", 1);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions database/factories/SemesterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Database\Factories;

use App\Enums\SemesterStatus;
use Illuminate\Database\Eloquent\Factories\Factory;

class SemesterFactory extends Factory
Expand All @@ -13,7 +12,7 @@ public function definition(): array
{
return [
"name" => "Semestr" . fake()->numberBetween(1, 7),
"status" => fake()->boolean ? SemesterStatus::ACTIVE->value : SemesterStatus::INACTIVE->value,
"active" => fake()->boolean,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function up(): void
Schema::create("semesters", function (Blueprint $table): void {
$table->ulid("id")->primary();
$table->string("name");
$table->enum("status", [1, 0])->default(0);
$table->boolean("active")->default(0);
$table->timestamps();
});
}
Expand Down
8 changes: 4 additions & 4 deletions resources/js/Pages/Dashboard/Semester/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const semesterToDeleteId = ref(0)

<template>
<DashboardLayout>
<div v-if="semesters.data.length" class="flex flex-col gap-8">
<div v-if="semesters.length" class="flex flex-col gap-8">
<ManagementHeader>
<template #header>
Zarządzanie semestrami
Expand All @@ -45,15 +45,15 @@ const semesterToDeleteId = ref(0)
<TableHeader />
</template>
<template #body>
<TableRow v-for="semester in semesters.data" :key="semester.id" :class="semester.status === 'active' ? 'bg-green-50' : ''">
<TableRow v-for="semester in semesters" :key="semester.id" :class="semester.active === true ? 'bg-green-50' : ''">
<TableCell>
{{ semester.name }}
</TableCell>
<TableCell>
{{ semester.statusLabel }}
{{ semester.active ? "aktywny" : "nieaktywny" }}
</TableCell>
<TableCell class="text-right">
<Button v-if="semester.status !== 'active'" :method="Method.POST" :href="`/dashboard/semesters/${semester.id}/activate`">
<Button v-if="semester.status !== true" :method="Method.POST" :href="`/dashboard/semesters/${semester.id}/activate`">
<CheckIcon class="w-6" />
</Button>
<Button :href="`/dashboard/semesters/${semester.id}/edit`">
Expand Down
18 changes: 9 additions & 9 deletions tests/Feature/SemesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,27 @@ public function testSemesterCanBeDeleted(): void

public function testSemesterCanBeSetToActiveStatus(): void
{
$semester = Semester::factory()->create(["status" => 0]);
$this->assertSame(0, $semester->status->value);
$semester = Semester::factory()->create(["active" => 0]);
$this->assertFalse($semester->active);

$this->post("/dashboard/semesters/{$semester->id}/activate");

$semester->refresh();
$this->assertSame(1, $semester->status->value);
$this->assertTrue($semester->active);
}

public function testOnlyOneSemesterCanBeActive(): void
{
$inactiveSemester = Semester::factory()->create(["status" => 0]);
$activeSemester = Semester::factory()->create(["status" => 1]);
$this->assertSame(0, $inactiveSemester->status->value);
$this->assertSame(1, $activeSemester->status->value);
$inactiveSemester = Semester::factory()->create(["active" => 0]);
$activeSemester = Semester::factory()->create(["active" => 1]);
$this->assertFalse($inactiveSemester->active);
$this->assertTrue($activeSemester->active);

$this->post("/dashboard/semesters/{$inactiveSemester->id}/activate");

$inactiveSemester->refresh();
$activeSemester->refresh();
$this->assertSame(1, $inactiveSemester->status->value);
$this->assertSame(0, $activeSemester->status->value);
$this->assertTrue($inactiveSemester->active);
$this->assertFalse($activeSemester->active);
}
}

0 comments on commit 8839aba

Please sign in to comment.