1
+ import axios from "axios" ;
2
+ import { drinkItemType , drinksType } from "../interfaces/drinksApiType" ;
3
+
4
+ const instance = axios . create ( {
5
+ baseURL : 'https://www.thecocktaildb.com/api/json/v1/1/'
6
+ } )
7
+
8
+ export const drinksAPI = {
9
+ searchByName ( name : string ) {
10
+ return instance . get < drinksType > ( 'search.php' , { params : { s : name } } )
11
+ . then ( res => res . data && res . data . drinks
12
+ ? res . data . drinks . map ( ( drinkItem : drinkItemType ) => {
13
+ return {
14
+ idDrink : drinkItem . idDrink ,
15
+ strDrink : drinkItem . strDrink ,
16
+ strDrinkThumb : drinkItem . strDrinkThumb ,
17
+ strAlcoholic : drinkItem . strAlcoholic
18
+ }
19
+ } )
20
+ : null )
21
+ . catch ( error => alert ( error ) )
22
+ } ,
23
+ filterIsAlcoholic ( isAlcoholic : boolean ) {
24
+ return instance . get < drinksType > ( 'filter.php' , { params : { a : isAlcoholic ? 'Alcoholic' : 'Non_Alcoholic' } } )
25
+ . then ( res => res . data . drinks )
26
+ . catch ( error => alert ( error ) )
27
+ } ,
28
+ getDetails ( id : string ) {
29
+ return instance . get < drinksType > ( 'lookup.php' , { params : { i : id } } )
30
+ . then ( res => res . data && res . data . drinks
31
+ ? res . data . drinks . map ( ( drinkItem : drinkItemType ) => {
32
+ return {
33
+ idDrink : drinkItem . idDrink ,
34
+ strDrink : drinkItem . strDrink ,
35
+ strDrinkThumb : drinkItem . strDrinkThumb ,
36
+ strAlcoholic : drinkItem . strAlcoholic ,
37
+ strInstructions : drinkItem . strInstructions
38
+ }
39
+ } )
40
+ : null )
41
+ . catch ( error => alert ( error ) )
42
+ }
43
+ }
0 commit comments