Skip to content

Commit

Permalink
Feat: 모든 게시물 조회 API 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
Nahyun-Kang committed Dec 15, 2024
1 parent 563eeb4 commit 4f9d06a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/app/_api/notice/getNotices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import axiosInstance from '@/lib/axios/axiosInstance';
import { NoticeListItemType } from '@/lib/types/noticeType';

const getNotices = async () => {
const result = await axiosInstance.get<NoticeListItemType[]>('/admin/notices');

return result.data;
};

export default getNotices;
18 changes: 14 additions & 4 deletions src/app/notice/NoticeList.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
'use client';

import Image from 'next/image';
import { useQuery } from '@tanstack/react-query';
import { QUERY_KEYS } from '@/lib/constants/queryKeys';
import getNotices from '../_api/notice/getNotices';

import { NoticeListItemType } from '@/lib/types/noticeType';
import { NOTICE_LIST_MOCKDATA } from './mockdata';

import * as styles from './NoticeList.css';
import Link from 'next/link';

function NoticeList() {
const { data: notices } = useQuery<NoticeListItemType[]>({
queryKey: [QUERY_KEYS.getAllNotices],
queryFn: getNotices,
staleTime: 1000 * 60 * 30,
});

return (
<ul className={styles.noticeListWrapper}>
{NOTICE_LIST_MOCKDATA?.map((item: NoticeListItemType) => (
<li key={item.id}>
{notices?.map((item: NoticeListItemType, index) => (
<li key={index}>
<NoticeListItem item={item} />
</li>
))}
Expand All @@ -26,7 +36,7 @@ interface NoticeListItemProps {

function NoticeListItem({ item }: NoticeListItemProps) {
return (
<Link href={`/notices/${item.id}`} className={styles.listItemWrapper}>
<Link href={`/notice/${item.id}`} className={styles.listItemWrapper}>
<div>
<h3 className={styles.noticeTitle}>{item.title}</h3>
<p className={styles.noticeDescription}>{item.description}</p>
Expand Down
1 change: 1 addition & 0 deletions src/lib/constants/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const QUERY_KEYS = {
getAdminAllNotice: 'getAdminAllNotice',

// 공지
getAllNotices: 'getAllNotices',
getNoticeCategories: 'getNoticeCategories',
getNoticeDetail: 'getNoticeDetail',
};

0 comments on commit 4f9d06a

Please sign in to comment.