feat(m13): cross-resource search + dashboard completion, tests, e2e
- SearchService (cross-resource keyword search across board/chat/todo/file/ event/meeting/milestone/note with type filter, project isolation) - DashboardService (project dashboard: in-progress todos, near-due(7d), latest chat/board/notes/files(5), next meeting, milestones w/ progress, recent activity(10); personal dashboard: my projects, incomplete todos, upcoming meetings, unread notifications, overdue tasks, recent activity) - CalendarRepository.findByProject - APIs: GET /api/projects/:projectId/search, GET /api/dashboard - Screens: complete personal dashboard, complete project overview, search page + SearchForm, ProjectNav 検索 link - Unit tests (SearchService, DashboardService) + e2e dashboard
This commit is contained in:
19
app/api/dashboard/route.ts
Normal file
19
app/api/dashboard/route.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getCurrentUser } from '@/lib/auth/getCurrentUser';
|
||||
import { createDashboardService } from '@/lib/api/services';
|
||||
import { UnauthorizedError } from '@/lib/errors';
|
||||
import { handleApiError } from '@/lib/api/handleError';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
export async function GET() {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) return handleApiError(new UnauthorizedError());
|
||||
|
||||
const service = createDashboardService();
|
||||
try {
|
||||
return NextResponse.json(service.getPersonalDashboard(user.id));
|
||||
} catch (error) {
|
||||
return handleApiError(error);
|
||||
}
|
||||
}
|
||||
32
app/api/projects/[projectId]/search/route.ts
Normal file
32
app/api/projects/[projectId]/search/route.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getCurrentUser } from '@/lib/auth/getCurrentUser';
|
||||
import { createSearchService } from '@/lib/api/services';
|
||||
import { UnauthorizedError } from '@/lib/errors';
|
||||
import { handleApiError } from '@/lib/api/handleError';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ projectId: string }> }
|
||||
) {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) return handleApiError(new UnauthorizedError());
|
||||
const { projectId } = await params;
|
||||
const q = request.nextUrl.searchParams.get('q') ?? '';
|
||||
const type = (request.nextUrl.searchParams.get('type') ?? undefined) as
|
||||
| string
|
||||
| undefined;
|
||||
|
||||
const service = createSearchService();
|
||||
try {
|
||||
return NextResponse.json(
|
||||
service.search(user.id, Number(projectId), {
|
||||
q,
|
||||
type: type as never,
|
||||
})
|
||||
);
|
||||
} catch (error) {
|
||||
return handleApiError(error);
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
import { getCurrentUser, toPublicUser } from '@/lib/auth/getCurrentUser';
|
||||
import { createProjectService } from '@/lib/api/services';
|
||||
import { createDashboardService } from '@/lib/api/services';
|
||||
import { Header } from '@/components/layout/Header';
|
||||
import { ProjectCard } from '@/components/project/ProjectCard';
|
||||
import { CreateProjectForm } from '@/components/project/CreateProjectForm';
|
||||
import { DashboardWidget } from '@/components/project/DashboardWidget';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
@ -13,31 +13,75 @@ export default async function DashboardPage() {
|
||||
redirect('/login');
|
||||
}
|
||||
|
||||
const service = createProjectService();
|
||||
const projects = service.getMyProjects(user.id);
|
||||
const service = createDashboardService();
|
||||
const dashboard = service.getPersonalDashboard(user.id);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<Header user={toPublicUser(user)} />
|
||||
<main className="mx-auto max-w-4xl space-y-6 p-6">
|
||||
<h1 className="text-2xl font-bold">ダッシュボード</h1>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<DashboardWidget title="参加プロジェクト" empty="ありません">
|
||||
{dashboard.projects.map((p) => (
|
||||
<a
|
||||
key={p.id}
|
||||
href={`/projects/${p.id}`}
|
||||
className="block rounded border px-3 py-2 text-sm hover:bg-gray-50"
|
||||
>
|
||||
{p.name}({p.status})
|
||||
</a>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget
|
||||
title={`未読通知 (${dashboard.unreadNotificationCount})`}
|
||||
empty="未読はありません"
|
||||
>
|
||||
<a
|
||||
href="/notifications"
|
||||
className="text-sm text-blue-600 hover:underline"
|
||||
>
|
||||
通知一覧を開く
|
||||
</a>
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget title="未完了ToDo" empty="ありません">
|
||||
{dashboard.incompleteTodos.map((t) => (
|
||||
<p key={t.id} className="text-sm">
|
||||
{t.title}
|
||||
{t.dueDate ? `(期限: ${t.dueDate})` : ''}
|
||||
</p>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget title="期限切れタスク" empty="ありません">
|
||||
{dashboard.overdueTasks.map((t) => (
|
||||
<p key={t.id} className="text-sm text-red-600">
|
||||
{t.title}(期限: {t.dueDate})
|
||||
</p>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget title="近日中のミーティング" empty="ありません">
|
||||
{dashboard.upcomingMeetings.map((m) => (
|
||||
<p key={m.id} className="text-sm">
|
||||
{m.title}({m.startAt})
|
||||
</p>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget title="最近のアクティビティ" empty="ありません">
|
||||
{dashboard.recentActivity.map((l) => (
|
||||
<p key={l.id} className="text-sm">
|
||||
{l.action}({l.targetType})
|
||||
</p>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
</div>
|
||||
|
||||
<CreateProjectForm />
|
||||
<section>
|
||||
<h2 className="mb-3 text-sm font-semibold text-gray-700">
|
||||
参加プロジェクト
|
||||
</h2>
|
||||
{projects.length === 0 ? (
|
||||
<p className="text-sm text-gray-400">
|
||||
参加しているプロジェクトはありません。
|
||||
</p>
|
||||
) : (
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
{projects.map((project) => (
|
||||
<ProjectCard key={project.id} project={project} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
|
||||
@ -1,43 +1,34 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
import { getCurrentUser, toPublicUser } from '@/lib/auth/getCurrentUser';
|
||||
import { createProjectService } from '@/lib/api/services';
|
||||
import { createDashboardService } from '@/lib/api/services';
|
||||
import { Header } from '@/components/layout/Header';
|
||||
import { ProjectNav } from '@/components/layout/ProjectNav';
|
||||
import { DashboardWidget } from '@/components/project/DashboardWidget';
|
||||
import { ForbiddenError, NotFoundError } from '@/lib/errors';
|
||||
import { ForbiddenError } from '@/lib/errors';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
active: 'Active',
|
||||
on_hold: 'On Hold',
|
||||
completed: 'Completed',
|
||||
archived: 'Archived',
|
||||
};
|
||||
|
||||
export default async function ProjectOverviewPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ projectId: string }>;
|
||||
}) {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) {
|
||||
redirect('/login');
|
||||
}
|
||||
if (!user) redirect('/login');
|
||||
const { projectId } = await params;
|
||||
|
||||
const service = createProjectService();
|
||||
const service = createDashboardService();
|
||||
let dashboard;
|
||||
try {
|
||||
dashboard = service.getDashboard(user.id, Number(projectId));
|
||||
dashboard = service.getProjectDashboard(user.id, Number(projectId));
|
||||
} catch (error) {
|
||||
if (error instanceof ForbiddenError || error instanceof NotFoundError) {
|
||||
if (error instanceof ForbiddenError) {
|
||||
redirect('/dashboard');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
const { project, members } = dashboard;
|
||||
const { project } = dashboard;
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
@ -47,31 +38,107 @@ export default async function ProjectOverviewPage({
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-2xl font-bold">{project.name}</h1>
|
||||
<span className="rounded bg-gray-100 px-2 py-0.5 text-xs">
|
||||
{STATUS_LABELS[project.status] ?? project.status}
|
||||
{project.status}
|
||||
</span>
|
||||
</div>
|
||||
{project.description && (
|
||||
<p className="text-gray-600">{project.description}</p>
|
||||
)}
|
||||
<p className="text-sm text-gray-500">メンバー数: {members.length}</p>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<DashboardWidget title="進行中ToDo" empty="ありません">
|
||||
{dashboard.inProgressTodos.map((t) => (
|
||||
<p key={t.id} className="text-sm">
|
||||
{t.title}
|
||||
{t.dueDate ? `(期限: ${t.dueDate})` : ''}
|
||||
</p>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget title="期限が近いToDo (7日以内)" empty="ありません">
|
||||
{dashboard.nearDueTodos.map((t) => (
|
||||
<p key={t.id} className="text-sm">
|
||||
{t.title}({t.dueDate})
|
||||
</p>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget title="最新チャット (5件)" empty="ありません">
|
||||
{dashboard.latestChat.map((m) => (
|
||||
<p key={m.id} className="text-sm">
|
||||
{m.body}
|
||||
</p>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget title="最新掲示板 (5件)" empty="ありません">
|
||||
{dashboard.latestBoard.map((t) => (
|
||||
<a
|
||||
key={t.id}
|
||||
href={`/projects/${project.id}/board/${t.id}`}
|
||||
className="block text-sm text-blue-600 hover:underline"
|
||||
>
|
||||
{t.isPinned === 1 ? '📌 ' : ''}
|
||||
{t.title}
|
||||
</a>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget title="最新メモ (5件)" empty="ありません">
|
||||
{dashboard.latestNotes.map((n) => (
|
||||
<a
|
||||
key={n.id}
|
||||
href={`/projects/${project.id}/notes/${n.id}`}
|
||||
className="block text-sm text-blue-600 hover:underline"
|
||||
>
|
||||
{n.isPinned === 1 ? '📌 ' : ''}
|
||||
{n.title}
|
||||
</a>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget title="最近のファイル (5件)" empty="ありません">
|
||||
{dashboard.recentFiles.map((f) => (
|
||||
<p key={f.id} className="text-sm">
|
||||
{f.originalName}
|
||||
</p>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget title="次回ミーティング" empty="予定なし">
|
||||
{dashboard.nextMeeting && (
|
||||
<p className="text-sm">
|
||||
{dashboard.nextMeeting.title}({dashboard.nextMeeting.startAt})
|
||||
</p>
|
||||
)}
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget title="マイルストーン進捗" empty="ありません">
|
||||
{dashboard.milestones.map((m) => (
|
||||
<div key={m.id}>
|
||||
<p className="text-sm">
|
||||
{m.title} - {m.progress}%
|
||||
</p>
|
||||
<div className="h-1.5 w-full rounded bg-gray-200">
|
||||
<div
|
||||
className="h-1.5 rounded bg-blue-500"
|
||||
style={{ width: `${m.progress}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
|
||||
<DashboardWidget
|
||||
title="進行中ToDo"
|
||||
empty="ToDo機能は後続マイルストーンで実装されます"
|
||||
/>
|
||||
<DashboardWidget
|
||||
title="最新チャット"
|
||||
empty="チャット機能は後続マイルストーンで実装されます"
|
||||
/>
|
||||
<DashboardWidget
|
||||
title="最新掲示板"
|
||||
empty="掲示板機能は後続マイルストーンで実装されます"
|
||||
/>
|
||||
<DashboardWidget
|
||||
title="最近のアクティビティ"
|
||||
empty="アクティビティログは後続マイルストーンで実装されます"
|
||||
/>
|
||||
title="最近のアクティビティ (10件)"
|
||||
empty="ありません"
|
||||
>
|
||||
{dashboard.recentActivity.map((l) => (
|
||||
<p key={l.id} className="text-sm">
|
||||
{l.action}({l.targetType})
|
||||
</p>
|
||||
))}
|
||||
</DashboardWidget>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
93
app/projects/[projectId]/search/page.tsx
Normal file
93
app/projects/[projectId]/search/page.tsx
Normal file
@ -0,0 +1,93 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
import { getCurrentUser, toPublicUser } from '@/lib/auth/getCurrentUser';
|
||||
import { createSearchService, createProjectService } from '@/lib/api/services';
|
||||
import { Header } from '@/components/layout/Header';
|
||||
import { ProjectNav } from '@/components/layout/ProjectNav';
|
||||
import { SearchForm } from '@/components/project/SearchForm';
|
||||
import { ForbiddenError, NotFoundError } from '@/lib/errors';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
const TYPE_LINKS: Record<string, (id: number, projectId: number) => string> = {
|
||||
thread: (id, p) => `/projects/${p}/board/${id}`,
|
||||
note: (id, p) => `/projects/${p}/notes/${id}`,
|
||||
todo: (_id, p) => `/projects/${p}/todos`,
|
||||
file: (id) => `/api/files/${id}/download`,
|
||||
event: (_id, p) => `/projects/${p}/calendar`,
|
||||
meeting: (_id, p) => `/projects/${p}/meetings`,
|
||||
milestone: (_id, p) => `/projects/${p}/milestones`,
|
||||
chat: (_id, p) => `/projects/${p}/chat`,
|
||||
};
|
||||
|
||||
export default async function SearchPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ projectId: string }>;
|
||||
searchParams: Promise<{ q?: string; type?: string }>;
|
||||
}) {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) redirect('/login');
|
||||
const { projectId } = await params;
|
||||
const { q, type } = await searchParams;
|
||||
|
||||
const projectService = createProjectService();
|
||||
let project: Awaited<ReturnType<typeof projectService.getProject>>;
|
||||
try {
|
||||
project = projectService.getProject(user.id, Number(projectId));
|
||||
} catch (error) {
|
||||
if (error instanceof ForbiddenError || error instanceof NotFoundError) {
|
||||
redirect('/dashboard');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
const searchService = createSearchService();
|
||||
const results = q
|
||||
? searchService.search(user.id, project.id, {
|
||||
q,
|
||||
type: type as never,
|
||||
})
|
||||
: [];
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<Header user={toPublicUser(user)} />
|
||||
<ProjectNav projectId={project.id} active="search" />
|
||||
<main className="mx-auto max-w-3xl space-y-6 p-6">
|
||||
<h1 className="text-2xl font-bold">検索</h1>
|
||||
<SearchForm
|
||||
projectId={project.id}
|
||||
initialQ={q ?? ''}
|
||||
initialType={type ?? ''}
|
||||
/>
|
||||
<section className="space-y-2">
|
||||
{q && results.length === 0 && (
|
||||
<p className="text-sm text-gray-400">該当する結果はありません。</p>
|
||||
)}
|
||||
{results.map((r) => {
|
||||
const href =
|
||||
TYPE_LINKS[r.type]?.(r.id, project.id) ??
|
||||
`/projects/${project.id}`;
|
||||
return (
|
||||
<a
|
||||
key={`${r.type}-${r.id}`}
|
||||
href={href}
|
||||
className="block rounded border bg-white p-3 shadow-sm hover:shadow-md"
|
||||
data-testid={`search-result-${r.type}-${r.id}`}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="font-medium text-gray-800">{r.title}</span>
|
||||
<span className="rounded bg-gray-100 px-2 py-0.5 text-xs">
|
||||
{r.type}
|
||||
</span>
|
||||
</div>
|
||||
<p className="mt-1 text-xs text-gray-500">{r.snippet}</p>
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user