File tree Expand file tree Collapse file tree 3 files changed +99
-0
lines changed
apps/frontend/src/features/workspace Expand file tree Collapse file tree 3 files changed +99
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Delete , Get , Post } from "@/shared/api" ;
2+ import {
3+ CreateWorkSpaceResponse ,
4+ CreateWorkSpaceResquest ,
5+ GetUserWorkspaceResponse ,
6+ RemoveWorkSpaceResponse ,
7+ } from "../model/workspaceTypes" ;
8+
9+ const BASE_URL = "/api/workspace" ;
10+
11+ export const createWorkspace = async ( payload : CreateWorkSpaceResquest ) => {
12+ const res = await Post < CreateWorkSpaceResponse , CreateWorkSpaceResquest > (
13+ BASE_URL ,
14+ payload ,
15+ ) ;
16+ return res . data ;
17+ } ;
18+
19+ export const removeWorkspace = async ( workspaceId : string ) => {
20+ const url = `${ BASE_URL } /${ workspaceId } ` ;
21+
22+ const res = await Delete < RemoveWorkSpaceResponse > ( url ) ;
23+ return res . data ;
24+ } ;
25+
26+ // TODO: /entities/user vs workspace 위치 고민해봐야할듯?
27+ export const getUserWorkspaces = async ( ) => {
28+ const url = `${ BASE_URL } /user` ;
29+
30+ const res = await Get < GetUserWorkspaceResponse > ( url ) ;
31+ return res . data ;
32+ } ;
Original file line number Diff line number Diff line change 1+ import { useMutation , useQuery , useQueryClient } from "@tanstack/react-query" ;
2+
3+ import {
4+ createWorkspace ,
5+ getUserWorkspaces ,
6+ removeWorkspace ,
7+ } from "../api/workspaceApi" ;
8+
9+ export const useUserWorkspace = ( ) => {
10+ return useQuery ( {
11+ queryKey : [ "userWorkspace" ] ,
12+ queryFn : getUserWorkspaces ,
13+ } ) ;
14+ } ;
15+
16+ // response로 workspaceId가 오는데 userWorkspace를 어떻게 invalidate 할까?
17+ // login state에 있는 userId로?
18+ export const useCreateWorkspace = ( ) => {
19+ const queryClient = useQueryClient ( ) ;
20+
21+ return useMutation ( {
22+ mutationFn : createWorkspace ,
23+ onSuccess : ( ) => {
24+ queryClient . invalidateQueries ( { queryKey : [ "userWorkspace" ] } ) ;
25+ } ,
26+ } ) ;
27+ } ;
28+
29+ export const useRemoveWorkspace = ( ) => {
30+ const queryClient = useQueryClient ( ) ;
31+
32+ return useMutation ( {
33+ mutationFn : removeWorkspace ,
34+ onSuccess : ( ) => {
35+ queryClient . invalidateQueries ( { queryKey : [ "userWorkspace" ] } ) ;
36+ } ,
37+ } ) ;
38+ } ;
Original file line number Diff line number Diff line change 1+ export interface Workspace {
2+ workspaceId : string ;
3+ title : string ;
4+ description : string ;
5+ thumbnailUrl : string ;
6+ role : "owner" | "guest" ;
7+ visibility : "private" | "public" ;
8+ }
9+
10+ export interface CreateWorkSpaceResquest {
11+ title : string ;
12+ description ?: string ;
13+ visibility ?: "private" | "public" ;
14+ thumbnailUrl ?: string ;
15+ }
16+
17+ export interface CreateWorkSpaceResponse {
18+ message : string ;
19+ workspaceId : string ;
20+ }
21+
22+ export interface RemoveWorkSpaceResponse {
23+ message : string ;
24+ }
25+
26+ export interface GetUserWorkspaceResponse {
27+ message : string ;
28+ workspaces : Workspace [ ] ;
29+ }
You can’t perform that action at this time.
0 commit comments