Add store course
This commit is contained in:
parent
61d98f6950
commit
489072411e
22
src/Api.php
22
src/Api.php
|
@ -4,6 +4,7 @@ namespace Zoomyboy\LaravelNami;
|
||||||
|
|
||||||
use App\Conf;
|
use App\Conf;
|
||||||
use App\Nami\Exceptions\TooManyLoginAttemptsException;
|
use App\Nami\Exceptions\TooManyLoginAttemptsException;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
|
@ -222,6 +223,27 @@ class Api {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $memberId
|
||||||
|
* @param array<string, mixed> $payload
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function createCourse(int $memberId, array $payload): int
|
||||||
|
{
|
||||||
|
$response = $this->http()->post(self::$url."/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}", [
|
||||||
|
'bausteinId' => $payload['course_id'],
|
||||||
|
'vstgName' => $payload['event_name'],
|
||||||
|
'vstgTag' => Carbon::parse($payload['completed_at'])->format('Y-m-d').'T00:00:00',
|
||||||
|
'veranstalter' => $payload['organizer'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (data_get($response->json(), 'success') !== true) {
|
||||||
|
$this->exception('Course creation failed', $payload, $response->json());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response['data'];
|
||||||
|
}
|
||||||
|
|
||||||
public function member($groupId, $memberId) {
|
public function member($groupId, $memberId) {
|
||||||
$url = self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId;
|
$url = self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId;
|
||||||
$response = $this->http()->get($url);
|
$response = $this->http()->get($url);
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami\Fakes;
|
||||||
|
|
||||||
|
use Illuminate\Http\Client\Response;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
class CourseFake extends Fake {
|
||||||
|
|
||||||
|
public function createsSuccessful(int $memberId, int $courseId): void
|
||||||
|
{
|
||||||
|
Http::fake(function($request) use ($memberId, $courseId) {
|
||||||
|
if ($request->url() === "https://nami.dpsg.de/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}") {
|
||||||
|
return Http::response([
|
||||||
|
'data' => $courseId,
|
||||||
|
'responseType' => 'OK',
|
||||||
|
'success' => true,
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $memberId
|
||||||
|
* @param array<string, mixed> $payload
|
||||||
|
*/
|
||||||
|
public function assertCreated(int $memberId, array $payload): void
|
||||||
|
{
|
||||||
|
Http::assertSent(function($request) use ($memberId, $payload) {
|
||||||
|
return $request->url() === "https://nami.dpsg.de/ica/rest/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/{$memberId}"
|
||||||
|
&& $request->method() === 'POST'
|
||||||
|
&& data_get($request, 'bausteinId') === $payload['bausteinId']
|
||||||
|
&& data_get($request, 'veranstalter') === $payload['veranstalter']
|
||||||
|
// && data_get($request, 'vstgName') === $payload['vstgName']
|
||||||
|
&& data_get($request, 'vstgTag') === $payload['vstgTag'];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue