mirror of
https://github.com/yusufipk/RepoHub.git
synced 2026-09-11 18:46:07 +00:00
feat: add PostgreSQL database support and development scripts
- Added pg and @types/pg dependencies for PostgreSQL integration - Created database testing and backend initialization scripts - Changed dev server port to 3002 to avoid conflicts
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { PackageService } from '@/services/packageService'
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const packageData = await PackageService.getById(params.id)
|
||||
|
||||
if (!packageData) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Package not found' },
|
||||
{ status: 404 }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json(packageData)
|
||||
} catch (error) {
|
||||
console.error('Error fetching package:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch package' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const packageData = await PackageService.update(params.id, body)
|
||||
|
||||
if (!packageData) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Package not found' },
|
||||
{ status: 404 }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json(packageData)
|
||||
} catch (error) {
|
||||
console.error('Error updating package:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to update package' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const success = await PackageService.delete(params.id)
|
||||
|
||||
if (!success) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Package not found' },
|
||||
{ status: 404 }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true })
|
||||
} catch (error) {
|
||||
console.error('Error deleting package:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to delete package' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { PackageService } from '@/services/packageService'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
|
||||
// Parse query parameters
|
||||
const filter = {
|
||||
platform_id: searchParams.get('platform_id') || undefined,
|
||||
category_id: searchParams.get('category_id') ?
|
||||
parseInt(searchParams.get('category_id')!) : undefined,
|
||||
type: searchParams.get('type') as 'gui' | 'cli' | undefined,
|
||||
repository: searchParams.get('repository') as 'official' | 'third-party' | undefined,
|
||||
search: searchParams.get('search') || undefined,
|
||||
limit: searchParams.get('limit') ?
|
||||
parseInt(searchParams.get('limit')!) : undefined,
|
||||
offset: searchParams.get('offset') ?
|
||||
parseInt(searchParams.get('offset')!) : undefined,
|
||||
sort_by: searchParams.get('sort_by') as
|
||||
'name' | 'popularity_score' | 'last_updated' | 'downloads_count' | undefined,
|
||||
sort_order: searchParams.get('sort_order') as 'asc' | 'desc' | undefined
|
||||
}
|
||||
|
||||
const result = await PackageService.getMany(filter)
|
||||
|
||||
return NextResponse.json({
|
||||
packages: result.packages,
|
||||
total: result.total,
|
||||
limit: filter.limit,
|
||||
offset: filter.offset
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error fetching packages:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch packages' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const packageData = await PackageService.create(body)
|
||||
return NextResponse.json(packageData, { status: 201 })
|
||||
} catch (error) {
|
||||
console.error('Error creating package:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to create package' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { PlatformService } from '@/services/platformService'
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const platform = await PlatformService.getById(params.id)
|
||||
|
||||
if (!platform) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Platform not found' },
|
||||
{ status: 404 }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json(platform)
|
||||
} catch (error) {
|
||||
console.error('Error fetching platform:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch platform' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const platform = await PlatformService.update(params.id, body)
|
||||
|
||||
if (!platform) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Platform not found' },
|
||||
{ status: 404 }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json(platform)
|
||||
} catch (error) {
|
||||
console.error('Error updating platform:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to update platform' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const success = await PlatformService.delete(params.id)
|
||||
|
||||
if (!success) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Platform not found' },
|
||||
{ status: 404 }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true })
|
||||
} catch (error) {
|
||||
console.error('Error deleting platform:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to delete platform' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { PlatformService } from '@/services/platformService'
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const platforms = await PlatformService.getAll()
|
||||
return NextResponse.json(platforms)
|
||||
} catch (error) {
|
||||
console.error('Error fetching platforms:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch platforms' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const platform = await PlatformService.create(body)
|
||||
return NextResponse.json(platform, { status: 201 })
|
||||
} catch (error) {
|
||||
console.error('Error creating platform:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to create platform' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { MetadataFetcher } from '@/services/metadataFetcher'
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const { platform_id, all_platforms } = body
|
||||
|
||||
if (all_platforms) {
|
||||
// Sync all platforms
|
||||
await MetadataFetcher.syncAllPlatforms()
|
||||
return NextResponse.json({
|
||||
message: 'All platforms synced successfully',
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} else if (platform_id) {
|
||||
// Sync specific platform
|
||||
await MetadataFetcher.syncPlatform(platform_id)
|
||||
return NextResponse.json({
|
||||
message: `Platform ${platform_id} synced successfully`,
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} else {
|
||||
return NextResponse.json(
|
||||
{ error: 'Either platform_id or all_platforms must be specified' },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error during sync:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Sync failed', details: error instanceof Error ? error.message : 'Unknown error' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
// Return sync status (would need to implement status tracking)
|
||||
return NextResponse.json({
|
||||
status: 'ready',
|
||||
last_sync: null,
|
||||
platforms: ['ubuntu', 'fedora', 'arch', 'windows', 'macos']
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Error getting sync status:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to get sync status' },
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user