feat: add getPublic route to fetch news item by slug
This commit is contained in:
parent
1825310280
commit
fb3d3c410c
@ -60,6 +60,29 @@ exports.listActive = async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.getPublic = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { slug } = req.params || {}
|
||||||
|
if (!slug) return res.status(400).json({ error: 'slug is required' })
|
||||||
|
const r = await NewsService.get(slug)
|
||||||
|
if (!r || !r.is_active) return res.status(404).json({ error: 'Not found' })
|
||||||
|
const data = {
|
||||||
|
id: r.id,
|
||||||
|
title: r.title,
|
||||||
|
summary: r.summary,
|
||||||
|
content: r.content,
|
||||||
|
slug: r.slug,
|
||||||
|
category: r.category,
|
||||||
|
published_at: r.published_at,
|
||||||
|
imageUrl: r.object_storage_id ? buildImageUrlFromKey(r.object_storage_id) : ''
|
||||||
|
}
|
||||||
|
res.json({ success: true, data })
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('[NewsController.getPublic] error', { msg: e.message })
|
||||||
|
res.status(500).json({ error: 'Failed to load news item' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exports.create = async (req, res) => {
|
exports.create = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { title, summary, content, slug, category, isActive, publishedAt } = req.body
|
const { title, summary, content, slug, category, isActive, publishedAt } = req.body
|
||||||
|
|||||||
@ -158,6 +158,7 @@ router.get('/admin/abonements', authMiddleware, adminOnly, AbonemmentController.
|
|||||||
// News Manager Routes
|
// News Manager Routes
|
||||||
router.get('/admin/news', authMiddleware, adminOnly, NewsController.list);
|
router.get('/admin/news', authMiddleware, adminOnly, NewsController.list);
|
||||||
router.get('/news/active', NewsController.listActive);
|
router.get('/news/active', NewsController.listActive);
|
||||||
|
router.get('/news/:slug', NewsController.getPublic);
|
||||||
|
|
||||||
// NEW: Invoice GETs
|
// NEW: Invoice GETs
|
||||||
router.get('/invoices/mine', authMiddleware, InvoiceController.listMine);
|
router.get('/invoices/mine', authMiddleware, InvoiceController.listMine);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user