| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 'use server';
- import PostReactionRequest from '@/dtos/request/forum/post/postReactionRequest';
- import PostBookmarkRequest from '@/dtos/request/forum/post/postBookmarkRequest';
- import PostReportRequest from '@/dtos/request/forum/post/postReportRequest';
- import PostFileDownLogRequest from '@/dtos/request/forum/post/postFileDownLogRequest';
- import PostCreateResponse from '@/dtos/response/forum/post/postCreateResponse';
- import PostUpdateResponse from '@/dtos/response/forum/post/postUpdateResponse';
- import PostResponse from '@/dtos/response/forum/post/postResponse';
- import { ResultDto } from '@/dtos/response/common';
- import { fetchJson } from '@/lib/utils/server';
- // 게시글 등록
- export async function fetchPostCreate(formData: FormData): Promise<ResultDto<PostCreateResponse>> {
- return await fetchJson<PostCreateResponse>('/api/forum/posts', {
- method: 'POST',
- headers: {'Accept': 'application/json'},
- body: formData
- });
- }
- // 게시글 정보 조회
- export async function fetchPostData(postID: number): Promise<ResultDto<PostResponse>> {
- const post = await fetchJson<PostResponse>(`/api/forum/posts/${postID}`, {
- method: 'GET',
- headers: {
- 'Accept': 'application/json'
- }
- });
- if (post.success && post.data) {
- // 이미지 URL 변경
- post.data.content = post.data.content.replace(/<img\b[^>]*?\bsrc=["']?(\/[^"'\s>]*)["']?/gi, (match, src) => {
- return match.replace(src, process.env.API_URL + src);
- });
- }
- return post;
- }
- // 게시글 반응(좋아요/싫어요) 처리
- export async function fetchPostReaction(params: PostReactionRequest): Promise<ResultDto> {
- return await fetchJson(`/api/forum/posts/${params.postID}/reaction`, {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({ reaction: params.reaction })
- });
- }
- // 게시글 즐겨찾기 처리
- export async function fetchPostBookmark(params: PostBookmarkRequest): Promise<ResultDto> {
- return await fetchJson(`/api/forum/posts/${params.postID}/bookmark`, {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- }
- });
- }
- // 게시글 신고
- export async function fetchReport(params: PostReportRequest): Promise<ResultDto> {
- return await fetchJson(`/api/forum/posts/${params.postID}/report`, {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({ type: params.type, reason: params.reason })
- });
- }
- // 게시글 삭제
- export async function fetchPostDelete(postID: number): Promise<ResultDto> {
- return await fetchJson(`/api/forum/posts/${postID}`, {
- method: 'DELETE',
- headers: {
- 'Accept': 'application/json'
- }
- });
- }
- // 게시글 수정
- export async function fetchPostUpdate(postID: number, formData: FormData): Promise<ResultDto<PostUpdateResponse>> {
- return await fetchJson<PostUpdateResponse>(`/api/forum/posts/${postID}`, {
- method: 'PUT',
- headers: {
- 'Accept': 'application/json',
- },
- body: formData
- });
- }
- // 파일 다운로드 기록
- export async function fetchFileDownLog(params: PostFileDownLogRequest): Promise<ResultDto<PostUpdateResponse>> {
- return await fetchJson<PostUpdateResponse>(`/api/forum/posts/files/${params.uuid}/download`, {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- }
- });
- }
|