feat: implement article management features with CRUD operations
Some checks failed
Build and Test / run-test (20.x) (push) Has been cancelled

This commit is contained in:
2026-04-09 21:49:29 -03:00
parent a338972c84
commit 878fc1094b
9 changed files with 609 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
'use server';
import {
ArticleModel,
CreateArticleModel,
PaginatedArticlesResult,
UpdateArticleModel,
} from '@/lib/feature/article/article.model';
import * as service from '@/lib/feature/article/article.service';
import { getSessionData } from '@/lib/session/session-storage';
import { UUIDv4 } from '@/utils/types/uuid';
export const getArticleByExternalId = async (
externalId: UUIDv4
): Promise<ArticleModel | null> => {
return await service.getArticleByExternalId(externalId);
};
export const getArticleBySlug = async (
slug: string
): Promise<ArticleModel | null> => {
return await service.getArticleBySlug(slug);
};
export const getArticlesPaginated = async (
page: number = 1,
pageSize: number = 10
): Promise<PaginatedArticlesResult> => {
return await service.getArticlesPaginated(page, pageSize);
};
export const saveArticle = async (
article: CreateArticleModel
): Promise<ArticleModel> => {
const session = await getSessionData();
if (!session || !session?.user || session?.user.role !== 'admin') {
throw new Error('Unauthorized: Only admin users can save articles.');
}
article.authorId = session.user.id;
return await service.saveArticle(article);
};
export const updateArticle = async (
articleId: string,
article: UpdateArticleModel
): Promise<ArticleModel> => {
const session = await getSessionData();
if (!session || !session?.user || session?.user.role !== 'admin') {
throw new Error('Unauthorized: Only admin users can save articles.');
}
return await service.updateArticle(articleId, article);
};
export const deleteArticle = async (articleId: string): Promise<void> => {
const session = await getSessionData();
if (!session || !session?.user || session?.user.role !== 'admin') {
throw new Error('Unauthorized: Only admin users can delete articles.');
}
await service.deleteArticle(articleId);
};