-
Notifications
You must be signed in to change notification settings - Fork 3
feat: 내 워크스페이스 목록·생성 Supabase 백엔드 연동 (#34) #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,4 @@ | ||
| # Supabase 연결 정보 — 값은 Supabase 대시보드(Settings > API Keys) 또는 팀 Discord 참고 | ||
| # PUBLISHABLE_KEY에는 publishable key(sb_publishable_...)를 사용한다 | ||
| NEXT_PUBLIC_SUPABASE_URL= | ||
| NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY= |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -45,3 +45,4 @@ AGENTS.md | |
| CLAUDE.md | ||
| .agents/ | ||
| .claude/ | ||
| !.env.example | ||
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,22 @@ | ||
| 'use client'; | ||
|
|
||
| // 전역 프로바이더 — tanstack-query 클라이언트를 앱 전체에 제공한다 | ||
| import { useState } from 'react'; | ||
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
|
|
||
| export default function Providers({ children }: { children: React.ReactNode }) { | ||
| // 요청 간 캐시가 섞이지 않도록 컴포넌트 수명과 함께 생성한다 | ||
| const [queryClient] = useState( | ||
| () => | ||
| new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { | ||
| staleTime: 30_000, | ||
| retry: 1, | ||
| }, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>; | ||
| } |
This file contains hidden or 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,22 +1,35 @@ | ||
| // create_workspace RPC의 Mock 구현 | ||
| // 백엔드 준비 시 supabase.rpc('create_workspace')로 교체한다 | ||
| // (실제로는 workspaces insert → invite_code 생성 → owner 등록 → purpose 기준 workspace_modules 생성 후 id 반환) | ||
| import type { WorkspacePurpose } from '../model/workspace.types'; | ||
| 'use server'; | ||
|
|
||
| export interface CreateWorkspaceInput { | ||
| name: string; | ||
| description?: string; | ||
| purpose: WorkspacePurpose; | ||
| } | ||
| // 워크스페이스 생성 서버액션 — create_workspace RPC | ||
| // (RPC가 workspaces + owner 멤버십 + purpose별 기본 모듈 + invite_code 생성을 한 트랜잭션으로 처리) | ||
| import { createSupabaseServerClient } from '@/shared/api/supabase/server'; | ||
| import { DEV_USER_ID } from '@/shared/config/dev-user'; | ||
| import { | ||
| createWorkspaceInputSchema, | ||
| type CreateWorkspaceInput, | ||
| } from '../model/create-workspace.schema'; | ||
| import { toDbPurpose } from '../model/purpose.mapper'; | ||
|
|
||
| export async function createWorkspace(input: CreateWorkspaceInput): Promise<{ id: string }> { | ||
| // Mock: 실제 저장 없이 워크스페이스 id만 생성해 반환한다 | ||
| const slug = | ||
| input.name | ||
| .trim() | ||
| .toLowerCase() | ||
| .replace(/[^a-z0-9가-힣]+/g, '-') | ||
| .replace(/^-+|-+$/g, '') || 'workspace'; | ||
| // 클라이언트(rhf+zod) 검증과 별개로 서버에서 재검증한다 | ||
| const parsed = createWorkspaceInputSchema.safeParse(input); | ||
| if (!parsed.success) { | ||
| throw new Error(parsed.error.issues[0]?.message ?? '입력값이 올바르지 않습니다'); | ||
| } | ||
|
|
||
| const supabase = await createSupabaseServerClient(); | ||
| const { data, error } = await supabase.rpc('create_workspace', { | ||
| p_user_id: DEV_USER_ID, | ||
| p_name: parsed.data.name, | ||
| p_purpose: toDbPurpose(parsed.data.purpose), | ||
| ...(parsed.data.description ? { p_description: parsed.data.description } : {}), | ||
| }); | ||
|
|
||
| if (error) { | ||
| // 상세 원인은 서버 로그에만 남기고, 클라이언트에는 일반화된 메시지만 반환한다 | ||
| console.error('[createWorkspace] RPC 실패:', error); | ||
| throw new Error('워크스페이스 생성에 실패했습니다. 잠시 후 다시 시도해주세요.'); | ||
| } | ||
|
|
||
| return { id: `ws-${slug}-${Date.now().toString(36)}` }; | ||
| return { id: data }; | ||
| } | ||
This file contains hidden or 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,51 +1,16 @@ | ||
| // get_my_workspaces RPC의 Mock 구현 | ||
| // 백엔드 준비 시 supabase.rpc('get_my_workspaces') 호출로 교체한다 (반환 shape 동일) | ||
| // 내 워크스페이스 목록 조회 — get_my_workspaces RPC (집계 포함 단일 쿼리, N+1 없음) | ||
| import { getSupabaseBrowserClient } from '@/shared/api/supabase/client'; | ||
| import { DEV_USER_ID } from '@/shared/config/dev-user'; | ||
| import { toUiPurpose } from '../model/purpose.mapper'; | ||
| import type { WorkspaceSummary } from '../model/workspace.types'; | ||
|
|
||
| // updated_at은 호출 시점 기준 상대값으로 생성해 "최근 활동" 표기가 자연스럽게 유지되도록 한다 | ||
| type MockWorkspaceSeed = Omit<WorkspaceSummary, 'updated_at' | 'progress'> & { | ||
| activityMinutesAgo: number; | ||
| }; | ||
|
|
||
| const MOCK_WORKSPACE_SEEDS: MockWorkspaceSeed[] = [ | ||
| { | ||
| id: 'ws-capstone-design', | ||
| name: '캡스톤 디자인 팀', | ||
| purpose: 'team-project', | ||
| member_count: 5, | ||
| task_count: 12, | ||
| done_task_count: 7, | ||
| activityMinutesAgo: 10, | ||
| }, | ||
| { | ||
| id: 'ws-fitto-app', | ||
| name: 'Fitto 앱 개발팀', | ||
| purpose: 'side-project', | ||
| member_count: 4, | ||
| task_count: 24, | ||
| done_task_count: 18, | ||
| activityMinutesAgo: 60, | ||
| }, | ||
| { | ||
| id: 'ws-cafe-gray', | ||
| name: '카페 그레이 운영', | ||
| purpose: 'store-operation', | ||
| member_count: 6, | ||
| task_count: 8, | ||
| done_task_count: 5, | ||
| activityMinutesAgo: 180, | ||
| }, | ||
| ]; | ||
|
|
||
| export async function getMyWorkspaces(): Promise<WorkspaceSummary[]> { | ||
| const now = Date.now(); | ||
| const supabase = getSupabaseBrowserClient(); | ||
| const { data, error } = await supabase.rpc('get_my_workspaces', { p_user_id: DEV_USER_ID }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| if (error) { | ||
| throw new Error(`워크스페이스 목록 조회에 실패했습니다: ${error.message}`); | ||
| } | ||
|
|
||
| return MOCK_WORKSPACE_SEEDS.map(({ activityMinutesAgo, ...summary }) => ({ | ||
| ...summary, | ||
| progress: | ||
| summary.task_count === 0 | ||
| ? 0 | ||
| : Math.round((summary.done_task_count / summary.task_count) * 100), | ||
| updated_at: new Date(now - activityMinutesAgo * 60_000).toISOString(), | ||
| })); | ||
| return (data ?? []).map((row) => ({ ...row, purpose: toUiPurpose(row.purpose) })); | ||
| } | ||
This file contains hidden or 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,16 @@ | ||
| 'use client'; | ||
|
|
||
| // 내 워크스페이스 목록 쿼리 훅 — GET은 tanstack-query 컨벤션 | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { DEV_USER_ID } from '@/shared/config/dev-user'; | ||
| import { getMyWorkspaces } from './get-my-workspaces'; | ||
|
|
||
| // 생성/수정 후 invalidateQueries({ queryKey: ['workspaces'] })로 무효화한다 | ||
| export const myWorkspacesQueryKey = ['workspaces', 'my', DEV_USER_ID] as const; | ||
|
|
||
| export function useMyWorkspaces() { | ||
| return useQuery({ | ||
| queryKey: myWorkspacesQueryKey, | ||
| queryFn: getMyWorkspaces, | ||
| }); | ||
| } |
This file contains hidden or 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 hidden or 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,20 @@ | ||
| // 워크스페이스 생성 입력 검증 — 폼(react-hook-form)과 서버액션이 같은 스키마를 공유한다 | ||
| import { z } from 'zod'; | ||
|
|
||
| export const createWorkspaceSchema = z.object({ | ||
| name: z | ||
| .string() | ||
| .trim() | ||
| .min(1, '워크스페이스 이름을 입력해주세요') | ||
| .max(50, '이름은 50자 이내로 입력해주세요'), | ||
| description: z.string().trim().max(200, '설명은 200자 이내로 입력해주세요').optional(), | ||
| }); | ||
|
|
||
| export type CreateWorkspaceForm = z.infer<typeof createWorkspaceSchema>; | ||
|
|
||
| // 서버액션용 — 폼 필드에 더해 purpose까지 재검증한다 (클라이언트 입력을 신뢰하지 않음) | ||
| export const createWorkspaceInputSchema = createWorkspaceSchema.extend({ | ||
| purpose: z.enum(['team-project', 'side-project', 'store-operation']), | ||
| }); | ||
|
|
||
| export type CreateWorkspaceInput = z.infer<typeof createWorkspaceInputSchema>; |
This file contains hidden or 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,20 @@ | ||
| // DB(snake_case) ↔ 프론트(hyphen) purpose 표기 매퍼 | ||
| // TODO: 프론트 WorkspacePurpose를 snake_case로 통일하는 리팩터링이 끝나면 이 파일을 제거한다 | ||
| import type { WorkspacePurposeDb } from './workspace.db.types'; | ||
| import type { WorkspacePurpose } from './workspace.types'; | ||
|
|
||
| const DB_TO_UI: Record<WorkspacePurposeDb, WorkspacePurpose> = { | ||
| team_project: 'team-project', | ||
| side_project: 'side-project', | ||
| store_operation: 'store-operation', | ||
| }; | ||
|
|
||
| const UI_TO_DB: Record<WorkspacePurpose, WorkspacePurposeDb> = { | ||
| 'team-project': 'team_project', | ||
| 'side-project': 'side_project', | ||
| 'store-operation': 'store_operation', | ||
| }; | ||
|
|
||
| export const toUiPurpose = (purpose: WorkspacePurposeDb): WorkspacePurpose => DB_TO_UI[purpose]; | ||
|
|
||
| export const toDbPurpose = (purpose: WorkspacePurpose): WorkspacePurposeDb => UI_TO_DB[purpose]; |
This file contains hidden or 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 hidden or 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,12 +1,2 @@ | ||
| import { z } from 'zod'; | ||
|
|
||
| export const createWorkspaceSchema = z.object({ | ||
| name: z | ||
| .string() | ||
| .trim() | ||
| .min(1, '워크스페이스 이름을 입력해주세요') | ||
| .max(50, '이름은 50자 이내로 입력해주세요'), | ||
| description: z.string().trim().max(200, '설명은 200자 이내로 입력해주세요').optional(), | ||
| }); | ||
|
|
||
| export type CreateWorkspaceForm = z.infer<typeof createWorkspaceSchema>; | ||
| // 폼 스키마는 서버액션 재검증과 공유하기 위해 entities/workspace가 소유한다 — 여기서는 재노출만 | ||
| export { createWorkspaceSchema, type CreateWorkspaceForm } from '@/entities/workspace'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.