%PDF- %PDF-
| Direktori : /home2/rezakur1/public/api-rezakurnia/src/controllers/ |
| Current File : //home2/rezakur1/public/api-rezakurnia/src/controllers/article.controller.js |
import * as repo from "../repositories/article.repository.js";
/*
|--------------------------------------------------------------------------
| GET ALL ARTICLES (FLAT - LAMA)
|--------------------------------------------------------------------------
*/
export const getAllArticles = async (req, res) => {
try {
const data = await repo.getAllArticles();
res.json({
status: "success",
data,
});
} catch (err) {
res.status(500).json({
status: "error",
message: err.message,
});
}
};
/*
|--------------------------------------------------------------------------
| GET ARTICLE STATISTICS (🔥 BARU)
|--------------------------------------------------------------------------
*/
export const getArticleStatistics = async (req, res) => {
try {
const data = await repo.getArticleStatistics();
res.json({
status: "success",
data,
});
} catch (err) {
res.status(500).json({
status: "error",
message: err.message,
});
}
};
/*
|--------------------------------------------------------------------------
| GET DETAIL ARTICLE BY SLUG
|--------------------------------------------------------------------------
*/
export const getArticleBySlug = async (req, res) => {
try {
const { slug } = req.params;
const data = await repo.getArticleBySlug(slug);
if (!data) {
return res.status(404).json({
status: "error",
message: "Artikel tidak ditemukan",
});
}
res.json({
status: "success",
data,
});
} catch (err) {
res.status(500).json({
status: "error",
message: err.message,
});
}
};
/*
|--------------------------------------------------------------------------
| 🔥 GET CATEGORIES + COUNT ARTICLES
|--------------------------------------------------------------------------
*/
export const getCategoriesWithCount = async (req, res) => {
try {
const data = await repo.getCategoriesWithCount();
res.json({
status: "success",
data,
});
} catch (err) {
res.status(500).json({
status: "error",
message: err.message,
});
}
};