-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: notes | Connect Notes to Backend (#534)
* [Feat] Connect Notes To Backend why: so the notes will be stored in db how: change the redux slice file, add fetching data with axios * [Feat] Connect Notes To Backend why: so the notes will be stored in db how: change the redux slice file, add fetching data with axios
- Loading branch information
Showing
6 changed files
with
256 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,65 @@ | ||
// we will add here the services after finising with the back-end | ||
import axios from "axios"; | ||
import { getApiUrl } from "../apiUrl"; | ||
|
||
const API_URL = getApiUrl("api/notes/"); | ||
|
||
// Create new note | ||
const createNote = async (noteData, token) => { | ||
const config = { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}; | ||
|
||
const response = await axios.post(API_URL, noteData, config); | ||
|
||
return response.data; | ||
}; | ||
|
||
// Update note | ||
const updateNote = async (id, noteData, token) => { | ||
const config = { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}; | ||
|
||
const response = await axios.put(API_URL + id, noteData, config); | ||
|
||
return response.data; | ||
}; | ||
|
||
// Get user notes | ||
const getNotes = async (token) => { | ||
const config = { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}; | ||
|
||
const response = await axios.get(API_URL, config); | ||
|
||
return response.data; | ||
}; | ||
|
||
// Delete user note | ||
const deleteNote = async (noteId, token) => { | ||
const config = { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}; | ||
|
||
const response = await axios.delete(API_URL + noteId, config); | ||
|
||
return response.data; | ||
}; | ||
|
||
const notesService = { | ||
createNote, | ||
updateNote, | ||
getNotes, | ||
deleteNote, | ||
}; | ||
|
||
export default notesService; |
Oops, something went wrong.