-
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.
Browse files
Browse the repository at this point in the history
Feat : 유저/채팅방 검색 기능 추가 pr
- Loading branch information
Showing
4 changed files
with
92 additions
and
7 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
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
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,26 @@ | ||
import React from 'react'; | ||
// import { fetchAllOpenChat } from './search.utils'; | ||
import SearchOpenChat from '../../Components/Search/SearchOpenChat'; | ||
import { User } from '@/types'; | ||
import { fetchAllUsers, fetchMyChats, fetchMyUser } from './searchmychat.utils'; | ||
|
||
const Search = async () => { | ||
const accessToken = process.env.NEXT_PUBLIC_ACCESSTOKEN as string; | ||
const allUsers: User[] = await fetchAllUsers(accessToken); | ||
const myUser: User = await fetchMyUser(accessToken); | ||
const allUsersExceptMe: User[] | [] = allUsers.filter( | ||
(user) => user.id !== myUser.id, | ||
); | ||
const myChats = await fetchMyChats(accessToken); | ||
|
||
return ( | ||
<> | ||
<SearchOpenChat | ||
allUsersExceptMe={allUsersExceptMe} | ||
allOpenChat={myChats} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
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,38 @@ | ||
export const fetchAllUsers = async (token: string) => { | ||
const res = await fetch('https://fastcampus-chat.net/users', { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
serverId: process.env.NEXT_PUBLIC_SERVER_ID as string, | ||
}, | ||
}); | ||
const data = await res.json(); | ||
return data; | ||
}; | ||
|
||
export const fetchMyUser = async (token: string) => { | ||
const res = await fetch('https://fastcampus-chat.net/auth/me', { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
serverId: process.env.NEXT_PUBLIC_SERVER_ID as string, | ||
}, | ||
}); | ||
const data = await res.json(); | ||
return data.user; | ||
}; | ||
|
||
export const fetchMyChats = async (token: string) => { | ||
const res = await fetch('https://fastcampus-chat.net/chat', { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
serverId: process.env.NEXT_PUBLIC_SERVER_ID as string, | ||
}, | ||
}); | ||
const data = await res.json(); | ||
return data.chats; | ||
}; |