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