feat(m5): notifications & activity log foundation
- Expand NotificationRepository (unread list paginated, count, markRead ownership-scoped); new ActivityLogRepository (create, findByProject paginated) with deterministic created_at+id ordering - NotificationService (notifyOnEvent, resolveTargets for 8 event types, injectable SseBroadcaster for M8) + ActivityLogService (logActivity, listByProject) - NotificationEvent/SseEvent/SseBroadcaster types in lib/types - APIs: GET /api/notifications, POST /api/notifications/:id/read, GET /api/projects/:projectId/activity - Screens: notifications list + MarkReadButton, NotificationBadge in Header, project activity page + ProjectNav link - Unit tests for both repositories and services (28 new)
This commit is contained in:
25
app/api/notifications/[id]/read/route.ts
Normal file
25
app/api/notifications/[id]/read/route.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getCurrentUser } from '@/lib/auth/getCurrentUser';
|
||||
import { createNotificationService } from '@/lib/api/services';
|
||||
import { UnauthorizedError, NotFoundError } from '@/lib/errors';
|
||||
import { handleApiError } from '@/lib/api/handleError';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
export async function POST(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) {
|
||||
return handleApiError(new UnauthorizedError());
|
||||
}
|
||||
const { id } = await params;
|
||||
|
||||
const service = createNotificationService();
|
||||
const updated = service.markRead(Number(id), user.id);
|
||||
if (!updated) {
|
||||
return handleApiError(new NotFoundError('Notification', id));
|
||||
}
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
19
app/api/notifications/route.ts
Normal file
19
app/api/notifications/route.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getCurrentUser } from '@/lib/auth/getCurrentUser';
|
||||
import { createNotificationService } 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) {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) {
|
||||
return handleApiError(new UnauthorizedError());
|
||||
}
|
||||
|
||||
const page = Number(request.nextUrl.searchParams.get('page') ?? '1') || 1;
|
||||
const service = createNotificationService();
|
||||
const result = service.listUnread(user.id, page);
|
||||
return NextResponse.json(result);
|
||||
}
|
||||
34
app/api/projects/[projectId]/activity/route.ts
Normal file
34
app/api/projects/[projectId]/activity/route.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getCurrentUser } from '@/lib/auth/getCurrentUser';
|
||||
import {
|
||||
createProjectService,
|
||||
createActivityLogService,
|
||||
} 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;
|
||||
|
||||
// メンバーシップ確認(非参加者は403)
|
||||
const projectService = createProjectService();
|
||||
try {
|
||||
projectService.getProject(user.id, Number(projectId));
|
||||
} catch (error) {
|
||||
return handleApiError(error);
|
||||
}
|
||||
|
||||
const page = Number(request.nextUrl.searchParams.get('page') ?? '1') || 1;
|
||||
const activityService = createActivityLogService();
|
||||
const result = activityService.listByProject(Number(projectId), page);
|
||||
return NextResponse.json(result);
|
||||
}
|
||||
Reference in New Issue
Block a user