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
|
// Note APIs
|
||||||
|
|
||||||
|
const instance = axios.create({
|
||||||
|
baseURL: "https://keannu126.pythonanywhere.com",
|
||||||
|
});
|
||||||
|
|
||||||
export function GetNotes() {
|
export function GetNotes() {
|
||||||
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
||||||
return axios
|
return instance
|
||||||
.get("http://localhost:8000/api/v1/notes/", {
|
.get("/api/v1/notes/", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Token " + token,
|
Authorization: "Token " + token,
|
||||||
},
|
},
|
||||||
|
@ -24,8 +28,8 @@ export function GetNotes() {
|
||||||
|
|
||||||
export function GetNote(id: number) {
|
export function GetNote(id: number) {
|
||||||
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
||||||
return axios
|
return instance
|
||||||
.get("http://localhost:8000/api/v1/notes/" + id + "/", {
|
.get("/api/v1/notes/" + id + "/", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Token " + token,
|
Authorization: "Token " + token,
|
||||||
},
|
},
|
||||||
|
@ -37,8 +41,8 @@ export function GetNote(id: number) {
|
||||||
|
|
||||||
export function UpdateNote(note: UpdateNoteParams) {
|
export function UpdateNote(note: UpdateNoteParams) {
|
||||||
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
||||||
return axios
|
return instance
|
||||||
.patch("http://localhost:8000/api/v1/notes/" + note.id + "/", note, {
|
.patch("/api/v1/notes/" + note.id + "/", note, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Token " + token,
|
Authorization: "Token " + token,
|
||||||
},
|
},
|
||||||
|
@ -47,15 +51,14 @@ export function UpdateNote(note: UpdateNoteParams) {
|
||||||
return response.data;
|
return response.data;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("Error updating note", error);
|
|
||||||
return error;
|
return error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AddNote(note: AddNoteParams) {
|
export function AddNote(note: AddNoteParams) {
|
||||||
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
||||||
return axios
|
return instance
|
||||||
.post("http://localhost:8000/api/v1/notes/", note, {
|
.post("/api/v1/notes/", note, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Token " + token,
|
Authorization: "Token " + token,
|
||||||
},
|
},
|
||||||
|
@ -64,21 +67,19 @@ export function AddNote(note: AddNoteParams) {
|
||||||
return response.data;
|
return response.data;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("Error adding note", error);
|
|
||||||
return error;
|
return error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DeleteNote(id: number) {
|
export function DeleteNote(id: number) {
|
||||||
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
||||||
return axios
|
return instance
|
||||||
.delete("http://localhost:8000/api/v1/notes/" + id + "/", {
|
.delete("/api/v1/notes/" + id + "/", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Token " + token,
|
Authorization: "Token " + token,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("Error deleting note", error);
|
|
||||||
return error;
|
return error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -86,58 +87,48 @@ export function DeleteNote(id: number) {
|
||||||
// User APIs
|
// User APIs
|
||||||
|
|
||||||
export function UserRegister(register: RegistrationParams) {
|
export function UserRegister(register: RegistrationParams) {
|
||||||
return axios
|
return instance
|
||||||
.post("http://localhost:8000/api/v1/accounts/users/", register)
|
.post("/api/v1/accounts/users/", register)
|
||||||
.then(async (response) => {
|
.then(async (response) => {
|
||||||
console.log(response.data);
|
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("Registration failed: " + error);
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function UserLogin(user: LoginParams) {
|
export function UserLogin(user: LoginParams) {
|
||||||
return axios
|
return instance
|
||||||
.post("http://localhost:8000/api/v1/accounts/token/login/", user)
|
.post("/api/v1/accounts/token/login/", user)
|
||||||
.then(async (response) => {
|
.then(async (response) => {
|
||||||
localStorage.setItem("token", JSON.stringify(response.data.auth_token));
|
localStorage.setItem("token", JSON.stringify(response.data.auth_token));
|
||||||
console.log(
|
|
||||||
"Login Success! Stored Token: ",
|
|
||||||
JSON.parse(localStorage.getItem("token") || "{}")
|
|
||||||
);
|
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("Login Failed: " + error);
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function UserInfo() {
|
export function UserInfo() {
|
||||||
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
const token = JSON.parse(localStorage.getItem("token") || "{}");
|
||||||
return axios
|
return instance
|
||||||
.get("http://localhost:8000/api/v1/accounts/users/me/", {
|
.get("/api/v1/accounts/users/me/", {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Token " + token,
|
Authorization: "Token " + token,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log(response.data);
|
|
||||||
return response.data;
|
return response.data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function UserActivate(activation: ActivationParams) {
|
export function UserActivate(activation: ActivationParams) {
|
||||||
return axios
|
return instance
|
||||||
.post("http://localhost:8000/api/v1/accounts/users/activation/", activation)
|
.post("/api/v1/accounts/users/activation/", activation)
|
||||||
.then(async (response) => {
|
.then(async (response) => {
|
||||||
console.log("Activation Success");
|
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("Activation failed: " + error);
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue