Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 99678ae1be | |||
| 4f3f9f842c | |||
| 9edfb87233 | |||
| 2d83276a27 |
@@ -30,13 +30,24 @@ app.use(express.json());
|
|||||||
// API ROUTEN
|
// API ROUTEN
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
|
|
||||||
|
// Root-Route zur Status-Überprüfung
|
||||||
|
app.get('/', (req, res) => {
|
||||||
|
res.json({
|
||||||
|
message: 'Appointment API Server läuft',
|
||||||
|
status: 'ok',
|
||||||
|
endpoints: {
|
||||||
|
appointments: '/api/appointments'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// 1. READ: Alle Termine abrufen (GET /api/appointments)
|
// 1. READ: Alle Termine abrufen (GET /api/appointments)
|
||||||
app.get('/api/appointments', async (req, res) => {
|
app.get('/api/appointments', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
// Finde alle Dokumente in der Collection 'appointments'
|
// Finde alle Dokumente in der Collection 'appointments', die nicht gelöscht sind
|
||||||
const appointments = await db.collection('appointments')
|
const appointments = await db.collection('appointments')
|
||||||
.find({})
|
.find({ deleted: { $ne: true } })
|
||||||
// Optional: Nach Termindatum sortieren (aufsteigend)
|
// Optional: Nach Termindatum sortieren (aufsteigend)
|
||||||
.sort({ termin: 1 })
|
.sort({ termin: 1 })
|
||||||
.toArray();
|
.toArray();
|
||||||
@@ -112,6 +123,7 @@ app.put('/api/appointments/:id', async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 4. DELETE: Termin löschen (DELETE /api/appointments/:id)
|
// 4. DELETE: Termin löschen (DELETE /api/appointments/:id)
|
||||||
|
// Soft Delete: Setzt das deleted-Flag statt den Eintrag zu löschen
|
||||||
app.delete('/api/appointments/:id', async (req, res) => {
|
app.delete('/api/appointments/:id', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
@@ -119,9 +131,13 @@ app.delete('/api/appointments/:id', async (req, res) => {
|
|||||||
|
|
||||||
const filter = { _id: new ObjectId(id) };
|
const filter = { _id: new ObjectId(id) };
|
||||||
|
|
||||||
const result = await db.collection('appointments').deleteOne(filter);
|
// Setze das deleted-Flag auf true statt den Eintrag zu löschen
|
||||||
|
const result = await db.collection('appointments').updateOne(
|
||||||
|
filter,
|
||||||
|
{ $set: { deleted: true, deletedAt: new Date() } }
|
||||||
|
);
|
||||||
|
|
||||||
if (result.deletedCount === 0) {
|
if (result.matchedCount === 0) {
|
||||||
return res.status(404).json({ message: "Termin nicht gefunden." });
|
return res.status(404).json({ message: "Termin nicht gefunden." });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ services:
|
|||||||
|
|
||||||
backend:
|
backend:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: ./backend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: backend
|
container_name: backend
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -29,14 +29,14 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- mongodb
|
- mongodb
|
||||||
volumes:
|
volumes:
|
||||||
- ./src:/app/src
|
- ./backend/src:/app/src
|
||||||
- ./package.json:/app/package.json
|
- ./backend/package.json:/app/package.json
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
build:
|
build:
|
||||||
context: ../frontend
|
context: ./frontend
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: frontend
|
container_name: frontend
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
@@ -45,8 +45,8 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
volumes:
|
volumes:
|
||||||
- ../frontend/src:/app/src
|
- ./frontend/src:/app/src
|
||||||
- ../frontend/package.json:/app/package.json
|
- ./frontend/package.json:/app/package.json
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
|
|
||||||
Reference in New Issue
Block a user