import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { Observable , of } from "rxjs" ; import { Country } from "src/app/common/country" ; import { State } from "src/app/common/state" ; import { map } from "rxjs/internal/operators/map" ; @ Injectable ( { providedIn : 'root' } ) export class CheckoutService { private countriesUrl = 'http://localhost:8080/api/v1/countries' ; private statesUrl = 'http://localhost:8080/api/v1/states/' ; constructor ( private httpClient ) { } getCountries ( ) { return this . httpClient . get < GetResponseCountries > ( this . countriesUrl ) . pipe ( map ( response => response . _embedded . countries ) ) ; } getStates ( theCountryCode ) { const searchStatesUrl = `${ this . statesUrl }/search/findByCountryCode?code=${ theCountryCode }` ; return this . httpClient . get < GetResponseStates > ( searchStatesUrl ) . pipe ( map ( response => response . _embedded . states ) ) ; } getCreditCardMonths ( startMonth ) { let data = [ ] ; for ( let theMonth = startMonth ; theMonth <= 12 ; theMonth ++ ) { data . push ( theMonth ) ; } return of ( data ) ; } getCreditCardYears ( ) { let data = [ ] ; const startYear = new Date ( ) . getFullYear ( ) ; const endYear = startYear + 10 ; for ( let theYear = startYear ; theYear <= endYear ; theYear ++ ) { data . push ( theYear ) ; } return of ( data ) ; } } interface GetResponseCountries { _embedded : { countries : Country [ ] ; } ; } interface GetResponseStates { _embedded : { states : State [ ] ; } ; }