Nicholai e50c1d9662
Some checks failed
CI / build-and-test (pull_request) Has been cancelled
updated the following components to use the API instead of hardcoded data:
### 1. __artists-grid.tsx__ (Main Artist Browsing)

- Uses  hook from
- Fetches from  endpoint
- Includes loading states, error handling, and filtering
- __Impact:__ Primary artist browsing experience now fully API-driven

### 2. __artist-portfolio.tsx__ (Individual Artist Pages)

- Uses  hook
- Fetches from  endpoint
- Fixed all TypeScript errors (changed image ID from number to string)
- Added loading/error states
- __Impact:__ Artist detail pages now fully API-driven

### 3. __booking-form.tsx__ (Artist Selection Dropdown)

- Uses  hook for artist selection
- Updated to use API data structure ( array, , etc.)
- Added loading state for dropdown
- __Impact:__ Booking flow now uses real artist data

## ⚠️ REMAINING (Decorative/Marketing Components)

Two complex components still use hardcoded :

### 4. __artists-section.tsx__ (Homepage Hero - 348 lines)

- Homepage marketing section with complex parallax scrolling
- Uses hardcoded artist data for visual cards
- __Non-blocking:__ This is a decorative homepage element

### 5. __artists-page-section.tsx__ (Artists Page Section - 413 lines)

- Full-page artists showcase with parallax effects
- Uses hardcoded artist data for visual layout
- __Non-blocking:__ Alternative to artists-grid.tsx (which IS using API)

##
2025-10-06 04:44:08 -06:00

117 lines
3.0 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server"
import { requireAuth } from "@/lib/auth"
import { UserRole } from "@/types/database"
import { getArtistByUserId, updateArtist } from "@/lib/db"
export const dynamic = "force-dynamic";
// GET /api/artists/me - Get current logged-in artist's profile
export async function GET(
request: NextRequest,
{ params }: { params?: any } = {},
context?: any
) {
try {
// Require artist authentication
const session = await requireAuth(UserRole.ARTIST)
// Fetch artist data by user ID
const artist = await getArtistByUserId(session.user.id, context?.env)
if (!artist) {
return NextResponse.json(
{ error: "Artist profile not found" },
{ status: 404 }
)
}
return NextResponse.json(artist)
} catch (error) {
console.error("Error fetching artist profile:", error)
if (error instanceof Error) {
if (error.message.includes("Authentication required")) {
return NextResponse.json(
{ error: "Authentication required" },
{ status: 401 }
)
}
if (error.message.includes("Insufficient permissions")) {
return NextResponse.json(
{ error: "You must be an artist to access this endpoint" },
{ status: 403 }
)
}
}
return NextResponse.json(
{ error: "Failed to fetch artist profile" },
{ status: 500 }
)
}
}
// PUT /api/artists/me - Update current logged-in artist's profile
export async function PUT(
request: NextRequest,
{ params }: { params?: any } = {},
context?: any
) {
try {
// Require artist authentication
const session = await requireAuth(UserRole.ARTIST)
// Fetch current artist data
const artist = await getArtistByUserId(session.user.id, context?.env)
if (!artist) {
return NextResponse.json(
{ error: "Artist profile not found" },
{ status: 404 }
)
}
// Parse request body
const body = await request.json()
// Artists can only update specific fields
const allowedUpdates = {
bio: body.bio,
specialties: body.specialties,
instagramHandle: body.instagramHandle,
hourlyRate: body.hourlyRate
}
// Update artist profile
const updatedArtist = await updateArtist(
artist.id,
allowedUpdates,
context?.env
)
return NextResponse.json(updatedArtist)
} catch (error) {
console.error("Error updating artist profile:", error)
if (error instanceof Error) {
if (error.message.includes("Authentication required")) {
return NextResponse.json(
{ error: "Authentication required" },
{ status: 401 }
)
}
if (error.message.includes("Insufficient permissions")) {
return NextResponse.json(
{ error: "You must be an artist to access this endpoint" },
{ status: 403 }
)
}
}
return NextResponse.json(
{ error: "Failed to update artist profile" },
{ status: 500 }
)
}
}