File tree Expand file tree Collapse file tree 3 files changed +1
-74
lines changed Expand file tree Collapse file tree 3 files changed +1
-74
lines changed Original file line number Diff line number Diff line change 1
1
import { NextResponse } from 'next/server'
2
- import { checkRedditMessages } from '@/lib/reddit'
2
+ import { checkRedditMessages } from '@/lib/jobs/ reddit'
3
3
4
4
export async function GET ( ) {
5
5
try {
Original file line number Diff line number Diff line change 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
- }
Original file line number Diff line number Diff line change 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
- } )
You can’t perform that action at this time.
0 commit comments