· 5 years ago · Feb 16, 2021, 07:30 PM
1/**
2 * Accounting API
3 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4 *
5 * The version of the OpenAPI document: 1.0.0
6 *
7 *
8 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9 * https://openapi-generator.tech
10 * Do not edit the class manually.
11 */
12/* tslint:disable:no-unused-variable member-ordering */
13
14import { Inject, Injectable, Optional } from '@angular/core';
15import { HttpClient, HttpHeaders, HttpParams,
16 HttpResponse, HttpEvent, HttpParameterCodec } from '@angular/common/http';
17import { CustomHttpParameterCodec } from '../encoder';
18import { Observable } from 'rxjs';
19
20import { ClientDTO } from '../model/models';
21import { ClientsPageDTO } from '../model/models';
22import { ErrorResponseDTO } from '../model/models';
23
24import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
25import { Configuration } from '../configuration';
26
27
28
29@Injectable({
30 providedIn: 'root'
31})
32export class ClientService {
33
34 protected basePath = 'http://localhost/api/v1';
35 public defaultHeaders = new HttpHeaders();
36 public configuration = new Configuration();
37 public encoder: HttpParameterCodec;
38
39 constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
40 if (configuration) {
41 this.configuration = configuration;
42 }
43 if (typeof this.configuration.basePath !== 'string') {
44 if (typeof basePath !== 'string') {
45 basePath = this.basePath;
46 }
47 this.configuration.basePath = basePath;
48 }
49 this.encoder = this.configuration.encoder || new CustomHttpParameterCodec();
50 }
51
52
53
54 private addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams {
55 if (typeof value === "object") {
56 httpParams = this.addToHttpParamsRecursive(httpParams, value);
57 } else {
58 httpParams = this.addToHttpParamsRecursive(httpParams, value, key);
59 }
60 return httpParams;
61 }
62
63 private addToHttpParamsRecursive(httpParams: HttpParams, value: any, key?: string): HttpParams {
64 if (typeof value === "object") {
65 if (Array.isArray(value)) {
66 (value as any[]).forEach( elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key));
67 } else if (value instanceof Date) {
68 if (key != null) {
69 httpParams = httpParams.append(key,
70 (value as Date).toISOString().substr(0, 10));
71 } else {
72 throw Error("key may not be null if value is Date");
73 }
74 } else {
75 Object.keys(value).forEach( k => httpParams = this.addToHttpParamsRecursive(
76 httpParams, value[k], key != null ? `${key}.${k}` : k));
77 }
78 } else if (key != null) {
79 httpParams = httpParams.append(key, value);
80 } else {
81 throw Error("key may not be null if value is not object or array");
82 }
83 return httpParams;
84 }
85
86 /**
87 * Create a new client
88 * @param clientDTO Client to create
89 * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
90 * @param reportProgress flag to report request and response progress.
91 */
92 public createClient(clientDTO: ClientDTO, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<ClientDTO>;
93 public createClient(clientDTO: ClientDTO, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<HttpResponse<ClientDTO>>;
94 public createClient(clientDTO: ClientDTO, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<HttpEvent<ClientDTO>>;
95 public createClient(clientDTO: ClientDTO, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json'}): Observable<any> {
96 if (clientDTO === null || clientDTO === undefined) {
97 throw new Error('Required parameter clientDTO was null or undefined when calling createClient.');
98 }
99
100 let headers = this.defaultHeaders;
101
102 // authentication (bearerAuth) required
103 if (this.configuration.accessToken) {
104 const accessToken = typeof this.configuration.accessToken === 'function'
105 ? this.configuration.accessToken()
106 : this.configuration.accessToken;
107 headers = headers.set('Authorization', 'Bearer ' + accessToken);
108 }
109 let httpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
110 if (httpHeaderAcceptSelected === undefined) {
111 // to determine the Accept header
112 const httpHeaderAccepts: string[] = [
113 'application/json'
114 ];
115 httpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
116 }
117 if (httpHeaderAcceptSelected !== undefined) {
118 headers = headers.set('Accept', httpHeaderAcceptSelected);
119 }
120
121
122 // to determine the Content-Type header
123 const consumes: string[] = [
124 'application/json'
125 ];
126 const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
127 if (httpContentTypeSelected !== undefined) {
128 headers = headers.set('Content-Type', httpContentTypeSelected);
129 }
130
131 let responseType: 'text' | 'json' = 'json';
132 if(httpHeaderAcceptSelected && httpHeaderAcceptSelected.startsWith('text')) {
133 responseType = 'text';
134 }
135
136 return this.httpClient.post<ClientDTO>(`${this.configuration.basePath}/clients`,
137 clientDTO,
138 {
139 responseType: <any>responseType,
140 withCredentials: this.configuration.withCredentials,
141 headers: headers,
142 observe: observe,
143 reportProgress: reportProgress
144 }
145 );
146 }
147
148 /**
149 * Delete a client
150 * @param id ID of the client to delete
151 * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
152 * @param reportProgress flag to report request and response progress.
153 */
154 public deleteClient(id: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<any>;
155 public deleteClient(id: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<HttpResponse<any>>;
156 public deleteClient(id: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<HttpEvent<any>>;
157 public deleteClient(id: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json'}): Observable<any> {
158 if (id === null || id === undefined) {
159 throw new Error('Required parameter id was null or undefined when calling deleteClient.');
160 }
161
162 let headers = this.defaultHeaders;
163
164 // authentication (bearerAuth) required
165 if (this.configuration.accessToken) {
166 const accessToken = typeof this.configuration.accessToken === 'function'
167 ? this.configuration.accessToken()
168 : this.configuration.accessToken;
169 headers = headers.set('Authorization', 'Bearer ' + accessToken);
170 }
171 let httpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
172 if (httpHeaderAcceptSelected === undefined) {
173 // to determine the Accept header
174 const httpHeaderAccepts: string[] = [
175 'application/json'
176 ];
177 httpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
178 }
179 if (httpHeaderAcceptSelected !== undefined) {
180 headers = headers.set('Accept', httpHeaderAcceptSelected);
181 }
182
183
184 let responseType: 'text' | 'json' = 'json';
185 if(httpHeaderAcceptSelected && httpHeaderAcceptSelected.startsWith('text')) {
186 responseType = 'text';
187 }
188
189 return this.httpClient.delete<any>(`${this.configuration.basePath}/clients/${encodeURIComponent(String(id))}`,
190 {
191 responseType: <any>responseType,
192 withCredentials: this.configuration.withCredentials,
193 headers: headers,
194 observe: observe,
195 reportProgress: reportProgress
196 }
197 );
198 }
199
200 /**
201 * Returns a client based on a single ID
202 * @param id ID of the client to fetch
203 * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
204 * @param reportProgress flag to report request and response progress.
205 */
206 public getClientById(id: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<ClientDTO>;
207 public getClientById(id: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<HttpResponse<ClientDTO>>;
208 public getClientById(id: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<HttpEvent<ClientDTO>>;
209 public getClientById(id: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json'}): Observable<any> {
210 if (id === null || id === undefined) {
211 throw new Error('Required parameter id was null or undefined when calling getClientById.');
212 }
213
214 let headers = this.defaultHeaders;
215
216 // authentication (bearerAuth) required
217 if (this.configuration.accessToken) {
218 const accessToken = typeof this.configuration.accessToken === 'function'
219 ? this.configuration.accessToken()
220 : this.configuration.accessToken;
221 headers = headers.set('Authorization', 'Bearer ' + accessToken);
222 }
223 let httpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
224 if (httpHeaderAcceptSelected === undefined) {
225 // to determine the Accept header
226 const httpHeaderAccepts: string[] = [
227 'application/json'
228 ];
229 httpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
230 }
231 if (httpHeaderAcceptSelected !== undefined) {
232 headers = headers.set('Accept', httpHeaderAcceptSelected);
233 }
234
235
236 let responseType: 'text' | 'json' = 'json';
237 if(httpHeaderAcceptSelected && httpHeaderAcceptSelected.startsWith('text')) {
238 responseType = 'text';
239 }
240
241 return this.httpClient.get<ClientDTO>(`${this.configuration.basePath}/clients/${encodeURIComponent(String(id))}`,
242 {
243 responseType: <any>responseType,
244 withCredentials: this.configuration.withCredentials,
245 headers: headers,
246 observe: observe,
247 reportProgress: reportProgress
248 }
249 );
250 }
251
252 /**
253 * Get a list of all clients
254 * @param page page
255 * @param size size
256 * @param name Filtering parameter for clients
257 * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
258 * @param reportProgress flag to report request and response progress.
259 */
260 public getClients(page?: number, size?: number, name?: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<ClientsPageDTO>;
261 public getClients(page?: number, size?: number, name?: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<HttpResponse<ClientsPageDTO>>;
262 public getClients(page?: number, size?: number, name?: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<HttpEvent<ClientsPageDTO>>;
263 public getClients(page?: number, size?: number, name?: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json'}): Observable<any> {
264
265 let queryParameters = new HttpParams({encoder: this.encoder});
266 if (page !== undefined && page !== null) {
267 queryParameters = this.addToHttpParams(queryParameters,
268 <any>page, 'page');
269 }
270 if (size !== undefined && size !== null) {
271 queryParameters = this.addToHttpParams(queryParameters,
272 <any>size, 'size');
273 }
274 if (name !== undefined && name !== null) {
275 queryParameters = this.addToHttpParams(queryParameters,
276 <any>name, 'name');
277 }
278
279 let headers = this.defaultHeaders;
280
281 // authentication (bearerAuth) required
282 if (this.configuration.accessToken) {
283 const accessToken = typeof this.configuration.accessToken === 'function'
284 ? this.configuration.accessToken()
285 : this.configuration.accessToken;
286 headers = headers.set('Authorization', 'Bearer ' + accessToken);
287 }
288 let httpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
289 if (httpHeaderAcceptSelected === undefined) {
290 // to determine the Accept header
291 const httpHeaderAccepts: string[] = [
292 'application/json'
293 ];
294 httpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
295 }
296 if (httpHeaderAcceptSelected !== undefined) {
297 headers = headers.set('Accept', httpHeaderAcceptSelected);
298 }
299
300
301 let responseType: 'text' | 'json' = 'json';
302 if(httpHeaderAcceptSelected && httpHeaderAcceptSelected.startsWith('text')) {
303 responseType = 'text';
304 }
305
306 return this.httpClient.get<ClientsPageDTO>(`${this.configuration.basePath}/clients`,
307 {
308 params: queryParameters,
309 responseType: <any>responseType,
310 withCredentials: this.configuration.withCredentials,
311 headers: headers,
312 observe: observe,
313 reportProgress: reportProgress
314 }
315 );
316 }
317
318 /**
319 * Update a client
320 * @param id ID of the client to update
321 * @param clientDTO Client to update
322 * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
323 * @param reportProgress flag to report request and response progress.
324 */
325 public updateClient(id: string, clientDTO: ClientDTO, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<ClientDTO>;
326 public updateClient(id: string, clientDTO: ClientDTO, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<HttpResponse<ClientDTO>>;
327 public updateClient(id: string, clientDTO: ClientDTO, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable<HttpEvent<ClientDTO>>;
328 public updateClient(id: string, clientDTO: ClientDTO, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json'}): Observable<any> {
329 if (id === null || id === undefined) {
330 throw new Error('Required parameter id was null or undefined when calling updateClient.');
331 }
332 if (clientDTO === null || clientDTO === undefined) {
333 throw new Error('Required parameter clientDTO was null or undefined when calling updateClient.');
334 }
335
336 let headers = this.defaultHeaders;
337
338 // authentication (bearerAuth) required
339 if (this.configuration.accessToken) {
340 const accessToken = typeof this.configuration.accessToken === 'function'
341 ? this.configuration.accessToken()
342 : this.configuration.accessToken;
343 headers = headers.set('Authorization', 'Bearer ' + accessToken);
344 }
345 let httpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
346 if (httpHeaderAcceptSelected === undefined) {
347 // to determine the Accept header
348 const httpHeaderAccepts: string[] = [
349 'application/json'
350 ];
351 httpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
352 }
353 if (httpHeaderAcceptSelected !== undefined) {
354 headers = headers.set('Accept', httpHeaderAcceptSelected);
355 }
356
357
358 // to determine the Content-Type header
359 const consumes: string[] = [
360 'application/json'
361 ];
362 const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
363 if (httpContentTypeSelected !== undefined) {
364 headers = headers.set('Content-Type', httpContentTypeSelected);
365 }
366
367 let responseType: 'text' | 'json' = 'json';
368 if(httpHeaderAcceptSelected && httpHeaderAcceptSelected.startsWith('text')) {
369 responseType = 'text';
370 }
371
372 return this.httpClient.put<ClientDTO>(`${this.configuration.basePath}/clients/${encodeURIComponent(String(id))}`,
373 clientDTO,
374 {
375 responseType: <any>responseType,
376 withCredentials: this.configuration.withCredentials,
377 headers: headers,
378 observe: observe,
379 reportProgress: reportProgress
380 }
381 );
382 }
383
384}
385