-
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.
- Loading branch information
1 parent
ddbb902
commit 967cad3
Showing
17 changed files
with
448 additions
and
3 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 |
---|---|---|
|
@@ -21,4 +21,3 @@ DB_PORT=5432 | |
DB_DATABASE=keating | ||
DB_USERNAME=keating | ||
DB_PASSWORD=password | ||
DB_ROOT_PASSWORD=example |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
enum SemesterStatus: string | ||
{ | ||
case ACTIVE = "active"; | ||
case INACTIVE = "inactive"; | ||
|
||
public function getLabel(): string | ||
{ | ||
return match ($this->value) { | ||
"active" => "aktywny", | ||
"inactive" => "nieaktywny", | ||
}; | ||
} | ||
} |
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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Dashboard; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\SemesterRequest; | ||
use App\Http\Resources\SemesterResource; | ||
use App\Models\Semester; | ||
use Illuminate\Http\RedirectResponse; | ||
use Inertia\Response; | ||
|
||
class SemesterController extends Controller | ||
{ | ||
public function index(): Response | ||
{ | ||
$semesters = Semester::all(); | ||
|
||
return inertia("Dashboard/Semester/Index", [ | ||
"semesters" => SemesterResource::collection($semesters), | ||
]); | ||
} | ||
|
||
public function create(): Response | ||
{ | ||
return inertia("Dashboard/Semester/Create"); | ||
} | ||
|
||
public function store(SemesterRequest $request): RedirectResponse | ||
{ | ||
Semester::query()->create($request->validated()); | ||
|
||
return redirect() | ||
->route("semesters.index") | ||
->with("success", "Dodano semestr"); | ||
} | ||
|
||
public function edit(Semester $semester): Response | ||
{ | ||
return inertia("Dashboard/Semester/Edit", [ | ||
"semester" => $semester, | ||
]); | ||
} | ||
|
||
public function update(SemesterRequest $request, Semester $semester): RedirectResponse | ||
{ | ||
$semester->update($request->validated()); | ||
|
||
return redirect() | ||
->route("semesters.index") | ||
->with("success", "Zaktualizowano semestr"); | ||
} | ||
|
||
public function destroy(Semester $semester): RedirectResponse | ||
{ | ||
$semester->delete(); | ||
|
||
return redirect()->back() | ||
->with("success", "Usunięto semestr"); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class SemesterRequest extends FormRequest | ||
{ | ||
public function rules(): array | ||
{ | ||
return [ | ||
"name" => ["required", "max:255"], | ||
]; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Resources; | ||
|
||
use App\Models\Semester; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class SemesterResource extends JsonResource | ||
{ | ||
public function toArray(Request $request): array | ||
{ | ||
/** @var Semester $semester */ | ||
$semester = $this; | ||
|
||
return [ | ||
"name" => $semester->name, | ||
"status" => $semester->status, | ||
"status_label" => $semester->status->getLabel(), | ||
]; | ||
} | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use App\Enums\SemesterStatus; | ||
use Carbon\Carbon; | ||
use Illuminate\Database\Eloquent\Concerns\HasUlids; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @property string $id | ||
* @property string $name | ||
* @property SemesterStatus $status | ||
* @property Carbon $created_at | ||
* @property Carbon $updated_at | ||
*/ | ||
class Semester extends Model | ||
{ | ||
use HasFactory; | ||
use HasUlids; | ||
|
||
protected $fillable = [ | ||
"name", | ||
"status", | ||
]; | ||
protected $casts = [ | ||
"status" => SemesterStatus::class, | ||
]; | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class SemesterFactory extends Factory | ||
{ | ||
public function definition(): array | ||
{ | ||
return [ | ||
"name" => "Semestr" . fake()->numberBetween(1, 7), | ||
]; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
database/migrations/2023_09_23_075139_create_semesters_table.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,24 @@ | ||
<?php | ||
|
||
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("semesters", function (Blueprint $table): void { | ||
$table->ulid("id")->primary(); | ||
$table->string("name"); | ||
$table->enum("status", ["active", "inactive"])->default("inactive"); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists("semesters"); | ||
} | ||
}; |
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,48 @@ | ||
<script setup> | ||
import DashboardLayout from '@/Layouts/DashboardLayout.vue' | ||
import Section from '@/Shared/Components/Section.vue' | ||
import SubmitButton from '@/Shared/Components/Buttons/SubmitButton.vue' | ||
import FormGroup from '@/Shared/Forms/FormGroup.vue' | ||
import FormLabel from '@/Shared/Forms/FormLabel.vue' | ||
import TextInput from '@/Shared/Forms/TextInput.vue' | ||
import SecondaryButton from '@/Shared/Components/Buttons/SecondaryButton.vue' | ||
import { useForm } from '@inertiajs/inertia-vue3' | ||
import FormError from '@/Shared/Forms/FormError.vue' | ||
const form = useForm({ | ||
name: '', | ||
}) | ||
function createSemester() { | ||
form.post('/dashboard/semesters') | ||
} | ||
</script> | ||
|
||
<template> | ||
<DashboardLayout> | ||
<h3 class="text-base font-semibold leading-6 text-gray-900"> | ||
Dodawanie semestru | ||
</h3> | ||
<form @submit.prevent="createSemester"> | ||
<Section class="mt-3"> | ||
<div class="flex justify-between"> | ||
<FormGroup> | ||
<FormLabel for="name"> | ||
Nazwa | ||
</FormLabel> | ||
<TextInput id="name" v-model="form.name" :error="form.errors.name" /> | ||
<FormError :error="form.errors.name" class="mt-2" /> | ||
</FormGroup> | ||
</div> | ||
<div class="flex justify-end space-x-3 py-3"> | ||
<SecondaryButton href="/dashboard/semesters"> | ||
Cofnij | ||
</SecondaryButton> | ||
<SubmitButton> | ||
Utwórz | ||
</SubmitButton> | ||
</div> | ||
</Section> | ||
</form> | ||
</DashboardLayout> | ||
</template> |
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,52 @@ | ||
<script setup> | ||
import DashboardLayout from '@/Layouts/DashboardLayout.vue' | ||
import Section from '@/Shared/Components/Section.vue' | ||
import SubmitButton from '@/Shared/Components/Buttons/SubmitButton.vue' | ||
import FormGroup from '@/Shared/Forms/FormGroup.vue' | ||
import FormLabel from '@/Shared/Forms/FormLabel.vue' | ||
import TextInput from '@/Shared/Forms/TextInput.vue' | ||
import SecondaryButton from '@/Shared/Components/Buttons/SecondaryButton.vue' | ||
import { useForm } from '@inertiajs/inertia-vue3' | ||
import FormError from '@/Shared/Forms/FormError.vue' | ||
const props = defineProps({ | ||
semester: Object, | ||
}) | ||
const form = useForm({ | ||
name: props.semester.name, | ||
}) | ||
function updateSemester() { | ||
form.patch(`/dashboard/semesters/${props.semester.id}`) | ||
} | ||
</script> | ||
|
||
<template> | ||
<DashboardLayout> | ||
<h3 class="text-base font-semibold leading-6 text-gray-900"> | ||
Edycja semestru | ||
</h3> | ||
<form @submit.prevent="updateSemester"> | ||
<Section class="mt-3"> | ||
<div class="flex justify-between"> | ||
<FormGroup> | ||
<FormLabel for="name"> | ||
Nazwa | ||
</FormLabel> | ||
<TextInput id="name" v-model="form.name" :error="form.errors.name" /> | ||
<FormError :error="form.errors.name" class="mt-2" /> | ||
</FormGroup> | ||
</div> | ||
<div class="flex justify-end space-x-3 py-3"> | ||
<SecondaryButton href="/dashboard/semesters"> | ||
Cofnij | ||
</SecondaryButton> | ||
<SubmitButton> | ||
Zapisz | ||
</SubmitButton> | ||
</div> | ||
</Section> | ||
</form> | ||
</DashboardLayout> | ||
</template> |
Oops, something went wrong.