@@ -9,20 +9,54 @@ export const ROUTE_URL = {
9
9
10
10
export enum PET_API_TYPE { DOG , CAT }
11
11
12
- export interface PetApiData {
12
+ export abstract class BreedData { }
13
+
14
+ export class DogBreedData extends BreedData {
15
+ breed : string
16
+ // bredFor: string[]
17
+ heightRangeCM : number [ ]
18
+ lifespanRange : number [ ]
19
+ // temperament: string[]
20
+ // weightKG: number[]
21
+
22
+ constructor ( breedsObj : any ) {
23
+ super ( )
24
+ this . breed = breedsObj . breed
25
+ // this.bredFor = breedsObj.bred_for.split(",").map((s: string) => s.trim())
26
+ this . heightRangeCM = breedsObj . height . metric . split ( "-" ) . map ( ( h : string ) => parseInt ( h ) )
27
+ this . lifespanRange = breedsObj . life_span . split ( "-" ) . map ( ( ls : string ) => parseInt ( ls ) )
28
+ }
29
+ }
30
+
31
+ export class CatBreedData extends BreedData {
32
+ constructor ( breedsObj : any ) {
33
+ super ( )
34
+ }
35
+ }
36
+
37
+ export class PetApiData {
13
38
id : number
14
39
imgURL : string
15
- breeds : any
16
- // breeds: {
17
- // name: string
18
- // heightCM: number
19
- // temperament: string[]
20
- // weightKG: number
21
- // }
22
-
40
+ breedData : BreedData | null
23
41
height : number
24
42
width : number
25
43
apiType : PET_API_TYPE
44
+
45
+ constructor ( id : number , imgURL : string , breedData : any , height : number , width : number , apiType : PET_API_TYPE ) {
46
+ this . id = id
47
+ this . imgURL = imgURL
48
+ this . breedData = null
49
+ this . height = height
50
+ this . width = width
51
+ this . apiType = apiType
52
+
53
+ if ( apiType === PET_API_TYPE . CAT ) {
54
+ this . breedData = new CatBreedData ( breedData )
55
+ }
56
+ else if ( apiType === PET_API_TYPE . DOG ) {
57
+ this . breedData = new DogBreedData ( breedData )
58
+ }
59
+ }
26
60
}
27
61
28
62
export const Utils = {
@@ -51,14 +85,13 @@ export const Utils = {
51
85
return new Date ( randomTimestamp ) ;
52
86
} ,
53
87
convertToPetApiData ( obj : any , apiType : PET_API_TYPE ) : PetApiData {
54
- return {
55
- id : obj . id ,
56
- imgURL : obj . url ,
57
- breeds : obj . breeds ,
58
- height : obj . height ,
59
- width : obj . width ,
60
- apiType : apiType
61
- } as PetApiData
88
+ return new PetApiData (
89
+ obj . id , obj . url ,
90
+ apiType === PET_API_TYPE . DOG ?
91
+ new DogBreedData ( obj . breeds [ 0 ] ) :
92
+ new CatBreedData ( obj . breeds [ 0 ] ) ,
93
+ obj . height , obj . width , apiType
94
+ )
62
95
} ,
63
96
durstenfeldShuffle ( arr : any [ ] ) : void {
64
97
for ( var i = arr . length - 1 ; i >= 0 ; i -- ) {
0 commit comments