first change
This commit is contained in:
0
Modules/CourseFinder/app/Services/.gitkeep
Normal file
0
Modules/CourseFinder/app/Services/.gitkeep
Normal file
49
Modules/CourseFinder/app/Services/CoopService.php
Normal file
49
Modules/CourseFinder/app/Services/CoopService.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\CourseFinder\Services;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\CourseFinder\Models\Coop;
|
||||
|
||||
class CoopService
|
||||
{
|
||||
|
||||
public function getAllCategories()
|
||||
{
|
||||
$query = Coop::query();
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function storeCoop(array $coopData): Coop
|
||||
{
|
||||
return DB::transaction(function () use ($coopData) {
|
||||
$coop = Coop::create($coopData);
|
||||
|
||||
return $coop;
|
||||
});
|
||||
}
|
||||
|
||||
public function getCoopById(int $id)
|
||||
{
|
||||
return Coop::findOrFail($id);
|
||||
}
|
||||
|
||||
public function updateCoop(int $id, array $coopData)
|
||||
{
|
||||
$coop = $this->getCoopById($id);
|
||||
|
||||
return DB::transaction(function () use ($coop, $coopData) {
|
||||
$coop->update($coopData);
|
||||
return $coop;
|
||||
});
|
||||
}
|
||||
|
||||
public function deleteCoop(int $id)
|
||||
{
|
||||
return DB::transaction(function () use ($id) {
|
||||
$coop = $this->getCoopById($id);
|
||||
$coop->delete();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
49
Modules/CourseFinder/app/Services/ProgramLevelService.php
Normal file
49
Modules/CourseFinder/app/Services/ProgramLevelService.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\CourseFinder\Services;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\CourseFinder\Models\ProgramLevel;
|
||||
|
||||
class ProgramLevelService
|
||||
{
|
||||
|
||||
public function getAllCategories()
|
||||
{
|
||||
$query = ProgramLevel::query();
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function storeProgramLevel(array $programLevelData): ProgramLevel
|
||||
{
|
||||
return DB::transaction(function () use ($programLevelData) {
|
||||
$programLevel = ProgramLevel::create($programLevelData);
|
||||
|
||||
return $programLevel;
|
||||
});
|
||||
}
|
||||
|
||||
public function getProgramLevelById(int $id)
|
||||
{
|
||||
return ProgramLevel::findOrFail($id);
|
||||
}
|
||||
|
||||
public function updateProgramLevel(int $id, array $programLevelData)
|
||||
{
|
||||
$programLevel = $this->getProgramLevelById($id);
|
||||
|
||||
return DB::transaction(function () use ($programLevel, $programLevelData) {
|
||||
$programLevel->update($programLevelData);
|
||||
return $programLevel;
|
||||
});
|
||||
}
|
||||
|
||||
public function deleteProgramLevel(int $id)
|
||||
{
|
||||
return DB::transaction(function () use ($id) {
|
||||
$programLevel = $this->getProgramLevelById($id);
|
||||
$programLevel->delete();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
54
Modules/CourseFinder/app/Services/ProgramService.php
Normal file
54
Modules/CourseFinder/app/Services/ProgramService.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\CourseFinder\Services;
|
||||
|
||||
use Modules\CourseFinder\Models\Program;
|
||||
|
||||
class ProgramService
|
||||
{
|
||||
public function findAll($request)
|
||||
{
|
||||
return Program::when($request, function ($query) use ($request) {
|
||||
if ($request->filled('country_id')) {
|
||||
$query->whereRelation('institution', 'country_id', $request->country_id);
|
||||
}
|
||||
|
||||
if ($request->filled('institution_id')) {
|
||||
$query->where("institution_id", $request->institution_id);
|
||||
}
|
||||
|
||||
if ($request->filled('programlevel_id')) {
|
||||
$query->where("programlevel_id", $request->programlevel_id);
|
||||
}
|
||||
|
||||
if ($request->filled('intake_id')) {
|
||||
$intakeId = $request->intake_id;
|
||||
$query->whereJsonContains('intake', $intakeId);
|
||||
}
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->status);
|
||||
}
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$search = $request->search;
|
||||
$query->where('keywords', 'like', "%{$search}%");
|
||||
}
|
||||
|
||||
if ($request->filled('location')) {
|
||||
$location = $request->location;
|
||||
$query->where('location', 'like', "%{$location}%");
|
||||
}
|
||||
|
||||
})->latest()->paginate(10)->withQueryString();
|
||||
}
|
||||
|
||||
public function pluck(callable $query = null)
|
||||
{
|
||||
$baseQuery = Program::query();
|
||||
if (is_callable($query)) {
|
||||
$query($baseQuery);
|
||||
}
|
||||
return $baseQuery->pluck('title', 'id');
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\CourseFinder\Services;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\CourseFinder\Models\RequiredDocument;
|
||||
|
||||
class RequiredDocumentService
|
||||
{
|
||||
|
||||
public function getAllCategories()
|
||||
{
|
||||
$query = RequiredDocument::query();
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function storeRequiredDocument(array $requiredDocumentData): RequiredDocument
|
||||
{
|
||||
return DB::transaction(function () use ($requiredDocumentData) {
|
||||
$requiredDocument = RequiredDocument::create($requiredDocumentData);
|
||||
|
||||
return $requiredDocument;
|
||||
});
|
||||
}
|
||||
|
||||
public function getRequiredDocumentById(int $id)
|
||||
{
|
||||
return RequiredDocument::findOrFail($id);
|
||||
}
|
||||
|
||||
public function updateRequiredDocument(int $id, array $requiredDocumentData)
|
||||
{
|
||||
$requiredDocument = $this->getRequiredDocumentById($id);
|
||||
|
||||
return DB::transaction(function () use ($requiredDocument, $requiredDocumentData) {
|
||||
$requiredDocument->update($requiredDocumentData);
|
||||
return $requiredDocument;
|
||||
});
|
||||
}
|
||||
|
||||
public function deleteRequiredDocument(int $id)
|
||||
{
|
||||
return DB::transaction(function () use ($id) {
|
||||
$requiredDocument = $this->getRequiredDocumentById($id);
|
||||
$requiredDocument->delete();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user