Skip to content

Commit

Permalink
GET /notice가 서버에서 fetch하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
yeolyi committed Sep 21, 2023
1 parent 8dde2f7 commit 3913e84
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
username: ${{secrets.SSH_USER}}
key: ${{secrets.SSH_KEY}}
script: |
cd ~/csereal_web
cd ~/csereal-web
git pull
npm run build
pm2 stop csereal_front
pm2 --name csereal_front start npm -- start
pm2 restart csereal_front
19 changes: 19 additions & 0 deletions actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ import { cookies } from 'next/headers';

import { BASE_URL, checkError } from '@/apis';

import { objToQueryString } from '@/utils/convertParams';

export const getRequest = async <T>(url: string, params: object = {}, init?: RequestInit) => {
const queryString = objToQueryString(params);
const fetchUrl = `${BASE_URL}${url}${queryString}`;
const jsessionId = cookies().get('JSESSIONID');
const response = await fetch(fetchUrl, {
...init,
method: 'GET',
headers: {
Cookie: `JSESSIONID=${jsessionId?.value}`,
...init?.headers,
},
});
checkError(response);
const responseData = await response.json();
return responseData as T;
};

export const deleteRequest = async (url: string, init?: RequestInit) => {
const fetchUrl = `${BASE_URL}${url}`;
const jsessionId = cookies().get('JSESSIONID');
Expand Down
14 changes: 13 additions & 1 deletion actions/noticeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@
import { revalidateTag } from 'next/cache';
import { redirect } from 'next/navigation';

import { NoticePreviewList, Notice } from '@/types/notice';
import { notice } from '@/types/page';
import { PostSearchQueryParams } from '@/types/post';

import { getPath } from '@/utils/page';

import { deleteRequest, patchRequest } from '.';
import { deleteRequest, getRequest, patchRequest } from '.';

const noticeApiPath = '/notice';
const noticePath = getPath(notice);

export const getNoticePosts = (params: PostSearchQueryParams) =>
getRequest(noticeApiPath, params, {
next: { tags: ['notice'] },
}) as Promise<NoticePreviewList>;

export const getNoticePostDetail = (id: number, params: PostSearchQueryParams) =>
getRequest(`${noticeApiPath}/${id}`, params, {
next: { tags: ['notice'] },
}) as Promise<Notice>;

export const batchDeleteAction = async (ids: Set<number>) => {
try {
await deleteRequest(noticeApiPath, {
Expand Down
14 changes: 2 additions & 12 deletions apis/notice.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import { Notice, NoticePreviewList, POSTNoticeBody, PatchNoticeBody } from '@/types/notice';
import { PostSearchQueryParams } from '@/types/post';

import {
deleteRequestWithCookie,
getRequest,
patchRequestWithCookie,
postRequestWithCookie,
} from '.';
import { deleteRequestWithCookie, patchRequestWithCookie, postRequestWithCookie } from '.';
import { getRequest } from '../actions';

const noticePath = '/notice';

export const getNoticePosts = (params: PostSearchQueryParams) =>
getRequest(noticePath, params, { next: { tags: ['notice'] } }) as Promise<NoticePreviewList>;

export const getNoticePostDetail = (id: number, params: PostSearchQueryParams) =>
getRequest(`${noticePath}/${id}`, params, { next: { tags: ['notice'] } }) as Promise<Notice>;

export const postNotice = async (body: POSTNoticeBody) => {
const formData = new FormData();
formData.append(
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/community/notice/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getNoticePostDetail } from '@/apis/notice';
import { getNoticePostDetail } from '@/actions/noticeActions';

import EditNoticePageContent from '@/components/notice/EditNoticePageContent';

Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/community/notice/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getNoticePostDetail } from '@/apis/notice';
import { getNoticePostDetail } from '@/actions/noticeActions';

import AdjPostNav from '@/components/common/AdjPostNav';
import Attachments from '@/components/common/Attachments';
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/community/notice/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function NoticeCreatePage() {
const handleCancel = () => router.push(noticePath);

const handleComplete = async (content: PostEditorContent) => {
console.log(content.description);
console.log(content.isPrivate);
canSubmit(content);

const attachments = content.attachments.filter(isLocalFile).map((x) => x.file);
Expand Down
2 changes: 1 addition & 1 deletion app/[locale]/community/notice/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getNoticePosts } from '@/apis/notice';
import { getNoticePosts } from '@/actions/noticeActions';

import NoticePageContent from '@/components/notice/NoticePageContent';

Expand Down
4 changes: 2 additions & 2 deletions components/notice/EditNoticePageContent.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use client';

import { useRouter } from 'next/navigation';
import { startTransition, useTransition } from 'react';
import { useTransition } from 'react';

import { noticeDeleteAction, revalidateNoticeTag } from '@/actions/noticeActions';

import { deleteNotice, patchNotice } from '@/apis/notice';
import { patchNotice } from '@/apis/notice';

import PostEditor from '@/components/editor/PostEditor';
import {
Expand Down

0 comments on commit 3913e84

Please sign in to comment.