Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jovitamaharani committed Jul 14, 2024
2 parents c32fd6d + 6ef9a29 commit f3fde4c
Show file tree
Hide file tree
Showing 28 changed files with 324 additions and 133 deletions.
16 changes: 16 additions & 0 deletions app/Contracts/Interfaces/Eloquent/WhereSchoolInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Contracts\Interfaces\Eloquent;

interface WhereSchoolInterface
{
/**
* Handle get data where user_id from models.
*
* @param mixed $id
*
* @return mixed
*/

public function whereSchool(mixed $id): mixed;
}
2 changes: 1 addition & 1 deletion app/Contracts/Interfaces/Eloquent/WhereUserIdInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ interface WhereUserIdInterface
* @return mixed
*/

public function whereUserId(mixed $id): mixed;
public function whereUserId(mixed $id): mixed;
}
4 changes: 3 additions & 1 deletion app/Contracts/Interfaces/EmployeeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use App\Contracts\Interfaces\Eloquent\DeleteInterface;
use App\Contracts\Interfaces\Eloquent\GetInterface;
use App\Contracts\Interfaces\Eloquent\ShowInterface;
use App\Contracts\Interfaces\Eloquent\ShowWithSlugInterface;
use App\Contracts\Interfaces\Eloquent\StoreInterface;
use App\Contracts\Interfaces\Eloquent\UpdateInterface;
use App\Contracts\Interfaces\Eloquent\WhereInterface;

interface EmployeeInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, WhereInterface
interface EmployeeInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, WhereInterface, ShowWithSlugInterface
{
public function paginate($query): mixed;
public function whereSchool(mixed $id, $query): mixed;
public function getTeacherBySchool(mixed $id): mixed;
}
3 changes: 2 additions & 1 deletion app/Contracts/Interfaces/LevelClassInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use App\Contracts\Interfaces\Eloquent\StoreInterface;
use App\Contracts\Interfaces\Eloquent\UpdateInterface;
use App\Contracts\Interfaces\Eloquent\WhereInterface;
use App\Contracts\Interfaces\Eloquent\WhereSchoolInterface;

interface LevelClassInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, WhereInterface
interface LevelClassInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, WhereInterface, WhereSchoolInterface
{
//
}
3 changes: 2 additions & 1 deletion app/Contracts/Interfaces/MapleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use App\Contracts\Interfaces\Eloquent\ShowInterface;
use App\Contracts\Interfaces\Eloquent\StoreInterface;
use App\Contracts\Interfaces\Eloquent\UpdateInterface;
use App\Contracts\Interfaces\Eloquent\WhereSchoolInterface;

interface MapleInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, PaginateInterface
interface MapleInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, PaginateInterface, WhereSchoolInterface
{
//
}
3 changes: 2 additions & 1 deletion app/Contracts/Interfaces/SchoolYearInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
use App\Contracts\Interfaces\Eloquent\StoreInterface;
use App\Contracts\Interfaces\Eloquent\UpdateInterface;
use App\Contracts\Interfaces\Eloquent\WhereInterface;
use App\Contracts\Interfaces\Eloquent\WhereSchoolInterface;

interface SchoolYearInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, PaginateInterface, WhereInterface
interface SchoolYearInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, PaginateInterface, WhereInterface, WhereSchoolInterface
{
//
}
3 changes: 2 additions & 1 deletion app/Contracts/Interfaces/StudentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use App\Contracts\Interfaces\Eloquent\ShowInterface;
use App\Contracts\Interfaces\Eloquent\StoreInterface;
use App\Contracts\Interfaces\Eloquent\UpdateInterface;
use App\Contracts\Interfaces\Eloquent\WhereSchoolInterface;

interface StudentInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, PaginateInterface
interface StudentInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, PaginateInterface, WhereSchoolInterface
{
//
}
3 changes: 2 additions & 1 deletion app/Contracts/Interfaces/TeacherMapleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use App\Contracts\Interfaces\Eloquent\ShowInterface;
use App\Contracts\Interfaces\Eloquent\StoreInterface;
use App\Contracts\Interfaces\Eloquent\UpdateInterface;
use App\Contracts\Interfaces\Eloquent\WhereInterface;

interface TeacherMapleInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, PaginateInterface
interface TeacherMapleInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, PaginateInterface, WhereInterface
{
//
}
10 changes: 10 additions & 0 deletions app/Contracts/Repositories/EmployeeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ public function getTeacherBySchool(mixed $id): mixed
{
return $this->model->query()->whereRelation('user.roles', 'name', RoleEnum::TEACHER->value)->where('school_id', $id)->get();
}

public function whereSchool(mixed $id, $query): mixed
{
return $this->model->query()->whereRelation('user.roles', 'name', $query)->where('school_id', $id)->latest()->paginate(10);
}

public function showWithSlug(string $slug): mixed
{
return $this->model->query()->whereRelation('user', 'slug', $slug)->firstOrFail();
}
}
5 changes: 5 additions & 0 deletions app/Contracts/Repositories/LevelClassRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public function where(mixed $data): mixed
{
return $this->model->query()->where('school_id', $data)->get();
}

public function whereSchool(mixed $id): mixed
{
return $this->model->query()->where('school_id', $id)->latest()->paginate(10);
}
}
9 changes: 7 additions & 2 deletions app/Contracts/Repositories/MapleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function show(mixed $id): mixed
{
return $this->model->query()->findOrFail($id);
}

public function update(mixed $id, array $data): mixed
{
return $this->model->query()->findOrFail($id)->update($data);
Expand All @@ -41,4 +41,9 @@ public function paginate() : mixed
{
return $this->model->query()->latest()->paginate(10);
}
}

public function whereSchool(mixed $id): mixed
{
return $this->model->query()->where('school_id', $id)->latest()->paginate(10);
}
}
11 changes: 8 additions & 3 deletions app/Contracts/Repositories/SchoolYearRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function show(mixed $id): mixed
{
return $this->model->query()->findOrFail($id);
}

public function update(mixed $id, array $data): mixed
{
return $this->model->query()->findOrFail($id)->update($data);
Expand All @@ -41,9 +41,14 @@ public function paginate() : mixed
{
return $this->model->query()->latest()->paginate(10);
}

public function where(mixed $data): mixed
{
return $this->model->query()->where('school_id', $data)->get();
}
}

public function whereSchool(mixed $id): mixed
{
return $this->model->query()->where('school_id', $id)->latest()->paginate(10);
}
}
9 changes: 7 additions & 2 deletions app/Contracts/Repositories/StudentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function show(mixed $id): mixed
{
return $this->model->query()->findOrFail($id);
}

public function update(mixed $id, array $data): mixed
{
return $this->model->query()->findOrFail($id)->update($data);
Expand All @@ -41,4 +41,9 @@ public function paginate() : mixed
{
return $this->model->query()->latest()->paginate(10);
}
}

public function whereSchool(mixed $id): mixed
{
return $this->model->query()->where('school_id', $id)->latest()->paginate(10);
}
}
9 changes: 7 additions & 2 deletions app/Contracts/Repositories/TeacherMapleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function show(mixed $id): mixed
{
return $this->model->query()->findOrFail($id);
}

public function update(mixed $id, array $data): mixed
{
return $this->model->query()->findOrFail($id)->update($data);
Expand All @@ -41,4 +41,9 @@ public function paginate() : mixed
{
return $this->model->query()->latest()->paginate(10);
}
}

