Skip to content

Commit

Permalink
Merge pull request #1 from E-ZSTU/room-schedule
Browse files Browse the repository at this point in the history
Room schedule
  • Loading branch information
TBlindaruk authored Nov 6, 2018
2 parents 52253db + 51b96d8 commit 4ab0cdc
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types = 1);

namespace ZSTU\RozkladClient\V1\Teacher\ResponseData;
namespace ZSTU\RozkladClient\V1\ResponseData\Activity;

use Illuminate\Support\Collection;

Expand All @@ -10,7 +10,7 @@
*
* @method ActivityData[] all()
*
* @package ZSTU\RozkladClient\V1\Teacher\ResponseData
* @package ZSTU\RozkladClient\V1\ResponseData\Activity
*/
class ActivityCollection extends Collection
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types = 1);

namespace ZSTU\RozkladClient\V1\Teacher\ResponseData;
namespace ZSTU\RozkladClient\V1\ResponseData\Activity;

/**
* Class ActivityData
*
* @package ZSTU\RozkladClient\V1\Teacher\ResponseData
* @package ZSTU\RozkladClient\V1\ResponseData\Activity
*/
class ActivityData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
declare(strict_types = 1);

namespace ZSTU\RozkladClient\V1\Room\ResponseData;
namespace ZSTU\RozkladClient\V1\ResponseData\Room;

use Illuminate\Support\Collection;

/**
* Class TeacherCollection
* Class RoomCollection
*
* @method RoomData[] all()
*
* @package ZSTU\RozkladClient\V1\Teacher\ResponseData
* @package ZSTU\RozkladClient\V1\ResponseData\Room
*/
class RoomCollection extends Collection
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types = 1);

namespace ZSTU\RozkladClient\V1\Room\ResponseData;
namespace ZSTU\RozkladClient\V1\ResponseData\Room;

