pedometar

problem with expogo, should be sorted before build
This commit is contained in:
dimitar committed 2025-11-28 18:08:52 +01:00
1 parent b0d751540e
commit 24ed0b6190
16 files changed
+1676 -64

No files matched your search

Binary file not shown.
@@ -0,0 +1,31 @@
import { NextRequest, NextResponse } from "next/server";
import { auth } from "@clerk/nextjs/server";
export async function GET(req: NextRequest) {
try {
const { userId } = await auth();
if (!userId) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const { searchParams } = new URL(req.url);
const date = searchParams.get("date") || new Date().toISOString().split('T')[0];
// TODO: Fetch from database when activity_logs methods are added to IDatabase
console.log(`Fetching daily activity for user ${userId} on ${date}`);
// Return mock data for now
return NextResponse.json({
steps: 0,
calories: 0,
duration: 0,
date
});
} catch (error) {
console.error("Error fetching daily activity:", error);
return NextResponse.json(
{ error: "Failed to fetch daily activity" },
{ status: 500 }
);
}
}
@@ -0,0 +1,24 @@
import { NextRequest, NextResponse } from "next/server";
import { auth } from "@clerk/nextjs/server";
export async function POST(req: NextRequest) {
try {
const { userId } = await auth();
if (!userId) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const { steps, timestamp } = await req.json();
// TODO: Implement database persistence when activity_logs methods are added to IDatabase
console.log(`Syncing steps for user ${userId}: ${steps} steps at ${timestamp}`);
return NextResponse.json({ success: true, steps });
} catch (error) {
console.error("Error syncing steps:", error);
return NextResponse.json(
{ error: "Failed to sync steps" },
{ status: 500 }
);
}
}
@@ -0,0 +1,42 @@
import { NextRequest, NextResponse } from "next/server";
import { auth } from "@clerk/nextjs/server";
import { getDatabase } from "@/lib/database";
export async function GET(req: NextRequest) {
try {
const { userId } = await auth();
// Return empty array if not authenticated (for testing)
if (!userId) {
return NextResponse.json([]);
}
const db = await getDatabase();
// Fetch recent fitness goals (last 5)
const recentGoals = await db.getFitnessGoalsByUserId(userId);
// Take only the 5 most recent and transform to format expected by mobile app
const activities = recentGoals.slice(0, 5).map((goal) => ({
title: goal.title,
subtitle: new Date(goal.createdAt).toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
}),
duration: 45, // Mock duration for now
icon: goal.goalType === 'strength_milestone' ? 'barbell' :
goal.goalType === 'endurance_target' ? 'bicycle' :
'fitness',
gradient: goal.goalType === 'strength_milestone' ? 'primary' :
goal.goalType === 'endurance_target' ? 'success' :
'purple',
}));
return NextResponse.json(activities);
} catch (error) {
console.error("Error fetching recent activities:", error);
return NextResponse.json([], { status: 200 }); // Return empty array on error
}
}
@@ -24,7 +24,7 @@ export async function POST(request: NextRequest) {
// Check if profile already exists
const existingProfile = await db.getFitnessProfileByUserId(profileData.userId)
let profile
if (existingProfile) {
profile = await db.updateFitnessProfile(profileData.userId, profileData)
@@ -33,7 +33,7 @@ export async function POST(request: NextRequest) {
}
return NextResponse.json(
{
{
message: 'Fitness profile saved successfully',
profile
},
@@ -50,11 +50,12 @@ export async function POST(request: NextRequest) {
export async function GET(request: NextRequest) {
try {
const db = await getDatabase()
const { searchParams } = new URL(request.url)
const userId = searchParams.get('userId')
// If userId is provided, get specific profile
if (userId) {
const db = await getDatabase()
const profile = await db.getFitnessProfileByUserId(userId)
if (!profile) {
return NextResponse.json(
@@ -62,11 +63,24 @@ export async function GET(request: NextRequest) {
{ status: 404 }
)
}
return NextResponse.json({ profile })
// Return profile with mock activity data for now
// TODO: Fetch real activity data from activity_logs table
return NextResponse.json({
profile,
steps: 0,
calories: 0,
duration: 0
})
}
const profiles = await db.getAllFitnessProfiles()
return NextResponse.json({ profiles })
// For mobile app: return activity data without userId param
// This is a simplified endpoint for the mobile ActivityWidget
return NextResponse.json({
steps: 0,
calories: 0,
duration: 0
})
} catch (error) {
console.error('Get fitness profiles error:', error)
return NextResponse.json(