Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/MOVIEJOJO7/cat-talk into Fe…
Browse files Browse the repository at this point in the history
…ature/#2
hhjs2 committed Nov 9, 2023
2 parents 789b780 + 88b6544 commit e321c6d
Showing 7 changed files with 93 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## 관련 이슈

<!-- 관련있는 이슈 번호(#000)을 적어주세요. -->

## Description

<!-- 작업 내용을 적어주세요. -->
<!-- 강조할 부분은 볼드체로 작성해 주세요. -->

## 유의할 점 및 ETC (optional)

<!-- 팀원이 유의해야할 변경 사항이나 로직 및 기타 사항이 생겼다면 적어주세요. -->
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_CHAT_ALL = 'chat/all';

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

export type AllOpenChatJSON = {
chats: AllOpenChat;
};

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;
};
};
19 changes: 19 additions & 0 deletions app/search/search.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Request, AllOpenChatJSON, AllOpenChat } from './search.type';
import { GET, CONTENT_TYPE, BASE_URL, GET_CHAT_ALL } 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_CHAT_ALL}`, Request);
const resJson: AllOpenChatJSON = await res.json();
const allOpenChat: AllOpenChat = resJson.chats;

return allOpenChat;
};
Empty file added hooks/.gitkeep
Empty file.
Empty file added type/.gitkeep
Empty file.

0 comments on commit e321c6d

Please sign in to comment.