/**
* Class RoomData
*
* @package ZSTU\RozkladClient\V1\Room\ResponseData
* @package ZSTU\RozkladClient\V1\ResponseData\Room
*/
class RoomData
{
Expand Down
66 changes: 66 additions & 0 deletions src/V1/ResponseData/Room/RoomScheduleResponseData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
declare(strict_types = 1);

namespace ZSTU\RozkladClient\V1\ResponseData\Room;

use ZSTU\RozkladClient\V1\ResponseData\Activity\ActivityCollection;
use ZSTU\RozkladClient\V1\ResponseData\Activity\ActivityData;

/**
* Class RoomScheduleResponseData
*
* @package ZSTU\RozkladClient\V1\ResponseData\Room
*/
class RoomScheduleResponseData
{
/**
* @var int
*/
private $roomId;

/**
* @var string
*/
private $roomName;

/**
* @var \Illuminate\Support\Collection|ActivityData[]
*/
private $activities;

/**
* ScheduleResponseData constructor.
*
* @param array $data
*/
public function __construct(array $data)
{
$this->roomId = (int) $data['room_id'];
$this->roomName = (string) $data['room_name'];
$this->activities = ActivityCollection::make($data['activities']);
}

/**
* @return int
*/
public function getRoomId(): int
{
return $this->roomId;
}

/**
* @return string
*/
public function getRoomName(): string
{
return $this->roomName;
}

/**
* @return ActivityCollection
*/
public function getActivities(): ActivityCollection
{
return $this->activities;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
declare(strict_types = 1);

namespace ZSTU\RozkladClient\V1\Room\ResponseData;
namespace ZSTU\RozkladClient\V1\ResponseData\Room;

/**
* Class SearchResponseData
* Class RoomSearchResponseData
*
* @package ZSTU\RozkladClient\V1\Room\ResponseData
* @package ZSTU\RozkladClient\V1\ResponseData\Room
*/
class SearchResponseData
class RoomSearchResponseData
{
/**
* @var null|RoomData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types = 1);

namespace ZSTU\RozkladClient\V1\Teacher\ResponseData;
namespace ZSTU\RozkladClient\V1\ResponseData\Teacher;

use Illuminate\Support\Collection;

Expand All @@ -10,7 +10,7 @@
*
* @method TeacherData[] all()
*
* @package ZSTU\RozkladClient\V1\Teacher\ResponseData
* @package ZSTU\RozkladClient\V1\ResponseData\Teacher
*/
class TeacherCollection extends Collection
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types = 1);

namespace ZSTU\RozkladClient\V1\Teacher\ResponseData;
namespace ZSTU\RozkladClient\V1\ResponseData\Teacher;

/**
* Class TeacherData
*
* @package ZSTU\RozkladClient\V1\Teacher\ResponseData
* @package ZSTU\RozkladClient\V1\ResponseData\Teacher
*/
class TeacherData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php
declare(strict_types = 1);

namespace ZSTU\RozkladClient\V1\Teacher\ResponseData;
namespace ZSTU\RozkladClient\V1\ResponseData\Teacher;

use ZSTU\RozkladClient\V1\ResponseData\Activity\ActivityCollection;
use ZSTU\RozkladClient\V1\ResponseData\Activity\ActivityData;

/**
* Class ScheduleResponseData
* Class TeacherScheduleResponseData
*
* @package ZSTU\RozkladClient\V1\Teacher\ResponseData
* @package ZSTU\RozkladClient\V1\ResponseData\Teacher
*/
class ScheduleResponseData
class TeacherScheduleResponseData
{
/**
* @var int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
declare(strict_types = 1);

namespace ZSTU\RozkladClient\V1\Teacher\ResponseData;
namespace ZSTU\RozkladClient\V1\ResponseData\Teacher;

/**
* Class SearchResponseData
* Class TeacherSearchResponseData
*
* @package ZSTU\RozkladClient\V1\Teacher\ResponseData
* @package ZSTU\RozkladClient\V1\ResponseData\Teacher
*/
class SearchResponseData
class TeacherSearchResponseData
{
/**
* @var TeacherData|null
Expand Down
23 changes: 19 additions & 4 deletions src/V1/Room/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\RequestOptions;
use ZSTU\RozkladClient\V1\Room\ResponseData\SearchResponseData;
use ZSTU\RozkladClient\V1\ResponseData\Room\RoomScheduleResponseData;
use ZSTU\RozkladClient\V1\ResponseData\Room\RoomSearchResponseData;

/**
* Class Client
Expand All @@ -32,15 +33,29 @@ public function __construct(HttpClient $httpClient)
/**
* @param string $name
*
* @return SearchResponseData
* @return RoomSearchResponseData
*/
public function search(string $name): SearchResponseData
public function search(string $name): RoomSearchResponseData
{
$response = $this->httpClient->request('GET', '/room-search', [
RequestOptions::QUERY => ['name' => $name],
]);
$jsonResponse = json_decode($response->getBody()->getContents(), true);

return new SearchResponseData($jsonResponse);
return new RoomSearchResponseData($jsonResponse);
}

/**
* @param int $id
*
* @return RoomScheduleResponseData
*/
public function schedule(int $id): RoomScheduleResponseData
{
$response = $this->httpClient->request('GET', "/room-schedule/$id");

$jsonResponse = json_decode($response->getBody()->getContents(), true);

return new RoomScheduleResponseData($jsonResponse);
}
}
16 changes: 8 additions & 8 deletions src/V1/Teacher/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\RequestOptions;
use ZSTU\RozkladClient\V1\Teacher\ResponseData\ScheduleResponseData;
use ZSTU\RozkladClient\V1\Teacher\ResponseData\SearchResponseData;
use ZSTU\RozkladClient\V1\ResponseData\Teacher\TeacherScheduleResponseData;
use ZSTU\RozkladClient\V1\ResponseData\Teacher\TeacherSearchResponseData;

/**
* Class Client
Expand All @@ -33,29 +33,29 @@ public function __construct(HttpClient $httpClient)
/**
* @param string $name
*
* @return SearchResponseData
* @return TeacherSearchResponseData
*/
public function search(string $name): SearchResponseData
public function search(string $name): TeacherSearchResponseData
{
$response = $this->httpClient->request('GET', '/teacher-search', [
RequestOptions::QUERY => ['name' => $name],
]);
$jsonResponse = json_decode($response->getBody()->getContents(), true);

return new SearchResponseData($jsonResponse);
return new TeacherSearchResponseData($jsonResponse);
}

/**
* @param int $id
*
* @return ScheduleResponseData
* @return TeacherScheduleResponseData
*/
public function schedule(int $id): ScheduleResponseData
public function schedule(int $id): TeacherScheduleResponseData
{
$response = $this->httpClient->request('GET', "/teacher-schedule/$id");

$jsonResponse = json_decode($response->getBody()->getContents(), true);

return new ScheduleResponseData($jsonResponse);
return new TeacherScheduleResponseData($jsonResponse);
}
}

0 comments on commit 4ab0cdc

Please sign in to comment.