wip
This commit is contained in:
90
apps/website/app/api/auth/complete-onboarding/route.ts
Normal file
90
apps/website/app/api/auth/complete-onboarding/route.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAuthService } from '@/lib/auth';
|
||||
import { getDriverRepository } from '@/lib/di-container';
|
||||
import { Driver } from '@gridpilot/racing';
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const authService = getAuthService();
|
||||
const session = await authService.getCurrentSession();
|
||||
|
||||
if (!session) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Not authenticated' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { firstName, lastName, displayName, country, timezone, bio } = body;
|
||||
|
||||
// Validation
|
||||
if (!firstName || !firstName.trim()) {
|
||||
return NextResponse.json(
|
||||
{ error: 'First name is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
if (!lastName || !lastName.trim()) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Last name is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
if (!displayName || displayName.trim().length < 3) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Display name must be at least 3 characters' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
if (!country) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Country is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const driverRepo = getDriverRepository();
|
||||
|
||||
// Check if user already has a driver profile
|
||||
if (session.user.primaryDriverId) {
|
||||
const existingDriver = await driverRepo.findById(session.user.primaryDriverId);
|
||||
if (existingDriver) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Driver profile already exists' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the driver profile
|
||||
const driverId = crypto.randomUUID();
|
||||
const driver = Driver.create({
|
||||
id: driverId,
|
||||
iracingId: '', // Will be set later via OAuth
|
||||
name: displayName.trim(),
|
||||
country: country,
|
||||
bio: bio || undefined,
|
||||
});
|
||||
|
||||
await driverRepo.create(driver);
|
||||
|
||||
// Update user's primary driver ID in session
|
||||
// Note: This would typically update the user record and refresh the session
|
||||
// For now we'll just return success and let the client handle navigation
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
driverId: driverId,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Onboarding error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: error instanceof Error ? error.message : 'Failed to complete onboarding' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
84
apps/website/app/api/avatar/generate/route.ts
Normal file
84
apps/website/app/api/avatar/generate/route.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAuthService } from '@/lib/auth';
|
||||
import {
|
||||
DemoFaceValidationAdapter,
|
||||
DemoAvatarGenerationAdapter,
|
||||
InMemoryAvatarGenerationRepository
|
||||
} from '@gridpilot/demo-infrastructure';
|
||||
import { RequestAvatarGenerationUseCase } from '@gridpilot/media';
|
||||
|
||||
// Create singleton instances
|
||||
const faceValidation = new DemoFaceValidationAdapter();
|
||||
const avatarGeneration = new DemoAvatarGenerationAdapter();
|
||||
const avatarRepository = new InMemoryAvatarGenerationRepository();
|
||||
|
||||
const requestAvatarGenerationUseCase = new RequestAvatarGenerationUseCase(
|
||||
avatarRepository,
|
||||
faceValidation,
|
||||
avatarGeneration
|
||||
);
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const authService = getAuthService();
|
||||
const session = await authService.getCurrentSession();
|
||||
|
||||
if (!session) {
|
||||
return NextResponse.json(
|
||||
{ success: false, errorMessage: 'Not authenticated' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { facePhotoData, suitColor } = body;
|
||||
|
||||
if (!facePhotoData) {
|
||||
return NextResponse.json(
|
||||
{ success: false, errorMessage: 'No face photo provided' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
if (!suitColor) {
|
||||
return NextResponse.json(
|
||||
{ success: false, errorMessage: 'No suit color selected' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Extract base64 data if it's a data URL
|
||||
let base64Data = facePhotoData;
|
||||
if (facePhotoData.startsWith('data:')) {
|
||||
base64Data = facePhotoData.split(',')[1] || facePhotoData;
|
||||
}
|
||||
|
||||
const result = await requestAvatarGenerationUseCase.execute({
|
||||
userId: session.user.id,
|
||||
facePhotoData: base64Data,
|
||||
suitColor,
|
||||
});
|
||||
|
||||
if (result.status === 'failed') {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
errorMessage: result.errorMessage,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
requestId: result.requestId,
|
||||
avatarUrls: result.avatarUrls,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Avatar generation error:', error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
errorMessage: error instanceof Error ? error.message : 'Failed to generate avatars'
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
40
apps/website/app/api/avatar/validate-face/route.ts
Normal file
40
apps/website/app/api/avatar/validate-face/route.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { DemoFaceValidationAdapter } from '@gridpilot/demo-infrastructure';
|
||||
|
||||
const faceValidation = new DemoFaceValidationAdapter();
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { imageData } = body;
|
||||
|
||||
if (!imageData) {
|
||||
return NextResponse.json(
|
||||
{ isValid: false, errorMessage: 'No image data provided' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Extract base64 data if it's a data URL
|
||||
let base64Data = imageData;
|
||||
if (imageData.startsWith('data:')) {
|
||||
base64Data = imageData.split(',')[1] || imageData;
|
||||
}
|
||||
|
||||
const result = await faceValidation.validateFacePhoto(base64Data);
|
||||
|
||||
return NextResponse.json(result);
|
||||
} catch (error) {
|
||||
console.error('Face validation error:', error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
isValid: false,
|
||||
hasFace: false,
|
||||
faceCount: 0,
|
||||
confidence: 0,
|
||||
errorMessage: 'Failed to validate photo'
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user