Skip to content

Commit

Permalink
Feat: 모든 오픈 채팅방 목록 불러오기
Browse files Browse the repository at this point in the history
  • Loading branch information
JitHoon committed Nov 8, 2023
1 parent 7173134 commit 703814a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/search/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { fetchAllOpenChat } from './search.utils';

const accessToken = process.env.ACCESSTOKEN as string; // 임시 access token

const Search = async () => {
const allOpenChat = await fetchAllOpenChat(accessToken);
console.log(allOpenChat);

return (
<>
<h1>Search 페이지</h1>
</>
);
};

export default Search;
9 changes: 9 additions & 0 deletions app/search/search.constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// http Method
export const GET = 'GET';

// API URL
export const BASE_URL = 'https://fastcampus-chat.net/';
export const GET_ALL_CHAT = 'chat/all';

// API Request 조건 정보
export const CONTENT_TYPE = 'application/json';
32 changes: 32 additions & 0 deletions app/search/search.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export type AllOpenChat = Chat[];

type Chat = {
id: string;
name: string;
users: User[];
isPrivate: boolean;
latestMessage: Message | null;
updatedAt: Date;
};

type User = {
id: string;
name: string;
picture: string;
};

type Message = {
id: string;
text: string;
userId: string;
createAt: Date;
};

export type Request = {
method: string;
headers: {
'content-type': string;
serverId: string;
Authorization: string;
};
};
18 changes: 18 additions & 0 deletions app/search/search.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Request, AllOpenChat } from './search.type';
import { GET, CONTENT_TYPE, BASE_URL, GET_ALL_CHAT } from './search.constant';

export const fetchAllOpenChat = async (accessToken: string) => {
const Request: Request = {
method: GET,
headers: {
'content-type': CONTENT_TYPE,
serverId: process.env.SERVER_ID as string, // 서버 아이디 임시 사용
Authorization: `Bearer ${accessToken}`,
},
};

const res = await fetch(`${BASE_URL}${GET_ALL_CHAT}`, Request);
const allOpenChat: AllOpenChat = await res.json();

return allOpenChat;
};

0 comments on commit 703814a

Please sign in to comment.