Skip to content

Commit 366e703

Browse files
Updated reddit lib to use new db.
1 parent 6639f8d commit 366e703

File tree

3 files changed

+1
-74
lines changed

3 files changed

+1
-74
lines changed

src/app/api/reddit/messages/fetch/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NextResponse } from 'next/server'
2-
import { checkRedditMessages } from '@/lib/reddit'
2+
import { checkRedditMessages } from '@/lib/jobs/reddit'
33

44
export async function GET() {
55
try {
Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +0,0 @@
1-
import { NextRequest, NextResponse } from 'next/server'
2-
import { fetchRedditPosts, storePosts } from '@/lib/reddit'
3-
import webpush from 'web-push'
4-
import prisma from '@/lib/db'
5-
6-
// List of subreddits to monitor for new posts
7-
const SUBREDDITS = [
8-
'forhire',
9-
'jobs4bitcoins',
10-
'freelance',
11-
'remotejs',
12-
'jobs4dogecoins',
13-
'jobs4crypto',
14-
]
15-
16-
// Set up web-push VAPID keys for push notifications
17-
webpush.setVapidDetails(
18-
'mailto:your-email@example.com',
19-
process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY!,
20-
process.env.VAPID_PRIVATE_KEY!
21-
)
22-
23-
export async function GET(req: NextRequest) {
24-
try {
25-
const posts = await fetchRedditPosts(SUBREDDITS)
26-
const hiringPosts = posts.filter((post) => post.title.includes('[Hiring]'))
27-
28-
await storePosts(hiringPosts)
29-
30-
return NextResponse.json({ message: 'Posts fetched and stored successfully.' })
31-
} catch (error) {
32-
console.error(error)
33-
return NextResponse.json({ error: 'An error occurred while fetching posts.' }, { status: 500 })
34-
} finally {
35-
await prisma.$disconnect()
36-
}
37-
}

src/app/api/reddit/posts/route.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +0,0 @@
1-
import { NextRequest, NextResponse } from 'next/server'
2-
import prisma from '@/lib/db'
3-
import { withLogging } from '@/lib/logger'
4-
5-
export const GET = withLogging(async (request: NextRequest) => {
6-
try {
7-
// Parse query parameters for pagination
8-
const { searchParams } = new URL(request.url)
9-
const page = parseInt(searchParams.get('page') || '1', 10)
10-
const pageSize = parseInt(searchParams.get('pageSize') || '10', 10)
11-
12-
// Calculate skip value
13-
const skip = (page - 1) * pageSize
14-
15-
// Fetch paginated posts from Prisma
16-
const posts = await prisma.redditPost.findMany({
17-
orderBy: { createdAt: 'desc' },
18-
skip,
19-
take: pageSize,
20-
// select: { id: true, title: true, ... } // You can choose which fields to return
21-
})
22-
23-
// Optionally, get the total number of posts to return along with pagination info
24-
const totalCount = await prisma.redditPost.count()
25-
26-
return NextResponse.json({
27-
data: posts,
28-
page,
29-
pageSize,
30-
totalCount,
31-
})
32-
} catch (error) {
33-
// Handle any errors
34-
return NextResponse.json({ error: (error as Error).message }, { status: 500 })
35-
}
36-
})

0 commit comments

Comments
 (0)