-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from rtjord/pulkit-frontend
Added changes for connecting end-points
- Loading branch information
Showing
11 changed files
with
4,225 additions
and
3,475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
// GET handler for downloading package and getting package info | ||
export async function GET( | ||
request: Request, | ||
{ params }: { params: { id: string } } | ||
) { | ||
try { | ||
const id = params.id; | ||
// Check if this is a rate, cost, or download request | ||
const { pathname } = new URL(request.url); | ||
|
||
let endpoint = `/package/${id}`; | ||
if (pathname.endsWith('/rate')) { | ||
endpoint = `/package/${id}/rate`; | ||
} else if (pathname.endsWith('/cost')) { | ||
endpoint = `/package/${id}/cost`; | ||
} | ||
|
||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}${endpoint}`, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Authorization': '' | ||
} | ||
}); | ||
|
||
console.log(`${endpoint} Status:`, response.status); | ||
|
||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
throw new Error(errorData.message || response.statusText); | ||
} | ||
|
||
const data = await response.json(); | ||
return NextResponse.json(data); | ||
} catch (error) { | ||
console.error('Package proxy error:', error); | ||
return NextResponse.json( | ||
{ error: error instanceof Error ? error.message : 'Failed to process request' }, | ||
{ status: 500 } | ||
); | ||
} | ||
} | ||
|
||
// POST handler for updating package | ||
export async function POST( | ||
request: Request, | ||
{ params }: { params: { id: string } } | ||
) { | ||
try { | ||
const id = params.id; | ||
const body = await request.json(); | ||
|
||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/package/${id}`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Authorization': '' | ||
}, | ||
body: JSON.stringify(body) | ||
}); | ||
|
||
console.log('Update Package Status:', response.status); | ||
|
||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
throw new Error(errorData.message || response.statusText); | ||
} | ||
|
||
const data = await response.json(); | ||
return NextResponse.json(data); | ||
} catch (error) { | ||
console.error('Package update error:', error); | ||
return NextResponse.json( | ||
{ error: error instanceof Error ? error.message : 'Failed to update package' }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function POST(request: Request) { | ||
try { | ||
const packageData = await request.json(); | ||
|
||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/package`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Authorization': '' | ||
}, | ||
body: JSON.stringify(packageData) | ||
}); | ||
|
||
const data = await response.json(); | ||
|
||
if (!response.ok) { | ||
console.error('API Error:', data); | ||
return NextResponse.json(data, { status: response.status }); | ||
} | ||
|
||
return NextResponse.json(data); | ||
} catch (error) { | ||
console.error('Error in package proxy:', error); | ||
return NextResponse.json( | ||
{ error: 'Failed to process package upload' }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function GET(request: Request) { | ||
try { | ||
const { searchParams } = new URL(request.url); | ||
const type = searchParams.get('type'); | ||
const query = searchParams.get('q'); | ||
|
||
if (!query) { | ||
return NextResponse.json({ error: 'Query parameter is required' }, { status: 400 }); | ||
} | ||
|
||
let response; | ||
|
||
switch (type) { | ||
case 'name': | ||
response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/byName/${encodeURIComponent(query)}`, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Authorization': '' | ||
} | ||
}); | ||
break; | ||
|
||
case 'id': | ||
response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/package/${encodeURIComponent(query)}`, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Authorization': '' | ||
} | ||
}); | ||
break; | ||
|
||
default: | ||
return NextResponse.json({ error: 'Invalid search type' }, { status: 400 }); | ||
} | ||
|
||
console.log(`${type.toUpperCase()} Search Status:`, response.status); | ||
const data = await response.json(); | ||
return NextResponse.json(data); | ||
} catch (error) { | ||
console.error('Search proxy error:', error); | ||
return NextResponse.json({ error: 'Failed to process search request' }, { status: 500 }); | ||
} | ||
} | ||
|
||
export async function POST(request: Request) { | ||
try { | ||
const { searchParams } = new URL(request.url); | ||
const type = searchParams.get('type'); | ||
const body = await request.json(); | ||
|
||
if (!body) { | ||
return NextResponse.json({ error: 'Request body is required' }, { status: 400 }); | ||
} | ||
|
||
let response; | ||
|
||
switch (type) { | ||
case 'regex': | ||
const regexQuery = body.query.includes('.*') ? body.query : `.*${body.query}.*`; | ||
response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/package/byRegEx`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Authorization': '' | ||
}, | ||
body: JSON.stringify({ | ||
RegEx: regexQuery | ||
}) | ||
}); | ||
break; | ||
|
||
case 'smart': | ||
response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/recommend`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Authorization': '' | ||
}, | ||
body: JSON.stringify({ Description: body.query }) | ||
}); | ||
break; | ||
|
||
default: | ||
return NextResponse.json({ error: 'Invalid search type' }, { status: 400 }); | ||
} | ||
|
||
console.log(`${type.toUpperCase()} Search Status:`, response.status); | ||
const data = await response.json(); | ||
return NextResponse.json(data); | ||
} catch (error) { | ||
console.error('Search proxy error:', error); | ||
return NextResponse.json({ error: 'Failed to process search request' }, { status: 500 }); | ||
} | ||
} |
Oops, something went wrong.