welcome page

with profile form
This commit is contained in:
dimitar committed 2025-11-07 21:16:03 +01:00
1 parent 3a554ba434
commit e287e55f1f
6 files changed
+520 -4

No files matched your search

@@ -0,0 +1,66 @@
import { NextRequest, NextResponse } from 'next/server'
import { users, fitnessProfiles } from '../../../../lib/database'
export async function POST(request: NextRequest) {
try {
const profileData: FitnessProfile = await request.json()
if (!profileData.userId || !profileData.height || !profileData.weight || !profileData.age) {
return NextResponse.json(
{ error: 'Missing required fields' },
{ status: 400 }
)
}
// For demo purposes, we'll allow profile creation without strict user validation
// In production, you'd validate against a persistent database
console.log('Creating fitness profile for user ID:', profileData.userId)
const existingProfile = fitnessProfiles.find(p => p.userId === profileData.userId)
if (existingProfile) {
Object.assign(existingProfile, profileData)
} else {
fitnessProfiles.push(profileData)
}
return NextResponse.json(
{
message: 'Fitness profile saved successfully',
profile: profileData
},
{ status: 201 }
)
} catch (error) {
console.error('Fitness profile error:', error)
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
)
}
}
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url)
const userId = searchParams.get('userId')
if (userId) {
const profile = fitnessProfiles.find(p => p.userId === userId)
if (!profile) {
return NextResponse.json(
{ error: 'Profile not found' },
{ status: 404 }
)
}
return NextResponse.json({ profile })
}
return NextResponse.json({ profiles: fitnessProfiles })
} catch (error) {
console.error('Get fitness profiles error:', error)
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
)
}
}
+15 -1
View File
@@ -18,6 +18,20 @@ export interface Client {
joinDate: Date
}
export interface FitnessProfile {
userId: string
height: string
weight: string
age: string
gender: 'male' | 'female' | 'other'
activityLevel: 'sedentary' | 'light' | 'moderate' | 'active' | 'very_active'
fitnessGoals: string[]
exerciseHabits: string
dietHabits: string
medicalConditions: string
}
// In-memory database
export const users: User[] = []
export const clients: Client[] = []
export const clients: Client[] = []
export const fitnessProfiles: FitnessProfile[] = []