implemented API
This commit is contained in:
@@ -2,17 +2,36 @@ import axios from "axios"
|
|||||||
|
|
||||||
const path = "https://api.jodel.anxietyprime.de/post";
|
const path = "https://api.jodel.anxietyprime.de/post";
|
||||||
|
|
||||||
const config = {
|
|
||||||
headers: {
|
|
||||||
auth: {
|
|
||||||
username: process.env.REACT_APP_AUTH_USERNAME,
|
|
||||||
password: process.env.REACT_APP_AUTH_PASSWORD,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const postApi = {
|
export const postApi = {
|
||||||
async getPostsByCoords (lon, lat) {
|
async getPostsByCoords (lon, lat) {
|
||||||
return (await axios.get(`${path}/${lon}/${lat}`, this.config)).data;
|
return (await axios.get(`${path}s/${lon}/${lat}`)).data;
|
||||||
|
},
|
||||||
|
async getPostByID (id) {
|
||||||
|
return (await axios.get(`${path}/${id}`)).data;
|
||||||
|
},
|
||||||
|
async createNewPost(title, content) {
|
||||||
|
if (navigator.geolocation) {
|
||||||
|
navigator.geolocation.getCurrentPosition(async function(position) {
|
||||||
|
const latitude = position.coords.latitude;
|
||||||
|
const longitude = position.coords.longitude;
|
||||||
|
await axios.post(`${path}s`, {
|
||||||
|
"authorID": 1,
|
||||||
|
"title": title,
|
||||||
|
"content": content,
|
||||||
|
"date": Date.now().toString(),
|
||||||
|
"location": {
|
||||||
|
"longitude": longitude,
|
||||||
|
"latitude": latitude,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log("Geolocation is not supported by this browser. Could'nt post without valid location");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async reactToPost(id, reaction) {
|
||||||
|
await axios.put(`${path}/${id}`, {
|
||||||
|
"reaction": reaction,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user