diff --git a/src/api/posts.api.js b/src/api/posts.api.js index 06e9fd7..851cbf2 100644 --- a/src/api/posts.api.js +++ b/src/api/posts.api.js @@ -2,17 +2,36 @@ import axios from "axios" 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 = { 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, + }) } } \ No newline at end of file