feat(02-02): add DELETE /api/logs endpoint to backend
- DELETE /api/logs accepts user_id, program_exercise_id, date, set_number in request body - Deletes matching workout_logs row by composite key - Returns 200 + deleted id on success, 404 if row not found - Consistent with existing POST /api/logs (no auth middleware, user_id from body)
This commit is contained in:
@@ -328,6 +328,27 @@ app.post('/api/logs', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Delete a specific set log
|
||||||
|
app.delete('/api/logs', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { user_id, program_exercise_id, date, set_number } = req.body;
|
||||||
|
|
||||||
|
const result = await pool.query(
|
||||||
|
'DELETE FROM workout_logs WHERE user_id = $1 AND program_exercise_id = $2 AND date = $3 AND set_number = $4 RETURNING id',
|
||||||
|
[user_id, program_exercise_id, date, set_number]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.rows.length === 0) {
|
||||||
|
return res.status(404).json({ error: 'Log not found' });
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({ deleted: result.rows[0].id });
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error deleting log:', err);
|
||||||
|
res.status(500).json({ error: 'Database error' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Calculate suggested weight based on progression
|
// Calculate suggested weight based on progression
|
||||||
app.get('/api/progression/:programExerciseId', async (req, res) => {
|
app.get('/api/progression/:programExerciseId', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user