Moved api functions to relevant folders
This commit is contained in:
30
src/api/le-systeme-solaire/index.ts
Normal file
30
src/api/le-systeme-solaire/index.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the API for all celestial bodies
|
||||||
|
* @returns Array of celestials in the API
|
||||||
|
*/
|
||||||
|
export const fetchCelestials = (): Promise<any> => {
|
||||||
|
return axios
|
||||||
|
.get("https://api.le-systeme-solaire.net/rest/bodies/")
|
||||||
|
.then(res => {
|
||||||
|
return res.data.bodies;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the API for all celestial bodies
|
||||||
|
* @returns Array of celestials in the API
|
||||||
|
*/
|
||||||
|
export const fetchCelestial = (slug: string): Promise<any> => {
|
||||||
|
return axios
|
||||||
|
.get(`https://api.le-systeme-solaire.net/rest/bodies/${slug}`)
|
||||||
|
.then(res => {
|
||||||
|
return res.data;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
fetchCelestials,
|
||||||
|
fetchCelestial
|
||||||
|
};
|
||||||
0
src/api/wikipedia/index.ts
Normal file
0
src/api/wikipedia/index.ts
Normal file
@@ -28,4 +28,4 @@ export const addCelestialsType = (celestials: any) => {
|
|||||||
export default {
|
export default {
|
||||||
addCelestialType,
|
addCelestialType,
|
||||||
addCelestialsType
|
addCelestialsType
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
import { defineComponent } from "vue";
|
import { defineComponent } from "vue";
|
||||||
|
|
||||||
// API
|
// API
|
||||||
import axios from "axios";
|
import { fetchCelestial } from "@/api/le-systeme-solaire";
|
||||||
|
|
||||||
// Global methods
|
// Global methods
|
||||||
import { addCelestialType } from "@/plugins/methods";
|
import { addCelestialType } from "@/plugins/methods";
|
||||||
import NestLoader from "@/components/NestLoader.vue";
|
import NestLoader from "@/components/NestLoader.vue";
|
||||||
@@ -47,7 +48,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
// Fetches from API...
|
// Fetches from API...
|
||||||
this.fetchCelestial()
|
fetchCelestial(this.slug)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
// Adds type after fake loading (it's just to showcase the spinner tbh)
|
// Adds type after fake loading (it's just to showcase the spinner tbh)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -58,19 +59,6 @@ export default defineComponent({
|
|||||||
.catch(() => {
|
.catch(() => {
|
||||||
this.error = "Impossible de récupérer l'astre demandé.";
|
this.error = "Impossible de récupérer l'astre demandé.";
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
/**
|
|
||||||
* Fetches celestial body from API
|
|
||||||
*/
|
|
||||||
fetchCelestial(): Promise<any> {
|
|
||||||
return axios
|
|
||||||
.get(`https://api.le-systeme-solaire.net/rest/bodies/${this.slug}`)
|
|
||||||
.then(res => {
|
|
||||||
return res.data;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
import { defineComponent, onMounted, ref } from "vue";
|
import { defineComponent, onMounted, ref } from "vue";
|
||||||
|
|
||||||
// API
|
// API
|
||||||
import axios from "axios";
|
import { fetchCelestials } from "@/api/le-systeme-solaire";
|
||||||
|
|
||||||
// Global methods
|
// Global methods
|
||||||
import { addCelestialsType } from "@/plugins/methods";
|
import { addCelestialsType } from "@/plugins/methods";
|
||||||
|
|
||||||
@@ -41,17 +42,6 @@ export default defineComponent({
|
|||||||
setup() {
|
setup() {
|
||||||
const celestials = ref(Array<any>());
|
const celestials = ref(Array<any>());
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches celestial bodies from API
|
|
||||||
*/
|
|
||||||
const fetchCelestials = (): Promise<any> => {
|
|
||||||
return axios
|
|
||||||
.get("https://api.le-systeme-solaire.net/rest/bodies/")
|
|
||||||
.then(res => {
|
|
||||||
return res.data.bodies;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const getCelestials = async () => {
|
const getCelestials = async () => {
|
||||||
celestials.value = await fetchCelestials();
|
celestials.value = await fetchCelestials();
|
||||||
celestials.value = addCelestialsType(celestials.value);
|
celestials.value = addCelestialsType(celestials.value);
|
||||||
|
|||||||
Reference in New Issue
Block a user