Commit 7cd34a85 by Sakilesh J

fix the json-server

parent c5835dbc
NEXT_PUBLIC_API_URL=http://192.168.1.161:4000/ NEXT_PUBLIC_API_URL=http://localhost:4000/
\ No newline at end of file \ No newline at end of file
{ {
"tasks": [ "tasks": [
{ {
"id": "1", "id": 1,
"task": "clg", "task": "clg",
"isCompleted": false "isCompleted": false
}, },
{ {
"id": "2", "id": 2,
"task": "new", "task": "new",
"isCompleted": true "isCompleted": true
}, },
{ {
"id": "3",
"task": "jake", "task": "jake",
"isCompleted": false "isCompleted": true,
"id": 3
}, },
{ {
"id": "4", "task": "items",
"task": "new", "isCompleted": false,
"isCompleted": true "id": 5
},
{
"task": "another items",
"isCompleted": false,
"id": 6
} }
] ]
} }
\ No newline at end of file
...@@ -3,11 +3,6 @@ import axios from "axios"; ...@@ -3,11 +3,6 @@ import axios from "axios";
export const Axios = axios.create( export const Axios = axios.create(
{ {
baseURL: SERVER_URL, baseURL: `${SERVER_URL}tasks/`,
timeout: 3000,
headers: {
"Content-Type": 'application/json',
Accept: 'application/json'
}
} }
) )
\ No newline at end of file
...@@ -3,10 +3,9 @@ import { Axios } from "./Instance"; ...@@ -3,10 +3,9 @@ import { Axios } from "./Instance";
export default async function AddTask(task: string) { export default async function AddTask(task: string) {
try { try {
const res = await Axios.post('tasks', { const res = await Axios.post('', {
task, isCompleted: false task, isCompleted: false
}) })
alert('Task added successfully')
return res.data return res.data
} catch (error) { } catch (error) {
alert("something went wrong") alert("something went wrong")
...@@ -19,7 +18,7 @@ export async function DeleteTask(id: number) { ...@@ -19,7 +18,7 @@ export async function DeleteTask(id: number) {
try { try {
const isDelete = confirm('Are you sure you want to delete'); const isDelete = confirm('Are you sure you want to delete');
if (isDelete) { if (isDelete) {
const res = await Axios.delete(`tasks/${id}`) const res = await Axios.delete(`${id}`)
return res.data return res.data
} }
} catch (error) { } catch (error) {
...@@ -30,7 +29,7 @@ export async function DeleteTask(id: number) { ...@@ -30,7 +29,7 @@ export async function DeleteTask(id: number) {
} }
export async function UpdateTask(id: number, task: string, isCompleted: boolean) { export async function UpdateTask(id: number, task: string, isCompleted: boolean) {
try { try {
const res = await Axios.put(`/tasks/${id}`, { const res = await Axios.put(`${id}`, {
task, isCompleted, id task, isCompleted, id
}) })
return res.data return res.data
......
...@@ -3,7 +3,7 @@ import { Axios } from "./Instance"; ...@@ -3,7 +3,7 @@ import { Axios } from "./Instance";
export default async function getall() { export default async function getall() {
try { try {
const res = await Axios.get('tasks'); const res = await Axios.get('');
return await res.data return await res.data
} catch (error) { } catch (error) {
console.log(error) console.log(error)
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
"autoprefixer": "^10.4.17", "autoprefixer": "^10.4.17",
"axios": "^1.7.2", "axios": "^1.7.2",
"classnames": "^2.5.1", "classnames": "^2.5.1",
"json-server": "^1.0.0-beta.0", "json-server": "^0.17.2",
"next": "^14.1.0", "next": "^14.1.0",
"postcss": "^8.4.33", "postcss": "^8.4.33",
"react": "^18.2.0", "react": "^18.2.0",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment