Polish api and link to deployed backend

This commit is contained in:
keannu125 2023-04-08 14:29:34 +08:00
parent c597e9eaab
commit 11a22403da

View file

@ -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,
}, },
@ -54,8 +58,8 @@ export function UpdateNote(note: UpdateNoteParams) {
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,
}, },
@ -71,8 +75,8 @@ export function AddNote(note: AddNoteParams) {
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,
}, },
@ -86,8 +90,8 @@ 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); console.log(response.data);
return true; return true;
@ -99,8 +103,8 @@ export function UserRegister(register: RegistrationParams) {
} }
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( console.log(
@ -117,8 +121,8 @@ export function UserLogin(user: LoginParams) {
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,
}, },
@ -130,8 +134,8 @@ export function UserInfo() {
} }
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"); console.log("Activation Success");
return true; return true;