-
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.
Merge pull request #76 from KUIT-Space/feat#51-chat_detail
Feat#51 chat detail
- Loading branch information
Showing
48 changed files
with
1,088 additions
and
143 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 |
---|---|---|
|
@@ -24,3 +24,5 @@ dist-ssr | |
*.sw? | ||
localhost-key.pem | ||
localhost.pem | ||
.env | ||
*_mockChat.tsx |
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,46 @@ | ||
import { createRequestOptionsFORM_AUTH, fetchApi } from "@/apis/_createRequestOptions"; | ||
|
||
interface CreateChatroomApiResponseType { | ||
code: number; | ||
status: number; | ||
message: string; | ||
result: { | ||
chatRoomId: number; | ||
}; | ||
} | ||
|
||
interface CreateChatroomApiRequestType { | ||
img?: File | null; // ์ด๋ฏธ์ง ํ์ผ์ ์ ํ์ | ||
name: string; | ||
memberList: number[]; | ||
} | ||
|
||
const createChatroomFormData = (body: CreateChatroomApiRequestType): FormData => { | ||
const formData = new FormData(); | ||
formData.append("name", body.name); | ||
|
||
if (body.img) { | ||
formData.append("img", body.img); | ||
} | ||
|
||
body.memberList.forEach((memberId) => { | ||
formData.append("memberList", memberId.toString()); | ||
}); | ||
|
||
return formData; | ||
}; | ||
|
||
export const createChatroomApi = async ( | ||
spaceId: number, | ||
name: string, | ||
memberList: number[], | ||
img?: File | null, | ||
) => { | ||
const formData = createChatroomFormData({ name, memberList, img: img || null }); | ||
const requestOptions = createRequestOptionsFORM_AUTH("POST", formData); | ||
|
||
if (!requestOptions) return null; | ||
|
||
const url = `${import.meta.env.VITE_API_BACK_URL}/space/${spaceId}/chat/chatroom`; | ||
return await fetchApi<CreateChatroomApiResponseType>(url, requestOptions); | ||
}; |
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,25 @@ | ||
import { createRequestOptionsJSON_AUTH, fetchApi } from "@/apis/_createRequestOptions"; | ||
|
||
export interface Chatroom { | ||
id: number; | ||
name: string; | ||
imgUrl: string; | ||
lastMsg: string; | ||
lastTime: string; | ||
unreadMsgCount: number; | ||
} | ||
|
||
interface ChatroomSearchApiResponse { | ||
code: number; | ||
status: number; | ||
message: string; | ||
result: { chatRoomList: Chatroom[] }; | ||
} | ||
|
||
export const chatroomSearchAllApi = async (spaceId: number) => { | ||
const requestOptions = createRequestOptionsJSON_AUTH("GET"); | ||
if (!requestOptions) return null; | ||
|
||
const url = `${import.meta.env.VITE_API_BACK_URL}/space/${spaceId}/chat/chatroom`; | ||
return await fetchApi<ChatroomSearchApiResponse>(url, requestOptions); | ||
}; |
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,51 @@ | ||
/* POST /space | ||
* @summary Create a Space | ||
* @body json์ด ์๋ form-data๋ก ์ ์กํด์ผ ํจ | ||
* * spaceName Text(String) 1~10 ์ ์ด๋ด์ ๋ฌธ์์ด | ||
* * spaceProfileImg File nullable / ์ด๋ฏธ์ง ํ์ผ ํ์ฅ์ ํ์์ ์งํค๋ ์ด๋ฏธ์ง ํ์ผ | ||
* @return status OK - success response | ||
*/ | ||
import { createRequestOptionsFORM_AUTH, RequestOptions } from "@/apis/_createRequestOptions"; | ||
|
||
interface CreateSpaceApiResponseType { | ||
code: number; | ||
message: string; | ||
status: string; | ||
timestamp?: string; | ||
} | ||
|
||
interface CreateSpaceApiRequestType { | ||
spaceName: string; | ||
spaceProfileImg?: File | null; // ์ด๋ฏธ์ง ํ์ผ์ ์ ํ์ | ||
} | ||
|
||
const fetchCreateSpaceApi = async (url: string, options: RequestOptions) => { | ||
const response: CreateSpaceApiResponseType = await fetch(url, options) | ||
.then((res) => res.json()) | ||
.catch((err) => { | ||
console.error("[fetch error]", err); | ||
throw err; | ||
}); | ||
|
||
return response; | ||
}; | ||
|
||
export const createSpaceApi = async (spaceName: string, spaceProfileImg?: File | null) => { | ||
const body: CreateSpaceApiRequestType = { | ||
spaceName: spaceName, | ||
spaceProfileImg: spaceProfileImg || null, | ||
}; | ||
|
||
const formData = new FormData(); | ||
formData.append("spaceName", body.spaceName); | ||
if (body.spaceProfileImg) { | ||
formData.append("spaceProfileImg", body.spaceProfileImg); | ||
} | ||
|
||
const requestOptions = createRequestOptionsFORM_AUTH("POST", formData); | ||
const result = requestOptions | ||
? await fetchCreateSpaceApi(`${import.meta.env.VITE_API_BACK_URL}/space`, requestOptions) | ||
: null; | ||
|
||
return result; | ||
}; |
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,28 @@ | ||
import { createRequestOptionsJSON_AUTH, fetchApi } from "@/apis/_createRequestOptions"; | ||
|
||
// ์ธํฐํ์ด์ค ์ ์ | ||
export interface UserInfoInSpace { | ||
userId: number; | ||
userName: string; | ||
profileImgUrl: string | null; | ||
userAuth: "manager" | "normal"; | ||
} | ||
|
||
interface SpaceSearchAllUserApiResponseType { | ||
code: number; | ||
status: number; | ||
message: string; | ||
result: { | ||
userInfoInSpaceList: UserInfoInSpace[]; | ||
}; | ||
} | ||
|
||
// API ํจ์ ์ ์ | ||
export const spaceSearchAllUserApi = async (spaceId: number) => { | ||
const requestOptions = createRequestOptionsJSON_AUTH("GET"); | ||
|
||
if (!requestOptions) return null; | ||
|
||
const url = `${import.meta.env.VITE_API_BACK_URL}/space/${spaceId}/all-member`; | ||
return await fetchApi<SpaceSearchAllUserApiResponseType>(url, requestOptions); | ||
}; |
Empty file.
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
export * from "@/apis/LoginApi"; | ||
export * from "@/apis/ChatroomSearchAllApi"; | ||
export * from "@/apis/ChatroomCreateApi"; | ||
export * from "@/apis/SpaceCreateApi"; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.