public function where(mixed $data): mixed
{
return $this->model->query()->whereIn('employee_id', $data)->latest()->paginate(10);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/LevelClassController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(LevelClassInterface $levelClass, LevelClassService $
*/
public function index()
{
$levelClasses = $this->levelClass->get();
$levelClasses = $this->levelClass->whereSchool(auth()->user()->school->id);
return view('school.pages.class-level.index', compact('levelClasses'));
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/MapleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(MapleInterface $maple, MapleService $service, Religi
*/
public function index()
{
$maples = $this->maple->get();
$maples = $this->maple->whereSchool(auth()->user()->school->id);
$religions = $this->religion->get();
return view('school.pages.subjects.create-subjects', compact('maples', 'religions'));
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/SchoolYearController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(SchoolYearInterface $schoolYear, SchoolYearService $
*/
public function index()
{
$schoolYears = $this->schoolYear->get();
$schoolYears = $this->schoolYear->whereSchool(auth()->user()->school->id);
return view('school.pages.school-year.index', compact('schoolYears'));
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/StudentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(StudentInterface $student, StudentService $service,
*/
public function index()
{
$students = $this->student->get();
$students = $this->student->whereSchool(auth()->user()->school->id);
$religions = $this->religion->get();

return view('school.pages.student.index', compact('students', 'religions'));
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Teacher/StaffController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(EmployeeInterface $employee, StaffService $service,
*/
public function index()
{
$staffs = $this->employee->paginate(RoleEnum::STAFF->value);
$staffs = $this->employee->whereSchool(auth()->user()->school->id, RoleEnum::STAFF->value);
$religions = $this->religion->get();
return view('school.pages.employe.index', compact('staffs', 'religions'));
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Teacher/TeacherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Controllers\Controller;
use App\Contracts\Interfaces\EmployeeInterface;
use App\Contracts\Interfaces\MapleInterface;
use App\Contracts\Interfaces\ReligionInterface;
use App\Enums\RoleEnum;
use App\Http\Requests\StoreEmployeeRequest;
Expand All @@ -29,7 +30,7 @@ public function __construct(EmployeeInterface $employee, TeacherService $service
*/
public function index()
{
$teachers = $this->employee->paginate(RoleEnum::TEACHER->value);
$teachers = $this->employee->whereSchool(auth()->user()->school->id, RoleEnum::TEACHER->value);
$religions = $this->religion->get();
return view('school.pages.teacher.index', compact('teachers', 'religions'));
}
Expand Down
31 changes: 24 additions & 7 deletions app/Http/Controllers/TeacherMapleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,44 @@

namespace App\Http\Controllers;

use App\Contracts\Interfaces\EmployeeInterface;
use App\Contracts\Interfaces\MapleInterface;
use App\Contracts\Interfaces\SchoolYearInterface;
use App\Contracts\Interfaces\TeacherMapleInterface;
use App\Models\TeacherMaple;
use App\Http\Requests\StoreTeacherMapleRequest;
use App\Http\Requests\UpdateTeacherMapleRequest;
use App\Models\Employee;
use App\Services\TeacherMapleService;

class TeacherMapleController extends Controller
{
private TeacherMapleInterface $teacherMaple;
private EmployeeInterface $employee;
private MapleInterface $maple;
private SchoolYearInterface $schoolYear;

public function __construct(TeacherMapleInterface $teacherMaple)
private TeacherMapleService $service;

public function __construct(TeacherMapleInterface $teacherMaple, EmployeeInterface $employee, MapleInterface $maple, SchoolYearInterface $schoolYear, TeacherMapleService $service)
{
$this->teacherMaple = $teacherMaple;
$this->employee = $employee;
$this->maple = $maple;
$this->schoolYear = $schoolYear;
$this->service = $service;
}

/**
* Display a listing of the resource.
*/
public function index()
public function index(string $employee)
{
$teacherMaples = $this->teacherMaple->get();
return view('', compact('teacherMaples'));
$employee_id = $this->employee->showWithSlug($employee);
$teacherMaples = $this->teacherMaple->where($employee_id);
$maples = $this->maple->whereSchool(auth()->user()->school->id);
$schoolYears = $this->schoolYear->whereSchool(auth()->user()->school->id);
return view('school.pages.teacher.detail-teacher', compact('teacherMaples', 'employee_id', 'maples', 'schoolYears'));
}

/**
Expand All @@ -36,9 +53,9 @@ public function create()
/**
* Store a newly created resource in storage.
*/
public function store(StoreTeacherMapleRequest $request)
public function store(StoreTeacherMapleRequest $request, string $employee)
{
$data = $request->validated();
$data = $this->service->store($request, $employee);
$this->teacherMaple->store($data);
return redirect()->back()->with('success', 'Berhasil menambahahkan guru mapel');
}
Expand All @@ -64,7 +81,7 @@ public function edit(TeacherMaple $teacherMaple)
*/
public function update(UpdateTeacherMapleRequest $request, TeacherMaple $teacherMaple)
{
$data = $request->validated();
$data = $this->service->update($request);
$this->teacherMaple->update($teacherMaple->id, $data);
return redirect()->back()->with('success', 'Berhasil memperbaiki guru mapel');
}
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Requests/StoreTeacherMapleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function rules(): array
{
return [
'maple_id' => 'required',
'employee_id' => 'required',
'school_year_id' => 'required'
];
}
Expand All @@ -37,7 +36,6 @@ public function messages(): array
{
return [
'maple_id.required' => 'ID mapel wajib diisi.',
'employee_id.required' => 'ID karyawan wajib diisi.',
'school_year_id.required' => 'ID tahun ajaran wajib diisi.',
];
}
Expand Down
2 changes: 0 additions & 2 deletions app/Http/Requests/UpdateTeacherMapleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function rules(): array
{
return [
'maple_id' => 'required',
'employee_id' => 'required',
'school_year_id' => 'required'
];
}
Expand All @@ -37,7 +36,6 @@ public function messages(): array
{
return [
'maple_id.required' => 'ID mapel wajib diisi.',
'employee_id.required' => 'ID karyawan wajib diisi.',
'school_year_id.required' => 'ID tahun ajaran wajib diisi.',
];
}
Expand Down
Loading

0 comments on commit f3fde4c

Please sign in to comment.