@@ -7,14 +7,14 @@ import { generateRandomMockInventoryDetails } from "@/mocks/Inventory_Details_In
77import { generateMockMember } from "@/mocks/Members_Details_Interface_Mocks" ;
88
99// tha main URL
10- export const BASE_URL = "http://localhost:8000/api/activities /" ;
10+ export const BASE_INVENTORY_URL = "http://localhost:8000/api/inventory /" ;
1111
1212// change when backend is ready
13- const isDev : boolean = true ;
13+ const isDev : boolean = false ;
1414
1515// --- GET: Fetch all items ---
1616export const getItems = async (
17- filterType : string ,
17+ URL : string ,
1818) : Promise < Inventory_Details_Interface [ ] > => {
1919 if ( isDev ) {
2020 // Mock data for development
@@ -27,7 +27,8 @@ export const getItems = async (
2727 } else {
2828 // 1. Fetch from Django
2929 // fetch() is used to get the data from backend using URL
30- const response = await fetch ( `${ BASE_URL } ?type=${ filterType } ` ) ;
30+ // `${}` is place holders for code, anything inside the curly braces is code
31+ const response = await fetch ( `${ URL } ` ) ;
3132
3233 // 2. Check if the request was successful
3334 if ( ! response . ok ) throw new Error ( "Failed to fetch" ) ;
@@ -53,7 +54,7 @@ export const createItem = async (
5354 console . log ( "Mock create item called with data:" , newData ) ;
5455 return true ; // Simulate successful creation
5556 } else {
56- const response = await fetch ( BASE_URL , {
57+ const response = await fetch ( BASE_INVENTORY_URL , {
5758 method : "POST" ,
5859 headers : { "Content-Type" : "application/json" } ,
5960 body : JSON . stringify ( newData ) ,
@@ -70,7 +71,7 @@ export const updateItem = async (
7071 newData : Inventory_Details_Interface ,
7172) => {
7273 // Django usually expects a trailing slash after the ID
73- const response = await fetch ( `${ BASE_URL } ${ id } /` , {
74+ const response = await fetch ( `${ BASE_INVENTORY_URL } ${ id } /` , {
7475 method : "PATCH" ,
7576 headers : { "Content-Type" : "application/json" } ,
7677 body : JSON . stringify ( newData ) ,
@@ -80,7 +81,7 @@ export const updateItem = async (
8081
8182// --- DELETE: Remove an item ---
8283export const deleteItem = async ( id : number ) => {
83- const response = await fetch ( `${ BASE_URL } ${ id } /` , {
84+ const response = await fetch ( `${ BASE_INVENTORY_URL } ${ id } /` , {
8485 method : "DELETE" ,
8586 } ) ;
8687 // DELETE usually returns a 204 No Content status, so we don't always .json() it
@@ -103,7 +104,7 @@ export const getMembers = async (
103104 } else {
104105 // 1. Fetch from Django
105106 // fetch() is used to get the data from backend using URL
106- const response = await fetch ( `${ BASE_URL } ?type=${ filterType } ` ) ;
107+ const response = await fetch ( `${ BASE_INVENTORY_URL } ?type=${ filterType } ` ) ;
107108
108109 // 2. Check if the request was successful
109110 if ( ! response . ok ) throw new Error ( "Failed to fetch" ) ;
@@ -124,7 +125,7 @@ export const createMember = async (
124125 console . log ( "Mock create Member called with data:" , newData ) ;
125126 return true ; // Simulate successful creation
126127 } else {
127- const response = await fetch ( BASE_URL , {
128+ const response = await fetch ( BASE_INVENTORY_URL , {
128129 method : "POST" ,
129130 headers : { "Content-Type" : "application/json" } ,
130131 body : JSON . stringify ( newData ) ,
@@ -141,7 +142,7 @@ export const updateMember = async (
141142 newData : Member_Details_Interface ,
142143) => {
143144 // Django usually expects a trailing slash after the ID
144- const response = await fetch ( `${ BASE_URL } ${ id } /` , {
145+ const response = await fetch ( `${ BASE_INVENTORY_URL } ${ id } /` , {
145146 method : "PATCH" ,
146147 headers : { "Content-Type" : "application/json" } ,
147148 body : JSON . stringify ( newData ) ,
@@ -151,7 +152,7 @@ export const updateMember = async (
151152
152153// --- DELETE: Remove an Member ---
153154export const deleteMember = async ( id : number ) => {
154- const response = await fetch ( `${ BASE_URL } ${ id } /` , {
155+ const response = await fetch ( `${ BASE_INVENTORY_URL } ${ id } /` , {
155156 method : "DELETE" ,
156157 } ) ;
157158 // DELETE usually returns a 204 No Content status, so we don't always .json() it
0 commit comments