Skip to content

Commit

Permalink
Improved the endpoints for fetching Staff by username, user Number an…
Browse files Browse the repository at this point in the history
…d all staff
  • Loading branch information
coolsam726 committed Oct 21, 2023
1 parent d8d8de0 commit 42846f5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
4 changes: 3 additions & 1 deletion database/migrations/add_webservice_settings.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ return new class extends \Spatie\LaravelSettings\Migrations\SettingsMigration
public function up()
{
$this->migrator->add('webservice.base_url','https://juba.strathmore.edu/dataservice');
$this->migrator->add('webservice.staff_endpoint','staff/getStaffByUsername/{username}');
$this->migrator->add('webservice.staff_endpoint','staff/getStaff/{staff_number}');
$this->migrator->add('webservice.staff_by_username_endpoint','staff/getStaffByUsername/{username}');
$this->migrator->add('webservice.student_endpoint','student/getStudent/{studentNumber}');
$this->migrator->add('webservice.all_staff_endpoint','staff/getAllStaff');
$this->migrator->add('webservice.all_current_students_endpoint','student/getAllCurrentStudents');
Expand All @@ -31,6 +32,7 @@ return new class extends \Spatie\LaravelSettings\Migrations\SettingsMigration
{
$this->migrator->deleteIfExists('webservice.base_url');
$this->migrator->deleteIfExists('webservice.staff_endpoint');
$this->migrator->deleteIfExists('webservice.staff_by_username_endpoint');
$this->migrator->deleteIfExists('webservice.student_endpoint');
$this->migrator->deleteIfExists('webservice.all_staff_endpoint');
$this->migrator->deleteIfExists('webservice.all_current_students_endpoint');
Expand Down
23 changes: 22 additions & 1 deletion src/Services/Webservice.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,33 @@ public function fetchStudent(string | int $studentNo): Collection
return Http::withoutVerifying()->asJson()->acceptJson()->get(Ws::settings()->getStudentUrl($studentNo))->throw()->collect();
}

public function fetchStaffByNumber(string $staff_number): Collection
{
return Http::withoutVerifying()->asJson()->acceptJson()->get(Ws::settings()->getStaffByNumberUrl($staff_number))->throw()->collect();
}

/**
* @deprecated Use fetchStaffByUsername instead.
* @param string $username
* @return Collection
* @throws RequestException
*/
public function fetchStaff(string $username): Collection
{
return Http::withoutVerifying()->asJson()->acceptJson()->get(Ws::settings()->getStaffUrl($username))->throw()->collect();
return $this->fetchStaffByUsername($username);
}

public function fetchAllStaff(): Collection
{
return Http::withoutVerifying()->asJson()->acceptJson()->get(Ws::settings()->getAllStaffUrl())->throw()->collect();
}

/**
* @throws RequestException
*/
public function fetchStaffByUsername(string $username): Collection
{
return Http::withoutVerifying()->asJson()->acceptJson()->get(Ws::settings()->getStaffByUsernameUrl($username))->throw()->collect();
}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/Settings/WebserviceSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class WebserviceSettings extends Settings

public ?string $staff_endpoint;

public ?string $staff_by_username_endpoint;

public ?string $student_endpoint;

public ?string $all_staff_endpoint;
Expand All @@ -37,11 +39,16 @@ public function makeUrl(string $endpoint, array $params = []): string
return \Str::of($this->base_url)->rtrim('/')->append('/')->append($path)->toString();
}

public function getStaffUrl($username): string
public function getStaffByUsernameUrl($username): string
{
return $this->makeUrl($this->staff_by_username_endpoint, ['username' => trim($username)]);
}
public function getStaffByNumberUrl(string $staff_number): string
{
return $this->makeUrl($this->staff_endpoint, ['username' => trim($username)]);
return $this->makeUrl($this->staff_endpoint, ['staff_number' => trim($staff_number)]);
}


public function getStudentUrl($studentNumber): string
{
return $this->makeUrl($this->student_endpoint, ['studentNo' => trim($studentNumber)]);
Expand Down
1 change: 1 addition & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function saas(): Saas
}
}


if (!function_exists('Savannabits\Saas\default_team')) {
function default_team(): Team
{
Expand Down

0 comments on commit 42846f5

Please sign in to comment.