Skip to content

Commit

Permalink
🐛 Fix getRandomCat()
Browse files Browse the repository at this point in the history
  • Loading branch information
fre-ben committed Feb 13, 2021
1 parent 2694005 commit 34fa665
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
31 changes: 31 additions & 0 deletions notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,34 @@ API Documentation | Postman Collection.
If you need any example code, or have any questions then checkout the forum: https://forum.thatapiguy.com

All the best, Aden.

## Random cat

// Schema von random.cat
export type Cat = {
file: string;
};

export type Cats = {
results: Cat;
};

// Infos die ich brauch von der CatAPI
export type RandomCat = {
imgSrc: string;
};

function convertToImage(randomCat: Cat): RandomCat {
return {
imgSrc: randomCat.file,
};
}

export async function getRandomCat() {
const response = await fetch(`https://aws.random.cat/meow`);
const result = (await response.json()) as Cat;
const test = convertToImage(result);
// const test = result.map((randomCat) => convertToImage(randomCat));
console.log(result);
return test;
}
4 changes: 2 additions & 2 deletions src/components/cat/randomcat.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createElement } from "../../utils/createElement";

export function displayCat({ url }) {
export function displayCat({ imgSrc }) {
return createElement("img", {
className: "catImg",
src: url,
src: imgSrc,
alt: "cat",
});
}
7 changes: 4 additions & 3 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type Cat = {
url: string;
};

// Infos, die ich brauch von der CatAPI
// Infos die ich brauch von der CatAPI
export type RandomCat = {
imgSrc: string;
};
Expand All @@ -28,7 +28,8 @@ export async function getRandomCat() {
},
}
);
const result = (await response.json()) as Cat;
const test = convertToImage(result);
const result = (await response.json()) as Cat[];
const test = convertToImage(result[0]);
console.log(result);
return test;
}

0 comments on commit 34fa665

Please sign in to comment.