Add Course DTO
This commit is contained in:
parent
220187bef4
commit
e400315cf6
|
@ -9,9 +9,11 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
|
"php": "8.1.*",
|
||||||
"guzzlehttp/guzzle": "^6.3.1|^7.0",
|
"guzzlehttp/guzzle": "^6.3.1|^7.0",
|
||||||
"laravel/framework": "^8.0",
|
"laravel/framework": "^8.0",
|
||||||
"laravel/ui": "^3.4"
|
"laravel/ui": "^3.4",
|
||||||
|
"spatie/data-transfer-object": "^3.7"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "c08ae38275555b5d4c8569acc8f033a1",
|
"content-hash": "91a283d3422069c7fa3a1b13a0850bbf",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "brick/math",
|
"name": "brick/math",
|
||||||
|
@ -2509,6 +2509,69 @@
|
||||||
],
|
],
|
||||||
"time": "2021-09-25T23:10:38+00:00"
|
"time": "2021-09-25T23:10:38+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "spatie/data-transfer-object",
|
||||||
|
"version": "3.7.3",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/spatie/data-transfer-object.git",
|
||||||
|
"reference": "341f72c77e0fce40ea2e0dcb212cb54dc27bbe72"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/spatie/data-transfer-object/zipball/341f72c77e0fce40ea2e0dcb212cb54dc27bbe72",
|
||||||
|
"reference": "341f72c77e0fce40ea2e0dcb212cb54dc27bbe72",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"illuminate/collections": "^8.36",
|
||||||
|
"jetbrains/phpstorm-attributes": "^1.0",
|
||||||
|
"larapack/dd": "^1.1",
|
||||||
|
"phpunit/phpunit": "^9.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Spatie\\DataTransferObject\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Brent Roose",
|
||||||
|
"email": "brent@spatie.be",
|
||||||
|
"homepage": "https://spatie.be",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Data transfer objects with batteries included",
|
||||||
|
"homepage": "https://github.com/spatie/data-transfer-object",
|
||||||
|
"keywords": [
|
||||||
|
"data-transfer-object",
|
||||||
|
"spatie"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/spatie/data-transfer-object/issues",
|
||||||
|
"source": "https://github.com/spatie/data-transfer-object/tree/3.7.3"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://spatie.be/open-source/support-us",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/spatie",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2021-12-30T20:31:10+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "swiftmailer/swiftmailer",
|
"name": "swiftmailer/swiftmailer",
|
||||||
"version": "v6.3.0",
|
"version": "v6.3.0",
|
||||||
|
@ -9046,7 +9109,9 @@
|
||||||
"stability-flags": [],
|
"stability-flags": [],
|
||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": [],
|
"platform": {
|
||||||
|
"php": "8.1.*"
|
||||||
|
},
|
||||||
"platform-dev": [],
|
"platform-dev": [],
|
||||||
"plugin-api-version": "2.1.0"
|
"plugin-api-version": "2.2.0"
|
||||||
}
|
}
|
||||||
|
|
28
src/Api.php
28
src/Api.php
|
@ -14,6 +14,7 @@ use Illuminate\Support\Str;
|
||||||
use Log;
|
use Log;
|
||||||
use Zoomyboy\LaravelNami\Authentication\Authenticator;
|
use Zoomyboy\LaravelNami\Authentication\Authenticator;
|
||||||
use Zoomyboy\LaravelNami\Concerns\IsNamiMember;
|
use Zoomyboy\LaravelNami\Concerns\IsNamiMember;
|
||||||
|
use Zoomyboy\LaravelNami\Data\Course;
|
||||||
use Zoomyboy\LaravelNami\Exceptions\NotAuthenticatedException;
|
use Zoomyboy\LaravelNami\Exceptions\NotAuthenticatedException;
|
||||||
use Zoomyboy\LaravelNami\Exceptions\RightException;
|
use Zoomyboy\LaravelNami\Exceptions\RightException;
|
||||||
use Zoomyboy\LaravelNami\NamiException;
|
use Zoomyboy\LaravelNami\NamiException;
|
||||||
|
@ -198,27 +199,26 @@ class Api {
|
||||||
$this->assertLoggedIn();
|
$this->assertLoggedIn();
|
||||||
|
|
||||||
return $this->fetchCollection('/ica/rest/module/baustein', 'Fetch courses failed')
|
return $this->fetchCollection('/ica/rest/module/baustein', 'Fetch courses failed')
|
||||||
->map(fn ($course) => (object) ['name' => $course['descriptor'], 'id' => $course['id']]);
|
->map(fn ($course) => (object) ['id' => $course['id']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<Course>
|
||||||
|
*/
|
||||||
public function coursesFor(int $memberId): Collection
|
public function coursesFor(int $memberId): Collection
|
||||||
{
|
{
|
||||||
$this->assertLoggedIn();
|
$this->assertLoggedIn();
|
||||||
|
|
||||||
return $this->fetchCollection(
|
return $this->fetchCollection("/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/flist", 'Courses fetch failed')
|
||||||
"/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/flist",
|
->map(fn ($course) => $this->course($memberId, $course['id']))
|
||||||
'Courses fetch failed'
|
->filter(fn ($course) => $course !== null);
|
||||||
)->map(function ($course) use ($memberId) {
|
}
|
||||||
$single = $this->fetchData("/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$course['id']}", "Error fetching single course");
|
|
||||||
|
|
||||||
return $single ? (object) [
|
public function course(int $memberId, int $courseId): ?Course
|
||||||
'id' => $single['id'],
|
{
|
||||||
'organizer' => $single['veranstalter'],
|
$single = $this->fetchData("/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}/{$courseId}", "Error fetching single course");
|
||||||
'course_id' => $single['bausteinId'],
|
|
||||||
'event_name' => $single['vstgName'],
|
return $single ? new Course($single) : null;
|
||||||
'completed_at' => $single['vstgTag'],
|
|
||||||
] : null;
|
|
||||||
})->filter(fn ($course) => $course !== null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami\Data;
|
||||||
|
|
||||||
|
use Spatie\DataTransferObject\Attributes\MapFrom;
|
||||||
|
use Spatie\DataTransferObject\DataTransferObject;
|
||||||
|
|
||||||
|
class Course extends DataTransferObject {
|
||||||
|
|
||||||
|
public int $id;
|
||||||
|
|
||||||
|
#[MapFrom('bausteinId')]
|
||||||
|
public string $courseId;
|
||||||
|
|
||||||
|
#[MapFrom('veranstalter')]
|
||||||
|
public string $organizer;
|
||||||
|
|
||||||
|
#[MapFrom('vstgName')]
|
||||||
|
public string $eventName;
|
||||||
|
|
||||||
|
#[MapFrom('vstgTag')]
|
||||||
|
public string $completedAt;
|
||||||
|
|
||||||
|
}
|
|
@ -38,9 +38,9 @@ class CourseTest extends TestCase
|
||||||
|
|
||||||
$this->assertEquals(788, $course->id);
|
$this->assertEquals(788, $course->id);
|
||||||
$this->assertEquals('KJA', $course->organizer);
|
$this->assertEquals('KJA', $course->organizer);
|
||||||
$this->assertEquals(506, $course->course_id);
|
$this->assertEquals(506, $course->courseId);
|
||||||
$this->assertEquals('eventname', $course->event_name);
|
$this->assertEquals('eventname', $course->eventName);
|
||||||
$this->assertEquals('2021-11-12 00:00:00', $course->completed_at);
|
$this->assertEquals('2021-11-12 00:00:00', $course->completedAt);
|
||||||
|
|
||||||
app(CourseFake::class)->assertFetched(11111);
|
app(CourseFake::class)->assertFetched(11111);
|
||||||
app(CourseFake::class)->assertFetchedSingle(11111, 788);
|
app(CourseFake::class)->assertFetchedSingle(11111, 788);
|
||||||
|
|
Loading…
Reference in New Issue