Implemented complete backend API foundation with authentication, document management, blog operations, and admin functionality. Added migration tools for database seeding and document import. **Controllers (4 files):** - auth.controller.js: User authentication (login, getCurrentUser, logout) - documents.controller.js: Document CRUD operations - blog.controller.js: Blog post management with admin/public access - admin.controller.js: Admin dashboard (stats, moderation queue, activity) **Routes (5 files):** - auth.routes.js: Authentication endpoints - documents.routes.js: Document API endpoints - blog.routes.js: Blog API endpoints - admin.routes.js: Admin API endpoints - index.js: Central routing configuration with API documentation **Migration Tools (2 scripts):** - seed-admin.js: Create admin user for system access - migrate-documents.js: Import markdown documents with metadata extraction, slug generation, and dry-run support. Successfully migrated 8 documents from anthropic-submission directory. **Server Updates:** - Integrated all API routes under /api namespace - Updated homepage to reflect completed API implementation - Maintained security middleware (Helmet, CORS, rate limiting) **Testing:** ✅ Server starts successfully on port 9000 ✅ Authentication flow working (login, token validation) ✅ Document endpoints tested (list, get by slug) ✅ Admin stats endpoint verified (requires authentication) ✅ Migration completed: 8 documents imported **Database Status:** - Documents collection: 8 technical papers - Users collection: 1 admin user - All indexes operational This completes the core backend API infrastructure. Next steps: build Tractatus governance services (InstructionClassifier, CrossReferenceValidator, BoundaryEnforcer). 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
80 lines
1.9 KiB
JavaScript
80 lines
1.9 KiB
JavaScript
/**
|
|
* Blog Routes
|
|
* AI-curated blog endpoints
|
|
*/
|
|
|
|
const express = require('express');
|
|
const router = express.Router();
|
|
|
|
const blogController = require('../controllers/blog.controller');
|
|
const { authenticateToken, requireRole } = require('../middleware/auth.middleware');
|
|
const { validateRequired, validateObjectId, validateSlug } = require('../middleware/validation.middleware');
|
|
const { asyncHandler } = require('../middleware/error.middleware');
|
|
|
|
/**
|
|
* Public routes
|
|
*/
|
|
|
|
// GET /api/blog - List published posts
|
|
router.get('/',
|
|
asyncHandler(blogController.listPublishedPosts)
|
|
);
|
|
|
|
// GET /api/blog/:slug - Get published post by slug
|
|
router.get('/:slug',
|
|
asyncHandler(blogController.getPublishedPost)
|
|
);
|
|
|
|
/**
|
|
* Admin routes
|
|
*/
|
|
|
|
// GET /api/blog/admin/posts?status=draft
|
|
router.get('/admin/posts',
|
|
authenticateToken,
|
|
requireRole('admin', 'moderator'),
|
|
asyncHandler(blogController.listPostsByStatus)
|
|
);
|
|
|
|
// GET /api/blog/admin/:id - Get any post by ID
|
|
router.get('/admin/:id',
|
|
authenticateToken,
|
|
requireRole('admin', 'moderator'),
|
|
validateObjectId('id'),
|
|
asyncHandler(blogController.getPostById)
|
|
);
|
|
|
|
// POST /api/blog - Create new post
|
|
router.post('/',
|
|
authenticateToken,
|
|
requireRole('admin'),
|
|
validateRequired(['title', 'slug', 'content']),
|
|
validateSlug,
|
|
asyncHandler(blogController.createPost)
|
|
);
|
|
|
|
// PUT /api/blog/:id - Update post
|
|
router.put('/:id',
|
|
authenticateToken,
|
|
requireRole('admin'),
|
|
validateObjectId('id'),
|
|
asyncHandler(blogController.updatePost)
|
|
);
|
|
|
|
// POST /api/blog/:id/publish - Publish post
|
|
router.post('/:id/publish',
|
|
authenticateToken,
|
|
requireRole('admin'),
|
|
validateObjectId('id'),
|
|
asyncHandler(blogController.publishPost)
|
|
);
|
|
|
|
// DELETE /api/blog/:id - Delete post
|
|
router.delete('/:id',
|
|
authenticateToken,
|
|
requireRole('admin'),
|
|
validateObjectId('id'),
|
|
asyncHandler(blogController.deletePost)
|
|
);
|
|
|
|
module.exports = router;
|