Skip to content

Commit 8d0e5df

Browse files
committed
feat(sdk): consolidate SDK functionality and update dependencies
- Introduced a new SDK package to replace the previous ssr-sdk, consolidating shared functionality for handling views and reactions. - Updated package.json files across applications to reference the new @afilmory/sdk. - Removed the old ssr-sdk package and its associated files, streamlining the codebase. - Enhanced API routes for reactions and views to utilize the new SDK schemas and client methods. - Updated dependencies in various packages to ensure compatibility and improved functionality. Signed-off-by: Innei <tukon479@gmail.com>
1 parent d01da03 commit 8d0e5df

File tree

25 files changed

+1302
-265
lines changed

25 files changed

+1302
-265
lines changed

apps/ssr/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
},
2020
"dependencies": {
2121
"@afilmory/data": "workspace:*",
22+
"@afilmory/sdk": "workspace:*",
2223
"@afilmory/ui": "workspace:*",
2324
"@afilmory/utils": "workspace:*",
2425
"@t3-oss/env-nextjs": "0.13.8",

apps/ssr/sdk/package.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

apps/ssr/sdk/src/index.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

apps/ssr/sdk/tsconfig.json

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import { ViewDtoSchema } from '@afilmory/sdk'
12
import { sql } from 'drizzle-orm'
23
import type { NextRequest } from 'next/server'
34

45
import { guardDbEnabled } from '~/lib/api-guard'
56
import { views } from '~/schemas'
67

7-
import { DbManager } from '../../../lib/db'
8-
import { ViewDto } from './dto'
8+
import { DbManager } from '../../../../lib/db'
99

1010
export const POST = guardDbEnabled(async (req: NextRequest) => {
11-
const { refKey } = ViewDto.parse(await req.json())
11+
const { refKey } = ViewDtoSchema.parse(await req.json())
1212

1313
const db = DbManager.shared.getDb()
1414
await db

apps/ssr/src/app/api/aggregation/analysis/dto.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

apps/ssr/src/app/api/aggregation/analysis/route.ts renamed to apps/ssr/src/app/api/reactions/add/route.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
1+
import type {AnalysisResponse} from '@afilmory/sdk';
2+
import { AnalysisDtoSchema, ReactionDtoSchema } from '@afilmory/sdk'
13
import { eq } from 'drizzle-orm'
24
import type { NextRequest } from 'next/server'
35
import { NextResponse } from 'next/server'
46

57
import { guardDbEnabled } from '~/lib/api-guard'
68
import { DbManager } from '~/lib/db'
9+
import { photoLoader } from '~/lib/photo-loader'
10+
import { reactions } from '~/schemas'
711
import * as schemas from '~/schemas'
812

9-
import type { AnalysisResponse } from './dto'
10-
import { AnalysisDto } from './dto'
13+
export const POST = guardDbEnabled(async (req: NextRequest) => {
14+
const { refKey, reaction } = ReactionDtoSchema.parse(await req.json())
15+
16+
const photo = photoLoader.getPhoto(refKey)
17+
if (!photo) {
18+
return new Response("Can't add reaction to non-existing photo", {
19+
status: 400,
20+
})
21+
}
22+
const db = DbManager.shared.getDb()
23+
try {
24+
await db.insert(reactions).values({
25+
refKey,
26+
reaction,
27+
})
28+
return new Response('', { status: 201 })
29+
} catch (error) {
30+
console.error('Failed to add reaction:', error)
31+
return new Response('Failed to add reaction', { status: 500 })
32+
}
33+
})
1134

1235
export const GET = guardDbEnabled(async (req: NextRequest): Promise<NextResponse<AnalysisResponse>> => {
1336
const db = DbManager.shared.getDb()
1437
const searchParams = req.nextUrl.searchParams.entries()
1538

16-
const { refKey } = AnalysisDto.parse(Object.fromEntries(searchParams))
39+
const { refKey } = AnalysisDtoSchema.parse(Object.fromEntries(searchParams))
1740

1841
const [views] = await db.select().from(schemas.views).where(eq(schemas.views.refKey, refKey))
1942
const reactions = await db.select().from(schemas.reactions).where(eq(schemas.reactions.refKey, refKey))

apps/ssr/src/app/api/reactions/dto.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

apps/ssr/src/app/api/reactions/route.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

apps/ssr/src/app/api/views/dto.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)