Compare commits
10 Commits
v1.1
...
d5296bd3fa
Author | SHA1 | Date | |
---|---|---|---|
d5296bd3fa | |||
3ee2f6b670 | |||
09af4c760c | |||
3fd0fd9584 | |||
27984ebac8 | |||
3d4aab74d5 | |||
4076630eec | |||
6025212e93 | |||
de554048eb | |||
e1d79d2c79 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -112,5 +112,3 @@ backend/public/uploads/
|
|||||||
config/
|
config/
|
||||||
secrets/
|
secrets/
|
||||||
keys/
|
keys/
|
||||||
|
|
||||||
ToDo.txt
|
|
11
Docs/HELP.md
11
Docs/HELP.md
@@ -1,11 +0,0 @@
|
|||||||
# Hilfe Seite
|
|
||||||
|
|
||||||
Hier finden Sie Informationen zur Verwendung des Systems.
|
|
||||||
|
|
||||||
## Unerwartete Probleme
|
|
||||||
|
|
||||||
Falls unerwartetet Probleme im Web oder im Safe auftreten sollten, können Sie den Support via Teams kontaktieren.
|
|
||||||
|
|
||||||
**Kontaktpersonen:**
|
|
||||||
- Theis Gaedigk (Web & Safe)
|
|
||||||
- Niklas Brunke (Safe)
|
|
@@ -8,7 +8,7 @@ On this page you will learn how my API works.
|
|||||||
|
|
||||||
When you look at my backend folder and file structure, you can see that I have two files called `API`. The first file called `api.js` is for my web frontend, because this file works together with my JWT token service.
|
When you look at my backend folder and file structure, you can see that I have two files called `API`. The first file called `api.js` is for my web frontend, because this file works together with my JWT token service.
|
||||||
|
|
||||||
**\*But I have built a second API. You can see the second API file in the same directory, the file is called `apiV2.js`.**
|
But I have built a second API. You can see the second API file in the same directory, the file is called `apiV2.js`.
|
||||||
|
|
||||||
This is the file that you can use to build an API.
|
This is the file that you can use to build an API.
|
||||||
|
|
||||||
@@ -45,114 +45,21 @@ Returns a list of all items and their details.
|
|||||||
#### Example Request
|
#### Example Request
|
||||||
|
|
||||||
```
|
```
|
||||||
GET https://backend.insta.the1s.de/apiV2/items/your_admin_key
|
GET /apiV2/items/your_admin_key
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Example Response
|
#### Example Response
|
||||||
|
|
||||||
```
|
```
|
||||||
{
|
[
|
||||||
"data": [
|
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"item_name": "DJI 1er Mikro",
|
"item_name": "DJI 1er Mikro",
|
||||||
"can_borrow_role": 4,
|
"can_borrow_role": "4",
|
||||||
"inSafe": 1,
|
"inSafe": 1
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
},
|
||||||
{
|
...
|
||||||
"id": 2,
|
]
|
||||||
"item_name": "DJI 2er Mikro 1",
|
|
||||||
"can_borrow_role": 4,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 3,
|
|
||||||
"item_name": "DJI 2er Mikro 2",
|
|
||||||
"can_borrow_role": 4,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 4,
|
|
||||||
"item_name": "Rode Richt Mikrofon",
|
|
||||||
"can_borrow_role": 2,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 5,
|
|
||||||
"item_name": "Kamera Stativ",
|
|
||||||
"can_borrow_role": 1,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 6,
|
|
||||||
"item_name": "SONY Kamera - inkl. Akkus und Objektiv",
|
|
||||||
"can_borrow_role": 1,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 7,
|
|
||||||
"item_name": "MacBook inkl. Adapter",
|
|
||||||
"can_borrow_role": 2,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 8,
|
|
||||||
"item_name": "SD Karten",
|
|
||||||
"can_borrow_role": 3,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 9,
|
|
||||||
"item_name": "Kameragimbal",
|
|
||||||
"can_borrow_role": 1,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 10,
|
|
||||||
"item_name": "ATEM MINI PRO",
|
|
||||||
"can_borrow_role": 1,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 11,
|
|
||||||
"item_name": "Handygimbal",
|
|
||||||
"can_borrow_role": 4,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 12,
|
|
||||||
"item_name": "Kameralfter",
|
|
||||||
"can_borrow_role": 1,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 13,
|
|
||||||
"item_name": "Kleine Kamera 1 - inkl. Objektiv",
|
|
||||||
"can_borrow_role": 2,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 14,
|
|
||||||
"item_name": "Kleine Kamera 2 - inkl. Objektiv",
|
|
||||||
"can_borrow_role": 2,
|
|
||||||
"inSafe": 1,
|
|
||||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Each item has the following properties:
|
Each item has the following properties:
|
||||||
@@ -162,8 +69,6 @@ Each item has the following properties:
|
|||||||
- `can_borrow_role`: The role ID that is allowed to borrow the item.
|
- `can_borrow_role`: The role ID that is allowed to borrow the item.
|
||||||
- `inSafe`: Indicates whether the item is currently in the locker (1) or not (0). This variable/state can change over time.
|
- `inSafe`: Indicates whether the item is currently in the locker (1) or not (0). This variable/state can change over time.
|
||||||
|
|
||||||
_You also get an http 200 status code._
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### 2. Change Item Safe State
|
### 2. Change Item Safe State
|
||||||
@@ -177,59 +82,7 @@ Updates the `inSafe` state of an item (whether it is in the locker).
|
|||||||
#### Example Request
|
#### Example Request
|
||||||
|
|
||||||
```
|
```
|
||||||
POST https://backend.insta.the1s.de/apiV2/controlInSafe/your_admin_key/item_id/new_item_state
|
POST /apiV2/controlInSafe/your_admin_key/5/0
|
||||||
```
|
|
||||||
|
|
||||||
#### Example Response
|
|
||||||
|
|
||||||
```
|
|
||||||
{}
|
|
||||||
```
|
|
||||||
|
|
||||||
_An empty object means, that the operation was successful and no further information is returned._
|
|
||||||
|
|
||||||
_You also get an http 200 status code._
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 3. Set Return Date
|
|
||||||
|
|
||||||
**POST** `/apiV2/setReturnDate/:key/:loan_code`
|
|
||||||
|
|
||||||
Sets the `returned_date` of a loan to the current server time.
|
|
||||||
|
|
||||||
- `loan_code`: The unique code of the loan.
|
|
||||||
|
|
||||||
#### Example Request
|
|
||||||
|
|
||||||
```
|
|
||||||
POST https://backend.insta.the1s.de/apiV2/setReturnDate/your_admin_key/your_loan_code
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Example Response
|
|
||||||
|
|
||||||
```
|
|
||||||
{}
|
|
||||||
```
|
|
||||||
|
|
||||||
_An empty object means, that the operation was successful and no further information is returned._
|
|
||||||
|
|
||||||
_You also get an http 200 status code._
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 4. Set Take Date
|
|
||||||
|
|
||||||
**POST** `/apiV2/setTakeDate/:key/:loan_code`
|
|
||||||
|
|
||||||
Sets the `take_date` of a loan to the current server time.
|
|
||||||
|
|
||||||
- `loan_code`: The unique code of the loan.
|
|
||||||
|
|
||||||
#### Example Request
|
|
||||||
|
|
||||||
```
|
|
||||||
POST https://backend.insta.the1s.de/apiV2/setTakeDate/your_admin_key/your_loan_code
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Example Response
|
#### Example Response
|
||||||
@@ -244,55 +97,56 @@ _You also get an http 2xx status code._
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### 5. Get whole loan by loan code
|
### 3. Set Return Date
|
||||||
|
|
||||||
**POST** `/getLoanByCode/:key/:loan_code`
|
**POST** `/apiV2/setReturnDate/:key/:loan_code`
|
||||||
|
|
||||||
Retrieves the details of a specific loan by its unique code.
|
Sets the `returned_date` of a loan to the current server time.
|
||||||
|
|
||||||
- `loan_code`: The unique code of the loan.
|
- `loan_code`: The unique code of the loan.
|
||||||
|
|
||||||
#### Example Request
|
#### Example Request
|
||||||
|
|
||||||
```
|
```
|
||||||
GET https://backend.insta.the1s.de/getLoanByCode/your_admin_key/your_loan_code
|
POST /apiV2/setReturnDate/your_admin_key/123456
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Example Response
|
#### Example Response
|
||||||
|
|
||||||
```
|
```
|
||||||
{
|
{}
|
||||||
"data": {
|
|
||||||
"id": 6,
|
|
||||||
"username": "theis",
|
|
||||||
"loan_code": 646473,
|
|
||||||
"start_date": "2025-08-25T13:23:00.000Z",
|
|
||||||
"end_date": "2025-08-26T13:23:00.000Z",
|
|
||||||
"take_date": null,
|
|
||||||
"returned_date": null,
|
|
||||||
"created_at": "2025-08-20T11:23:40.000Z",
|
|
||||||
"loaned_items_id": [
|
|
||||||
8,
|
|
||||||
9
|
|
||||||
],
|
|
||||||
"loaned_items_name": [
|
|
||||||
"SD Karten",
|
|
||||||
"Kameragimbal"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
_You also get an http 200 status code._
|
_An empty object means, that the operation was successful and no further information is returned._
|
||||||
|
|
||||||
If the loan id does not exist, you will receive a 404 status code and an error message.
|
_You also get an http 2xx status code._
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4. Set Take Date
|
||||||
|
|
||||||
|
**POST** `/apiV2/setTakeDate/:key/:loan_code`
|
||||||
|
|
||||||
|
Sets the `take_date` of a loan to the current server time.
|
||||||
|
|
||||||
|
- `loan_code`: The unique code of the loan.
|
||||||
|
|
||||||
|
#### Example Request
|
||||||
|
|
||||||
```
|
```
|
||||||
{
|
POST /apiV2/setTakeDate/your_admin_key/123456
|
||||||
"message": "Loan not found"
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Example Response
|
||||||
|
|
||||||
|
```
|
||||||
|
{}
|
||||||
|
```
|
||||||
|
|
||||||
|
_An empty object means, that the operation was successful and no further information is returned._
|
||||||
|
|
||||||
|
_You also get an http 2xx status code._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Error Handling
|
## Error Handling
|
||||||
|
@@ -7,6 +7,6 @@ RUN npm install
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
EXPOSE 8002
|
EXPOSE 8102
|
||||||
|
|
||||||
CMD ["npm", "start"]
|
CMD ["npm", "start"]
|
@@ -11,6 +11,7 @@ import {
|
|||||||
import { authenticate, generateToken } from "../services/tokenService.js";
|
import { authenticate, generateToken } from "../services/tokenService.js";
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
|
// Example endpoint
|
||||||
router.post("/login", async (req, res) => {
|
router.post("/login", async (req, res) => {
|
||||||
const result = await loginFunc(req.body.username, req.body.password);
|
const result = await loginFunc(req.body.username, req.body.password);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
@@ -5,7 +5,6 @@ import {
|
|||||||
changeInSafeStateV2,
|
changeInSafeStateV2,
|
||||||
setReturnDateV2,
|
setReturnDateV2,
|
||||||
setTakeDateV2,
|
setTakeDateV2,
|
||||||
getLoanByCodeV2,
|
|
||||||
} from "../services/database.js";
|
} from "../services/database.js";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
@@ -45,19 +44,6 @@ router.post("/controlInSafe/:key/:itemId/:state", async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/getLoanByCode/:key/:loan_code", async (req, res) => {
|
|
||||||
if (req.params.key === process.env.ADMIN_ID) {
|
|
||||||
const loan_code = req.params.loan_code;
|
|
||||||
|
|
||||||
const result = await getLoanByCodeV2(loan_code);
|
|
||||||
if (result.success) {
|
|
||||||
res.status(200).json({ data: result.data });
|
|
||||||
} else {
|
|
||||||
res.status(404).json({ message: "Loan not found" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Route for API to set the return date
|
// Route for API to set the return date
|
||||||
router.post("/setReturnDate/:key/:loan_code", async (req, res) => {
|
router.post("/setReturnDate/:key/:loan_code", async (req, res) => {
|
||||||
if (req.params.key === process.env.ADMIN_ID) {
|
if (req.params.key === process.env.ADMIN_ID) {
|
||||||
|
@@ -5,7 +5,7 @@ import apiRouter from "./routes/api.js";
|
|||||||
import apiRouterV2 from "./routes/apiV2.js";
|
import apiRouterV2 from "./routes/apiV2.js";
|
||||||
env.config();
|
env.config();
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 8002;
|
const port = 8102;
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
// Increase body size limits to support large CSV JSON payloads
|
// Increase body size limits to support large CSV JSON payloads
|
||||||
|
@@ -8,6 +8,7 @@ const pool = mysql
|
|||||||
user: process.env.DB_USER,
|
user: process.env.DB_USER,
|
||||||
password: process.env.DB_PASSWORD,
|
password: process.env.DB_PASSWORD,
|
||||||
database: process.env.DB_NAME,
|
database: process.env.DB_NAME,
|
||||||
|
port: process.env.DB_PORT,
|
||||||
})
|
})
|
||||||
.promise();
|
.promise();
|
||||||
|
|
||||||
@@ -28,17 +29,6 @@ export const getItemsFromDatabaseV2 = async () => {
|
|||||||
return { success: false };
|
return { success: false };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getLoanByCodeV2 = async (loan_code) => {
|
|
||||||
const [result] = await pool.query(
|
|
||||||
"SELECT * FROM loans WHERE loan_code = ?;",
|
|
||||||
[loan_code]
|
|
||||||
);
|
|
||||||
if (result.length > 0) {
|
|
||||||
return { success: true, data: result[0] };
|
|
||||||
}
|
|
||||||
return { success: false };
|
|
||||||
};
|
|
||||||
|
|
||||||
export const changeInSafeStateV2 = async (itemId, state) => {
|
export const changeInSafeStateV2 = async (itemId, state) => {
|
||||||
const [result] = await pool.query(
|
const [result] = await pool.query(
|
||||||
"UPDATE items SET inSafe = ? WHERE id = ?",
|
"UPDATE items SET inSafe = ? WHERE id = ?",
|
||||||
|
@@ -1,23 +1,30 @@
|
|||||||
services:
|
services:
|
||||||
# borrow_system-frontend:
|
borrow_system-frontend:
|
||||||
# container_name: borrow_system-frontend
|
container_name: borrow_system-frontend
|
||||||
# build: ./frontend
|
build: ./frontend
|
||||||
# ports:
|
ports:
|
||||||
# - "8001:8001"
|
- "8101:8101"
|
||||||
# environment:
|
networks:
|
||||||
# - CHOKIDAR_USEPOLLING=true
|
- proxynet
|
||||||
# volumes:
|
- borrow_system-internal
|
||||||
# - ./frontend:/app
|
environment:
|
||||||
# - /app/node_modules
|
- CHOKIDAR_USEPOLLING=true
|
||||||
# restart: unless-stopped
|
volumes:
|
||||||
|
- ./frontend:/app
|
||||||
|
- /app/node_modules
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
borrow_system-backend:
|
borrow_system-backend:
|
||||||
container_name: borrow_system-backend
|
container_name: borrow_system-backend
|
||||||
build: ./backend
|
build: ./backend
|
||||||
ports:
|
ports:
|
||||||
- "8002:8002"
|
- "8102:8102"
|
||||||
|
networks:
|
||||||
|
- proxynet
|
||||||
|
- borrow_system-internal
|
||||||
environment:
|
environment:
|
||||||
DB_HOST: mysql
|
DB_HOST: mysql
|
||||||
|
DB_PORT: 3306
|
||||||
DB_USER: root
|
DB_USER: root
|
||||||
DB_PASSWORD: ${DB_PASSWORD}
|
DB_PASSWORD: ${DB_PASSWORD}
|
||||||
DB_NAME: borrow_system
|
DB_NAME: borrow_system
|
||||||
@@ -38,6 +45,14 @@ services:
|
|||||||
- mysql-data:/var/lib/mysql
|
- mysql-data:/var/lib/mysql
|
||||||
ports:
|
ports:
|
||||||
- "3309:3306"
|
- "3309:3306"
|
||||||
|
networks:
|
||||||
|
- borrow_system-internal
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
mysql-data:
|
mysql-data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
proxynet:
|
||||||
|
external: true
|
||||||
|
borrow_system-internal:
|
||||||
|
external: false
|
||||||
|
@@ -7,6 +7,6 @@ RUN npm install
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
EXPOSE 8001
|
EXPOSE 8101
|
||||||
|
|
||||||
CMD ["npm", "run", "dev"]
|
CMD ["npm", "run", "dev"]
|
@@ -6,11 +6,7 @@ import Form2 from "./components/Form2";
|
|||||||
import Form4 from "./components/Form4";
|
import Form4 from "./components/Form4";
|
||||||
import LoginForm from "./components/LoginForm";
|
import LoginForm from "./components/LoginForm";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import {
|
import { fetchAllData, ALL_ITEMS_UPDATED_EVENT } from "./utils/fetchData";
|
||||||
fetchAllData,
|
|
||||||
ALL_ITEMS_UPDATED_EVENT,
|
|
||||||
AUTH_LOGOUT_EVENT,
|
|
||||||
} from "./utils/fetchData";
|
|
||||||
import { myToast } from "./utils/toastify";
|
import { myToast } from "./utils/toastify";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
@@ -22,15 +18,8 @@ function App() {
|
|||||||
setIsLoggedIn(true);
|
setIsLoggedIn(true);
|
||||||
fetchAllData(token);
|
fetchAllData(token);
|
||||||
}
|
}
|
||||||
localStorage.setItem("borrowableItems", JSON.stringify([]));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
localStorage.setItem("borrowableItems", JSON.stringify([]));
|
||||||
const onAuthLogout = () => {
|
|
||||||
setIsLoggedIn(false);
|
|
||||||
};
|
|
||||||
window.addEventListener(AUTH_LOGOUT_EVENT, onAuthLogout);
|
|
||||||
return () => window.removeEventListener(AUTH_LOGOUT_EVENT, onAuthLogout);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleLogout = () => {
|
const handleLogout = () => {
|
||||||
|
@@ -1,12 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
|
|
||||||
const Footer: React.FC = () => {
|
|
||||||
return (
|
|
||||||
<footer className="fixed bottom-0 left-0 text-sm w-full bg-slate-100 text-center py-2 border-t border-slate-200 z-50">
|
|
||||||
<p>Made with ❤️ by Theis Gaedigk - Jahrgang 2019</p>
|
|
||||||
<p>v1.1</p>
|
|
||||||
</footer>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Footer;
|
|
@@ -23,16 +23,6 @@ const Header: React.FC<HeaderProps> = ({ onLogout }) => {
|
|||||||
>
|
>
|
||||||
Logout
|
Logout
|
||||||
</button>
|
</button>
|
||||||
<a href="https://git.the1s.de/Matthias-Claudius-Schule/borrow-system/src/branch/dev/Docs/HELP.md">
|
|
||||||
<button className="h-9 px-3 rounded-md border border-slate-300 text-slate-700 hover:bg-slate-100 transition">
|
|
||||||
Hilfe
|
|
||||||
</button>
|
|
||||||
</a>
|
|
||||||
<a href="https://git.the1s.de/Matthias-Claudius-Schule/borrow-system">
|
|
||||||
<button className="h-9 px-3 rounded-md border border-slate-300 text-slate-700 hover:bg-slate-100 transition">
|
|
||||||
Source Code
|
|
||||||
</button>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
);
|
);
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import Footer from "./Footer";
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { loginUser } from "../utils/fetchData";
|
import { loginUser } from "../utils/fetchData";
|
||||||
import { myToast } from "../utils/toastify";
|
import { myToast } from "../utils/toastify";
|
||||||
@@ -67,7 +66,6 @@ const LoginForm: React.FC<LoginFormProps> = ({ onLogin }) => {
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<Footer />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -70,9 +70,7 @@ const Sidebar: React.FC = () => {
|
|||||||
<Object
|
<Object
|
||||||
title={item.item_name}
|
title={item.item_name}
|
||||||
description={
|
description={
|
||||||
item.inSafe
|
item.inSafe ? "Im Schließfach" : "Nicht im Schließfach"
|
||||||
? "Aktuell im Schließfach"
|
|
||||||
: "Aktuell nicht im Schließfach"
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -83,7 +81,7 @@ const Sidebar: React.FC = () => {
|
|||||||
<div className="mt-4 pt-3 border-t border-slate-200/70 text-[10px] sm:text-xs text-slate-500 items-center gap-4 hidden md:flex">
|
<div className="mt-4 pt-3 border-t border-slate-200/70 text-[10px] sm:text-xs text-slate-500 items-center gap-4 hidden md:flex">
|
||||||
<span className="inline-flex items-center gap-1">
|
<span className="inline-flex items-center gap-1">
|
||||||
<span className="inline-block w-3 h-3 bg-emerald-500 rounded-full ring-2 ring-white shadow-sm"></span>
|
<span className="inline-block w-3 h-3 bg-emerald-500 rounded-full ring-2 ring-white shadow-sm"></span>
|
||||||
Im Schließfach
|
Verfügbar
|
||||||
</span>
|
</span>
|
||||||
<span className="inline-flex items-center gap-1">
|
<span className="inline-flex items-center gap-1">
|
||||||
<span className="inline-block w-3 h-3 bg-red-500 rounded-full ring-2 ring-white shadow-sm"></span>
|
<span className="inline-block w-3 h-3 bg-red-500 rounded-full ring-2 ring-white shadow-sm"></span>
|
||||||
|
@@ -2,7 +2,6 @@ import React from "react";
|
|||||||
import "../App.css";
|
import "../App.css";
|
||||||
import Header from "../components/Header";
|
import Header from "../components/Header";
|
||||||
import Sidebar from "../components/Sidebar";
|
import Sidebar from "../components/Sidebar";
|
||||||
import Footer from "../components/Footer";
|
|
||||||
|
|
||||||
type LayoutProps = {
|
type LayoutProps = {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@@ -11,13 +10,15 @@ type LayoutProps = {
|
|||||||
|
|
||||||
const Layout: React.FC<LayoutProps> = ({ children, onLogout }) => {
|
const Layout: React.FC<LayoutProps> = ({ children, onLogout }) => {
|
||||||
return (
|
return (
|
||||||
<div className="h-screen flex flex-col bg-slate-50 text-slate-800">
|
<div className="h-screen overflow-hidden flex bg-slate-50 text-slate-800">
|
||||||
{/* Main */}
|
{/* Main */}
|
||||||
<main className="flex-1 min-h-0 overflow-hidden flex flex-col items-center px-3 sm:px-5 py-4 sm:py-8 pb-12">
|
<main className="flex-1 min-h-0 overflow-hidden flex flex-col items-center px-3 sm:px-5 py-4 sm:py-8">
|
||||||
|
{/* Sidebar on mobile appears inline on top; on desktop it's a sticky column */}
|
||||||
<div className="w-full max-w-5xl flex flex-col gap-3 md:flex-row md:gap-6 md:items-stretch min-h-0 h-full">
|
<div className="w-full max-w-5xl flex flex-col gap-3 md:flex-row md:gap-6 md:items-stretch min-h-0 h-full">
|
||||||
<div className="hidden md:flex md:flex-col md:shrink-0 md:w-72 md:min-h-0 md:h-full">
|
<div className="hidden md:flex md:flex-col md:shrink-0 md:w-72 md:min-h-0 md:h-full">
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex-1 min-w-0 min-h-0 h-full flex flex-col overflow-hidden">
|
<div className="flex-1 min-w-0 min-h-0 h-full flex flex-col overflow-hidden">
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<Header onLogout={onLogout} />
|
<Header onLogout={onLogout} />
|
||||||
@@ -28,7 +29,6 @@ const Layout: React.FC<LayoutProps> = ({ children, onLogout }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
<Footer />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -2,7 +2,7 @@ import { StrictMode } from "react";
|
|||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import App from "./App.tsx";
|
import App from "./App.tsx";
|
||||||
import { ToastContainer, Flip } from "react-toastify";
|
import { ToastContainer } from "react-toastify";
|
||||||
import "react-toastify/dist/ReactToastify.css";
|
import "react-toastify/dist/ReactToastify.css";
|
||||||
import { QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClientProvider } from "@tanstack/react-query";
|
||||||
import { queryClient } from "./utils/queryClient";
|
import { queryClient } from "./utils/queryClient";
|
||||||
@@ -18,11 +18,11 @@ createRoot(document.getElementById("root")!).render(
|
|||||||
newestOnTop
|
newestOnTop
|
||||||
closeOnClick
|
closeOnClick
|
||||||
rtl={false}
|
rtl={false}
|
||||||
pauseOnFocusLoss
|
pauseOnFocusLoss={false}
|
||||||
draggable
|
draggable
|
||||||
pauseOnHover
|
pauseOnHover
|
||||||
theme="colored"
|
theme="colored"
|
||||||
transition={Flip}
|
style={{ zIndex: 9999 }}
|
||||||
/>
|
/>
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
</StrictMode>
|
</StrictMode>
|
||||||
|
@@ -4,44 +4,18 @@ import { myToast } from "./toastify";
|
|||||||
// Event name used to notify the app when the list of items has been updated
|
// Event name used to notify the app when the list of items has been updated
|
||||||
export const ALL_ITEMS_UPDATED_EVENT = "allItemsUpdated";
|
export const ALL_ITEMS_UPDATED_EVENT = "allItemsUpdated";
|
||||||
export const BORROWABLE_ITEMS_UPDATED_EVENT = "borrowableItemsUpdated";
|
export const BORROWABLE_ITEMS_UPDATED_EVENT = "borrowableItemsUpdated";
|
||||||
export const AUTH_LOGOUT_EVENT = "authLogout";
|
|
||||||
|
|
||||||
let sendError = false;
|
|
||||||
|
|
||||||
function logout() {
|
|
||||||
Cookies.remove("token");
|
|
||||||
Cookies.remove("startDate");
|
|
||||||
Cookies.remove("endDate");
|
|
||||||
localStorage.removeItem("allItems");
|
|
||||||
localStorage.removeItem("allLoans");
|
|
||||||
localStorage.removeItem("userLoans");
|
|
||||||
localStorage.removeItem("borrowableItems");
|
|
||||||
window.dispatchEvent(new Event(ALL_ITEMS_UPDATED_EVENT));
|
|
||||||
window.dispatchEvent(new Event(BORROWABLE_ITEMS_UPDATED_EVENT));
|
|
||||||
window.dispatchEvent(new Event(AUTH_LOGOUT_EVENT));
|
|
||||||
}
|
|
||||||
|
|
||||||
export const fetchAllData = async (token: string | undefined) => {
|
export const fetchAllData = async (token: string | undefined) => {
|
||||||
if (!token) return;
|
if (!token) return;
|
||||||
// First we fetch all items that are potentially available for borrowing
|
// First we fetch all items that are potentially available for borrowing
|
||||||
try {
|
try {
|
||||||
const response = await fetch("http://localhost:8002/api/items", {
|
const response = await fetch("https://backend.insta.the1s.de/api/items", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.status === 500) {
|
|
||||||
if (!sendError) {
|
|
||||||
sendError = true;
|
|
||||||
myToast("Session expired. Please log in again.", "error");
|
|
||||||
logout();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
myToast("Failed to fetch items", "error");
|
myToast("Failed to fetch items", "error");
|
||||||
return;
|
return;
|
||||||
@@ -57,23 +31,13 @@ export const fetchAllData = async (token: string | undefined) => {
|
|||||||
|
|
||||||
// get all loans
|
// get all loans
|
||||||
try {
|
try {
|
||||||
const response = await fetch("http://localhost:8002/api/loans", {
|
const response = await fetch("https://backend.insta.the1s.de/api/loans", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.status === 500) {
|
|
||||||
if (!sendError) {
|
|
||||||
sendError = true;
|
|
||||||
myToast("Session expired. Please log in again.", "error");
|
|
||||||
logout();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
myToast("Failed to fetch loans!", "error");
|
myToast("Failed to fetch loans!", "error");
|
||||||
return;
|
return;
|
||||||
@@ -89,23 +53,13 @@ export const fetchAllData = async (token: string | undefined) => {
|
|||||||
|
|
||||||
// get user loans
|
// get user loans
|
||||||
try {
|
try {
|
||||||
const response = await fetch("http://localhost:8002/api/userLoans", {
|
const response = await fetch("https://backend.insta.the1s.de/api/userLoans", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.status === 500) {
|
|
||||||
if (!sendError) {
|
|
||||||
sendError = true;
|
|
||||||
myToast("Session expired. Please log in again.", "error");
|
|
||||||
logout();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
myToast("Failed to fetch user loans!", "error");
|
myToast("Failed to fetch user loans!", "error");
|
||||||
return;
|
return;
|
||||||
@@ -122,7 +76,7 @@ export const fetchAllData = async (token: string | undefined) => {
|
|||||||
|
|
||||||
export const loginUser = async (username: string, password: string) => {
|
export const loginUser = async (username: string, password: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("http://localhost:8002/api/login", {
|
const response = await fetch("https://backend.insta.the1s.de/api/login", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -158,7 +112,7 @@ export const getBorrowableItems = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("http://localhost:8002/api/borrowableItems", {
|
const response = await fetch("https://backend.insta.the1s.de/api/borrowableItems", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${Cookies.get("token") || ""}`,
|
Authorization: `Bearer ${Cookies.get("token") || ""}`,
|
||||||
@@ -168,16 +122,6 @@ export const getBorrowableItems = async () => {
|
|||||||
body: JSON.stringify({ startDate, endDate }),
|
body: JSON.stringify({ startDate, endDate }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.status === 500) {
|
|
||||||
if (!sendError) {
|
|
||||||
sendError = true;
|
|
||||||
myToast("Session expired. Please log in again.", "error");
|
|
||||||
logout();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
myToast("Failed to fetch borrowable items", "error");
|
myToast("Failed to fetch borrowable items", "error");
|
||||||
return;
|
return;
|
||||||
|
@@ -1,18 +1,17 @@
|
|||||||
import { toast, Flip, type ToastOptions } from "react-toastify";
|
import { toast, type ToastOptions } from "react-toastify";
|
||||||
|
|
||||||
export type ToastType = "success" | "error" | "info" | "warning";
|
export type ToastType = "success" | "error" | "info" | "warning";
|
||||||
|
|
||||||
export const myToast = (message: string, msgType: ToastType) => {
|
export const myToast = (message: string, msgType: ToastType) => {
|
||||||
let config: ToastOptions = {
|
let config: ToastOptions = {
|
||||||
position: "top-right",
|
position: "top-right",
|
||||||
autoClose: 3000,
|
autoClose: 5000,
|
||||||
hideProgressBar: false,
|
hideProgressBar: false,
|
||||||
closeOnClick: true,
|
closeOnClick: true,
|
||||||
pauseOnHover: true,
|
pauseOnHover: true,
|
||||||
draggable: true,
|
draggable: true,
|
||||||
progress: undefined,
|
progress: undefined,
|
||||||
theme: "colored",
|
theme: "light",
|
||||||
transition: Flip,
|
|
||||||
};
|
};
|
||||||
toast[msgType](message, config);
|
toast[msgType](message, config);
|
||||||
};
|
};
|
||||||
|
@@ -5,7 +5,7 @@ import { queryClient } from "./queryClient";
|
|||||||
export const handleDeleteLoan = async (loanID: number): Promise<boolean> => {
|
export const handleDeleteLoan = async (loanID: number): Promise<boolean> => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`http://localhost:8002/api/deleteLoan/${loanID}`,
|
`https://backend.insta.the1s.de/api/deleteLoan/${loanID}`,
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -75,7 +75,7 @@ export const rmFromRemove = (itemID: number) => {
|
|||||||
|
|
||||||
export const createLoan = async (startDate: string, endDate: string) => {
|
export const createLoan = async (startDate: string, endDate: string) => {
|
||||||
const items = removeArr;
|
const items = removeArr;
|
||||||
const response = await fetch("http://localhost:8002/api/createLoan", {
|
const response = await fetch("https://backend.insta.the1s.de/api/createLoan", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
@@ -1,15 +1,17 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import react from "@vitejs/plugin-react";
|
|
||||||
import svgr from "vite-plugin-svgr";
|
|
||||||
import tailwindcss from "@tailwindcss/vite";
|
import tailwindcss from "@tailwindcss/vite";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react(), svgr(), tailwindcss()],
|
plugins: [tailwindcss()],
|
||||||
server: {
|
server: {
|
||||||
host: "0.0.0.0",
|
host: "0.0.0.0",
|
||||||
port: 8001,
|
allowedHosts: ["insta.the1s.de"],
|
||||||
watch: {
|
port: 8101,
|
||||||
usePolling: true,
|
watch: { usePolling: true },
|
||||||
|
hmr: {
|
||||||
|
host: "insta.the1s.de",
|
||||||
|
port: 8101,
|
||||||
|
protocol: "wss",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user