Skip to content

Commit

Permalink
interfaces-to-classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Zogg committed Mar 29, 2020
1 parent 5d5c601 commit 27040ee
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/ApiClient/Pet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ListPets = async (queryString: string): Promise<HttpError | PetList
const json = await response.json();

if (200 === response.status) {
return json;
return new PetList({ ...json });
}

if (400 === response.status) {
Expand Down Expand Up @@ -53,7 +53,7 @@ export const CreatePet = async (pet: PetRequest): Promise<HttpError | PetRespons
const json = await response.json();

if (201 === response.status) {
return json;
return new PetResponse({ ...json });
}

if (422 === response.status) {
Expand Down Expand Up @@ -82,7 +82,7 @@ export const ReadPet = async (id: string): Promise<HttpError | PetResponse> => {
const json = await response.json();

if (200 === response.status) {
return json;
return new PetResponse({ ...json });
}

if (404 === response.status) {
Expand Down Expand Up @@ -113,7 +113,7 @@ export const UpdatePet = async (id: string, pet: PetRequest): Promise<HttpError
const json = await response.json();

if (200 === response.status) {
return json;
return new PetResponse({ ...json });
}

if (404 === response.status) {
Expand Down
5 changes: 4 additions & 1 deletion src/Model/Pet/Embedded.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import PetResponse from './PetResponse';

interface Embedded {
class Embedded {
items: Array<PetResponse>;
constructor({ items }: { items: Array<PetResponse> }) {
this.items = items;
}
};

export default Embedded;
5 changes: 4 additions & 1 deletion src/Model/Pet/PetFilters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
interface PetFilters {
class PetFilters {
name?: string;
constructor({ name }: { name?: string }) {
this.name = name;
}
};

export default PetFilters;
9 changes: 8 additions & 1 deletion src/Model/Pet/PetList.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import Embedded from './Embedded';
import Links from './Links';

interface PetList {
class PetList {
offset: number;
limit: number;
count: number;
_embedded: Embedded;
_links: Links;
constructor({ offset, limit, count, _embedded, _links }: { offset: number, limit: number, count: number, _embedded: Embedded, _links: Links }) {
this.offset = offset;
this.limit = limit;
this.count = count;
this._embedded = _embedded;
this._links = _links;
}
};

export default PetList;
8 changes: 6 additions & 2 deletions src/Model/Pet/PetRequest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Vaccination from './Vaccination';
import Links from './Links';

interface PetRequest {
class PetRequest {
name: string;
tag?: string;
vaccinations: Array<Vaccination>;
constructor({ name, tag, vaccinations }: { name: string, tag?: string, vaccinations: Array<Vaccination> }) {
this.name = name;
this.tag = tag;
this.vaccinations = vaccinations;
}
};

export default PetRequest;
14 changes: 11 additions & 3 deletions src/Model/Pet/PetResponse.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import Links from './Links';
import PetRequest from './PetRequest';
import Vaccination from './Vaccination';

interface PetResponse extends PetRequest {
class PetResponse extends PetRequest {
id: string;
createdAt: string,
updatedAt?: string,
createdAt: string;
updatedAt?: string;
_links: Links;
constructor({ id, createdAt, updatedAt, name, tag, vaccinations, _links }: { id: string, createdAt: string, updatedAt?: string, name: string, tag?: string, vaccinations: Array<Vaccination>, _links: Links; }) {
super({ name, tag, vaccinations });
this.id = id;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this._links = _links;
}
};

export default PetResponse;
5 changes: 4 additions & 1 deletion src/Model/Pet/Vaccination.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
interface Vaccination {
class Vaccination {
name: string;
constructor({ name }: { name: string }) {
this.name = name;
}
};

export default Vaccination;

0 comments on commit 27040ee

Please sign in to comment.