-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |