Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#228 팀페이지, 스터디 페이지 학습자료 crud #252

42 changes: 42 additions & 0 deletions src/app/api/document.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { fetcher } from '@/app/api/fetcher';
import { Document } from '@/types';

const documentFetcher = fetcher();

const postDocument = (groupType: number, groupId: number, document: Document, files: FormData) => {
documentFetcher(`/${groupType}/${groupId}/documents`, {
method: 'POST',
body: { document, files },
});
};

const getDocumentList = (groupType: number, groupId: number, page: number = 0, size: number = 4) => {
documentFetcher(`/${groupType}/${groupId}/documents?page=${page}&size=${size}`, {
method: 'GET',
});
};

const getDocument = (documentId: number) => {
documentFetcher(`/${documentId}`, {
method: 'GET',
});
};

const putDocument = (documentId: number, title: string, description: string, accessType: string) => {
documentFetcher(`/${documentId}`, {
method: 'PUT',
body: {
title,
description,
accessType,
},
});
};

const deleteDocument = (documentId: number) => {
documentFetcher(`/${documentId}`, {
method: 'DELETE',
});
};

export { postDocument, getDocumentList, getDocument, putDocument, deleteDocument };
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,12 @@ export interface Curriculum {
itemOrder: number;
isCompleted?: boolean;
}

export interface Document {
title: string;
description: string;
accessType: string;
type: string;
url: string;
uploaderId: number;
}