-
Notifications
You must be signed in to change notification settings - Fork 1
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 #18 from codeforpakistan/pehchan-integration
Pehchan integration
- Loading branch information
Showing
44 changed files
with
5,508 additions
and
379 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,29 @@ | ||
name: Build Check | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '18' | ||
cache: 'npm' | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Build project | ||
run: npm run build |
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
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
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 GET(request: Request) { | ||
const authHeader = request.headers.get('Authorization') | ||
|
||
if (!authHeader) { | ||
return NextResponse.json({ error: 'No authorization header' }, { status: 401 }) | ||
} | ||
|
||
try { | ||
const response = await fetch(`${process.env.NEXT_PUBLIC_PEHCHAN_URL}/api/auth/userinfo`, { | ||
headers: { | ||
'Authorization': authHeader | ||
} | ||
}) | ||
|
||
if (!response.ok) { | ||
throw new Error('Failed to fetch user info') | ||
} | ||
|
||
const data = await response.json() | ||
console.log('Pehchan userinfo response:', data) | ||
return NextResponse.json(data) | ||
} catch (error) { | ||
console.error('User info error:', error) | ||
return NextResponse.json( | ||
{ error: 'Failed to fetch user info' }, | ||
{ 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,95 @@ | ||
import { db } from '@/lib/db' | ||
import { chatThreads } from '@/lib/db/schema/chat-threads' | ||
import { eq, and } from 'drizzle-orm' | ||
import { NextResponse } from 'next/server' | ||
|
||
export async function GET( | ||
request: Request, | ||
{ params }: { params: { id: string } } | ||
) { | ||
const { searchParams } = new URL(request.url) | ||
const pehchanId = searchParams.get('pehchan_id') | ||
|
||
if (!pehchanId) { | ||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
} | ||
|
||
try { | ||
const [thread] = await db | ||
.select() | ||
.from(chatThreads) | ||
.where( | ||
and( | ||
eq(chatThreads.id, parseInt(params.id)), | ||
eq(chatThreads.pehchanId, pehchanId) | ||
) | ||
) | ||
|
||
return NextResponse.json(thread) | ||
} catch (error) { | ||
return NextResponse.json({ error: 'Failed to fetch thread' }, { status: 500 }) | ||
} | ||
} | ||
|
||
export async function PATCH( | ||
request: Request, | ||
{ params }: { params: { id: string } } | ||
) { | ||
const { messages, title, pehchanId } = await request.json() | ||
|
||
if (!pehchanId) { | ||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
} | ||
|
||
try { | ||
const [thread] = await db | ||
.update(chatThreads) | ||
.set({ | ||
messages, | ||
title, | ||
updatedAt: new Date() | ||
}) | ||
.where( | ||
and( | ||
eq(chatThreads.id, parseInt(params.id)), | ||
eq(chatThreads.pehchanId, pehchanId) | ||
) | ||
) | ||
.returning() | ||
|
||
return NextResponse.json(thread) | ||
} catch (error) { | ||
return NextResponse.json({ error: 'Failed to update thread' }, { status: 500 }) | ||
} | ||
} | ||
|
||
export async function DELETE( | ||
request: Request, | ||
{ params }: { params: { id: string } } | ||
) { | ||
const { pehchanId } = await request.json() | ||
|
||
if (!pehchanId) { | ||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
} | ||
|
||
try { | ||
const [deletedThread] = await db | ||
.delete(chatThreads) | ||
.where( | ||
and( | ||
eq(chatThreads.id, parseInt(params.id)), | ||
eq(chatThreads.pehchanId, pehchanId) | ||
) | ||
) | ||
.returning() | ||
|
||
return NextResponse.json(deletedThread) | ||
} catch (error) { | ||
console.error('Error deleting thread:', error) | ||
return NextResponse.json( | ||
{ error: 'Failed to delete thread' }, | ||
{ 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,51 @@ | ||
import { db } from '@/lib/db' | ||
import { chatThreads } from '@/lib/db/schema/chat-threads' | ||
import { eq } from 'drizzle-orm' | ||
import { NextResponse } from 'next/server' | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams } = new URL(request.url) | ||
const pehchanId = searchParams.get('pehchan_id') | ||
|
||
if (!pehchanId) { | ||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
} | ||
|
||
try { | ||
const threads = await db | ||
.select() | ||
.from(chatThreads) | ||
.where(eq(chatThreads.pehchanId, pehchanId)) | ||
.orderBy(chatThreads.updatedAt) | ||
|
||
return NextResponse.json(threads) | ||
} catch (error) { | ||
return NextResponse.json({ error: 'Failed to fetch threads' }, { status: 500 }) | ||
} | ||
} | ||
|
||
export async function POST(request: Request) { | ||
const { pehchanId, title = 'New Chat', messages = [] } = await request.json() | ||
console.log('Creating thread:', { pehchanId, title, messages }) | ||
|
||
if (!pehchanId) { | ||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) | ||
} | ||
|
||
try { | ||
const [thread] = await db | ||
.insert(chatThreads) | ||
.values({ | ||
pehchanId, | ||
title, | ||
messages | ||
}) | ||
.returning() | ||
|
||
console.log('Created thread:', thread) | ||
return NextResponse.json(thread) | ||
} catch (error) { | ||
console.error('Failed to create thread:', error) | ||
return NextResponse.json({ error: 'Failed to create thread' }, { status: 500 }) | ||
} | ||
} |
Oops, something went wrong.