mirror of
https://github.com/lemeow125/React-NotesApp.git
synced 2024-11-17 06:29:28 +08:00
Removed console.logs from apis
This commit is contained in:
parent
c2e58117b7
commit
eff9ebcbfa
1 changed files with 22 additions and 31 deletions
|
@ -9,10 +9,14 @@ import {
|
|||
|
||||
// Note APIs
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL: "https://keannu126.pythonanywhere.com",
|
||||
});
|
||||
|
||||
export function GetNotes() {
|
||||
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
||||
return axios
|
||||
.get("http://localhost:8000/api/v1/notes/", {
|
||||
return instance
|
||||
.get("/api/v1/notes/", {
|
||||
headers: {
|
||||
Authorization: "Token " + token,
|
||||
},
|
||||
|
@ -24,8 +28,8 @@ export function GetNotes() {
|
|||
|
||||
export function GetNote(id: number) {
|
||||
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
||||
return axios
|
||||
.get("http://localhost:8000/api/v1/notes/" + id + "/", {
|
||||
return instance
|
||||
.get("/api/v1/notes/" + id + "/", {
|
||||
headers: {
|
||||
Authorization: "Token " + token,
|
||||
},
|
||||
|
@ -37,8 +41,8 @@ export function GetNote(id: number) {
|
|||
|
||||
export function UpdateNote(note: UpdateNoteParams) {
|
||||
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
||||
return axios
|
||||
.patch("http://localhost:8000/api/v1/notes/" + note.id + "/", note, {
|
||||
return instance
|
||||
.patch("/api/v1/notes/" + note.id + "/", note, {
|
||||
headers: {
|
||||
Authorization: "Token " + token,
|
||||
},
|
||||
|
@ -47,15 +51,14 @@ export function UpdateNote(note: UpdateNoteParams) {
|
|||
return response.data;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Error updating note", error);
|
||||
return error;
|
||||
});
|
||||
}
|
||||
|
||||
export function AddNote(note: AddNoteParams) {
|
||||
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
||||
return axios
|
||||
.post("http://localhost:8000/api/v1/notes/", note, {
|
||||
return instance
|
||||
.post("/api/v1/notes/", note, {
|
||||
headers: {
|
||||
Authorization: "Token " + token,
|
||||
},
|
||||
|
@ -64,21 +67,19 @@ export function AddNote(note: AddNoteParams) {
|
|||
return response.data;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Error adding note", error);
|
||||
return error;
|
||||
});
|
||||
}
|
||||
|
||||
export function DeleteNote(id: number) {
|
||||
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
||||
return axios
|
||||
.delete("http://localhost:8000/api/v1/notes/" + id + "/", {
|
||||
return instance
|
||||
.delete("/api/v1/notes/" + id + "/", {
|
||||
headers: {
|
||||
Authorization: "Token " + token,
|
||||
},
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Error deleting note", error);
|
||||
return error;
|
||||
});
|
||||
}
|
||||
|
@ -86,58 +87,48 @@ export function DeleteNote(id: number) {
|
|||
// User APIs
|
||||
|
||||
export function UserRegister(register: RegistrationParams) {
|
||||
return axios
|
||||
.post("http://localhost:8000/api/v1/accounts/users/", register)
|
||||
return instance
|
||||
.post("/api/v1/accounts/users/", register)
|
||||
.then(async (response) => {
|
||||
console.log(response.data);
|
||||
return true;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Registration failed: " + error);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
export function UserLogin(user: LoginParams) {
|
||||
return axios
|
||||
.post("http://localhost:8000/api/v1/accounts/token/login/", user)
|
||||
return instance
|
||||
.post("/api/v1/accounts/token/login/", user)
|
||||
.then(async (response) => {
|
||||
localStorage.setItem("token", JSON.stringify(response.data.auth_token));
|
||||
console.log(
|
||||
"Login Success! Stored Token: ",
|
||||
JSON.parse(localStorage.getItem("token") || "{}")
|
||||
);
|
||||
return true;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Login Failed: " + error);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
export function UserInfo() {
|
||||
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
||||
return axios
|
||||
.get("http://localhost:8000/api/v1/accounts/users/me/", {
|
||||
return instance
|
||||
.get("/api/v1/accounts/users/me/", {
|
||||
headers: {
|
||||
Authorization: "Token " + token,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response.data);
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
|
||||
export function UserActivate(activation: ActivationParams) {
|
||||
return axios
|
||||
.post("http://localhost:8000/api/v1/accounts/users/activation/", activation)
|
||||
return instance
|
||||
.post("/api/v1/accounts/users/activation/", activation)
|
||||
.then(async (response) => {
|
||||
console.log("Activation Success");
|
||||
return true;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Activation failed: " + error);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue