Skip to content

Commit 9969bd8

Browse files
committed
reference module
image module
1 parent 5f8a671 commit 9969bd8

File tree

6 files changed

+354
-1
lines changed

6 files changed

+354
-1
lines changed

src/SistemApi/ApiClient.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
use SistemApi\Service\GaleriService;
77
use SistemApi\Service\GrupService;
88
use SistemApi\Service\HaberService;
9-
use SistemApi\Service\HeadlineService;
109
use SistemApi\Service\IlceService;
1110
use SistemApi\Service\IletisimMesajService;
11+
use SistemApi\Service\ImageService;
1212
use SistemApi\Service\KullaniciService;
1313
use SistemApi\Service\MansetService;
1414
use SistemApi\Service\MenuService;
15+
use SistemApi\Service\ReferenceService;
1516
use SistemApi\Service\ReklamService;
1617
use SistemApi\Service\ResimService;
1718
use SistemApi\Service\SanatService;
@@ -45,6 +46,9 @@
4546
* @property SiparisService siparis
4647
* @property SanatService sanat
4748
* @property GrupService grup
49+
*
50+
* @property ReferenceService reference
51+
* @property ImageService image
4852
*/
4953
class ApiClient
5054
{
@@ -83,6 +87,9 @@ public function __construct($token, $uri = 'http://www.ifsistem.com/api/v1')
8387
'sanat' => \DI\get(SanatService::class),
8488
'grup' => \DI\get(GrupService::class),
8589

90+
'reference' => \DI\get(ReferenceService::class),
91+
'image' => \DI\get(ImageService::class),
92+
8693
'api' => function() use($token, $uri) {
8794
return new ApiService($token, $uri);
8895
},
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php namespace SistemApi\Model\Ayar;
2+
3+
use SistemApi\Model\Ayar\Base\ListeAyar;
4+
5+
class ReferenceListConfig extends ListeAyar
6+
{
7+
8+
}

src/SistemApi/Model/Reference.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php namespace SistemApi\Model;
2+
3+
use Illuminate\Support\Collection;
4+
use SistemApi\Model\Base\Model;
5+
6+
/**
7+
* @property int id
8+
* @property string title
9+
* @property int site_id
10+
*
11+
* @property int is_new
12+
* @property int is_active
13+
* @property int is_deleted
14+
*
15+
* // model
16+
*
17+
* @property Collection langs
18+
* @property Collection|Resim[] images
19+
*/
20+
class Reference extends Model
21+
{
22+
public function __set($key, $value)
23+
{
24+
switch ($key) {
25+
case 'images':
26+
$collection = new Collection();
27+
foreach ($value as $item) {
28+
$collection->push(new Resim($item));
29+
}
30+
$value = $collection;
31+
break;
32+
}
33+
34+
parent::__set($key, $value);
35+
}
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php namespace SistemApi\Model\Response;
2+
3+
use SistemApi\Model\Reference;
4+
use SistemApi\Model\Response\Base\PagedResponse;
5+
6+
class ReferencePagedResponse extends PagedResponse
7+
{
8+
/**
9+
* @param \stdClass $item
10+
*/
11+
public function __construct($item)
12+
{
13+
parent::__construct($item, Reference::class);
14+
}
15+
16+
/**
17+
* @return Reference[]
18+
*/
19+
public function getReferences()
20+
{
21+
return $this->kayitlar;
22+
}
23+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php namespace SistemApi\Service;
2+
3+
use SistemApi\Exception\BadRequestException;
4+
use SistemApi\Exception\InternalApiErrorException;
5+
use SistemApi\Exception\NotFoundException;
6+
use SistemApi\Exception\UnauthorizedException;
7+
use SistemApi\Exception\UnknownException;
8+
use SistemApi\Model\Resim;
9+
10+
class ImageService
11+
{
12+
/**
13+
* @Inject
14+
* @var ApiService
15+
*/
16+
private $api;
17+
18+
/**
19+
* @param array $data
20+
* @param string $image
21+
* @return Resim
22+
*
23+
* @throws BadRequestException
24+
* @throws UnauthorizedException
25+
* @throws UnknownException
26+
* @throws InternalApiErrorException
27+
*/
28+
public function createImage($data, $image)
29+
{
30+
// response alalım
31+
$response = $this->api->post('/image/create', $data, [
32+
'image' => $image
33+
]);
34+
35+
// durum koduna göre işlem yapalım
36+
switch ($response->code) {
37+
38+
case 200: return new Resim($response->body);
39+
case 400: throw new BadRequestException($response);
40+
case 401: throw new UnauthorizedException($response->body->mesaj);
41+
case 500: throw new InternalApiErrorException($response);
42+
}
43+
44+
throw new UnknownException($response);
45+
}
46+
47+
/**
48+
* @param int $id
49+
* @param array $data
50+
* @return Resim
51+
*
52+
* @throws BadRequestException
53+
* @throws UnauthorizedException
54+
* @throws NotFoundException
55+
* @throws UnknownException
56+
*/
57+
public function updateImage($id, $data)
58+
{
59+
// response alalım
60+
$response = $this->api->post('/image/update/' . $id, $data);
61+
62+
// durum koduna göre işlem yapalım
63+
switch ($response->code) {
64+
65+
case 200: return new Resim($response->body);
66+
case 400: throw new BadRequestException($response);
67+
case 401: throw new UnauthorizedException($response->body->mesaj);
68+
case 404: throw new NotFoundException($response->body->mesaj);
69+
case 500: throw new InternalApiErrorException($response);
70+
}
71+
72+
throw new UnknownException($response);
73+
}
74+
}
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
<?php namespace SistemApi\Service;
2+
3+
use SistemApi\Exception\BadRequestException;
4+
use SistemApi\Exception\InternalApiErrorException;
5+
use SistemApi\Exception\NotFoundException;
6+
use SistemApi\Exception\UnauthorizedException;
7+
use SistemApi\Exception\UnknownException;
8+
use SistemApi\Model\Ayar\ReferenceListConfig;
9+
use SistemApi\Model\Reference;
10+
use SistemApi\Model\Resim;
11+
use SistemApi\Model\Response\ReferencePagedResponse;
12+
13+
class ReferenceService
14+
{
15+
/**
16+
* @Inject
17+
* @var ApiService
18+
*/
19+
private $api;
20+
21+
/**
22+
* @param ReferenceListConfig $config
23+
* @return ReferencePagedResponse
24+
*
25+
* @throws UnauthorizedException
26+
* @throws UnknownException
27+
*/
28+
public function getReferences(ReferenceListConfig $config = null)
29+
{
30+
// response alalım
31+
$response = $this->api->get('/reference/list', is_null($config) ? [] : $config->toArray());
32+
33+
// durum koduna göre işlem yapalım
34+
switch ($response->code) {
35+
36+
case 200: return new ReferencePagedResponse($response->body);
37+
case 401: throw new UnauthorizedException($response->body->mesaj);
38+
case 500: throw new InternalApiErrorException($response);
39+
}
40+
41+
throw new UnknownException($response);
42+
}
43+
44+
/**
45+
* @param int $id
46+
* @return Reference
47+
*
48+
* @throws NotFoundException
49+
* @throws UnauthorizedException
50+
*/
51+
public function getReference($id)
52+
{
53+
// response alalım
54+
$response = $this->api->get('/reference/get/' . $id);
55+
56+
// durum koduna göre işlem yapalım
57+
switch ($response->code) {
58+
59+
case 200: return new Reference($response->body);
60+
case 401: throw new UnauthorizedException($response->body->mesaj);
61+
case 404: throw new NotFoundException($response->body->mesaj);
62+
case 500: throw new InternalApiErrorException($response);
63+
}
64+
65+
throw new UnknownException($response);
66+
}
67+
68+
/**
69+
* @param array $data
70+
* @return Reference
71+
*
72+
* @throws BadRequestException
73+
* @throws UnauthorizedException
74+
* @throws UnknownException
75+
*/
76+
public function createReference($data = [])
77+
{
78+
// response alalım
79+
$response = $this->api->post('/reference/create', $data);
80+
81+
// durum koduna göre işlem yapalım
82+
switch ($response->code) {
83+
84+
case 200: return new Reference($response->body);
85+
case 400: throw new BadRequestException($response);
86+
case 401: throw new UnauthorizedException($response->body->mesaj);
87+
case 500: throw new InternalApiErrorException($response);
88+
}
89+
90+
throw new UnknownException($response);
91+
}
92+
93+
/**
94+
* @param int $id
95+
* @param array $data
96+
* @return Reference
97+
*
98+
* @throws BadRequestException
99+
* @throws UnauthorizedException
100+
* @throws NotFoundException
101+
* @throws UnknownException
102+
*/
103+
public function updateReference($id, $data)
104+
{
105+
// response alalım
106+
$response = $this->api->post('/reference/update/' . $id, $data);
107+
108+
// durum koduna göre işlem yapalım
109+
switch ($response->code) {
110+
111+
case 200: return new Reference($response->body);
112+
case 400: throw new BadRequestException($response);
113+
case 401: throw new UnauthorizedException($response->body->mesaj);
114+
case 404: throw new NotFoundException($response->body->mesaj);
115+
case 500: throw new InternalApiErrorException($response);
116+
}
117+
118+
throw new UnknownException($response);
119+
}
120+
121+
/**
122+
* @param int $id
123+
* @return Reference
124+
*
125+
* @throws BadRequestException
126+
* @throws UnauthorizedException
127+
* @throws NotFoundException
128+
* @throws UnknownException
129+
*/
130+
public function deleteReference($id)
131+
{
132+
// response alalım
133+
$response = $this->api->get('/reference/delete/' . $id);
134+
135+
// durum koduna göre işlem yapalım
136+
switch ($response->code) {
137+
138+
case 200: return new Reference($response->body);
139+
case 400: throw new BadRequestException($response);
140+
case 401: throw new UnauthorizedException($response->body->mesaj);
141+
case 404: throw new NotFoundException($response->body->mesaj);
142+
case 500: throw new InternalApiErrorException($response);
143+
}
144+
145+
throw new UnknownException($response);
146+
}
147+
148+
/**
149+
* @param int $referenceId
150+
* @param string $image
151+
* @return Resim
152+
*
153+
* @throws NotFoundException
154+
* @throws UnauthorizedException
155+
*/
156+
public function createImage($referenceId, $image)
157+
{
158+
$files = [
159+
'image' => $image
160+
];
161+
162+
// response alalım
163+
$response = $this->api->post('/reference/image/create/' . $referenceId, [], $files);
164+
165+
// durum koduna göre işlem yapalım
166+
switch ($response->code) {
167+
168+
case 200: return new Resim($response->body);
169+
case 400: throw new BadRequestException($response);
170+
case 401: throw new UnauthorizedException($response->body->mesaj);
171+
case 404: throw new NotFoundException($response->body->mesaj);
172+
case 500: throw new InternalApiErrorException($response);
173+
}
174+
175+
throw new UnknownException($response);
176+
}
177+
178+
/**
179+
* @param int $referenceId
180+
* @param int $imageId
181+
* @return Reference
182+
*
183+
* @throws BadRequestException
184+
* @throws UnauthorizedException
185+
* @throws NotFoundException
186+
* @throws UnknownException
187+
*/
188+
public function deleteImage($referenceId, $imageId)
189+
{
190+
// response alalım
191+
$response = $this->api->get('/reference/image/delete/' . $referenceId . '/' . $imageId);
192+
193+
// durum koduna göre işlem yapalım
194+
switch ($response->code) {
195+
196+
case 200: return new Reference($response->body);
197+
case 400: throw new BadRequestException($response);
198+
case 401: throw new UnauthorizedException($response->body->mesaj);
199+
case 404: throw new NotFoundException($response->body->mesaj);
200+
case 500: throw new InternalApiErrorException($response);
201+
}
202+
203+
throw new UnknownException($response);
204+
}
205+
}

0 commit comments

Comments
 (0)