File tree 3 files changed +88
-0
lines changed
3 files changed +88
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { zValidator } from '@hono/zod-validator'
2
2
import { z } from 'zod'
3
+ import { createLaunchRecord } from '@/controllers/create-launch-record.ts'
3
4
import { deleteRom } from '@/controllers/delete-rom.ts'
5
+ import { getLaunchRecords } from '@/controllers/get-launch-records.ts'
4
6
import { createRoms } from '../controllers/create-roms.ts'
5
7
import { createState } from '../controllers/create-state.ts'
6
8
import { getRomContent } from '../controllers/get-rom-content.ts'
@@ -110,4 +112,41 @@ app.get('state/:id/thumbnail', async (c) => {
110
112
}
111
113
} )
112
114
115
+ app . post (
116
+ 'launch_record/new' ,
117
+
118
+ zValidator (
119
+ 'form' ,
120
+ z . object ( {
121
+ core : z . string ( ) ,
122
+ platform : z . string ( ) ,
123
+ rom : z . string ( ) ,
124
+ } ) ,
125
+ ) ,
126
+
127
+ async ( c ) => {
128
+ const form = c . req . valid ( 'form' )
129
+ await createLaunchRecord ( form )
130
+ return c . json ( null )
131
+ } ,
132
+ )
133
+
134
+ app . get (
135
+ 'launch_records' ,
136
+
137
+ zValidator (
138
+ 'query' ,
139
+ z . object ( {
140
+ page : z . number ( ) . default ( 1 ) ,
141
+ page_size : z . number ( ) . default ( 50 ) ,
142
+ } ) ,
143
+ ) ,
144
+
145
+ async ( c ) => {
146
+ const query = c . req . valid ( 'query' )
147
+ const result = await getLaunchRecords ( query )
148
+ return c . json ( result )
149
+ } ,
150
+ )
151
+
113
152
export { app as api }
Original file line number Diff line number Diff line change
1
+ import { getContextData } from 'waku/middleware/context'
2
+ import { launchRecordTable } from '../databases/library/schema.ts'
3
+
4
+ interface CreateRomParams {
5
+ core : string
6
+ platform : string
7
+ rom : string
8
+ }
9
+
10
+ export async function createLaunchRecord ( params : CreateRomParams ) {
11
+ const { currentUser, db } = getContextData ( )
12
+ const { library } = db
13
+
14
+ const [ result ] = await library
15
+ . insert ( launchRecordTable )
16
+ . values ( {
17
+ core : params . core ,
18
+ platform : params . platform ,
19
+ rom_id : params . rom ,
20
+ user_id : currentUser . id ,
21
+ } )
22
+ . returning ( )
23
+
24
+ return result
25
+ }
Original file line number Diff line number Diff line change
1
+ import { eq , max } from 'drizzle-orm'
2
+ import { getContextData } from 'waku/middleware/context'
3
+ import { launchRecordTable } from '../databases/library/schema.ts'
4
+
5
+ export async function getLaunchRecords ( { page = 1 , pageSize = 50 } : { page ?: number ; pageSize ?: number } ) {
6
+ const { currentUser, db } = getContextData ( )
7
+ const { library } = db
8
+
9
+ const offset = ( page - 1 ) * pageSize
10
+ const results = await library
11
+ . select ( {
12
+ core : launchRecordTable . core ,
13
+ lastLaunched : max ( launchRecordTable . created_at ) ,
14
+ romId : launchRecordTable . rom_id ,
15
+ userId : launchRecordTable . user_id ,
16
+ } )
17
+ . from ( launchRecordTable )
18
+ . where ( eq ( launchRecordTable . user_id , currentUser . id ) )
19
+ . groupBy ( launchRecordTable . rom_id )
20
+ . offset ( offset )
21
+ . limit ( pageSize )
22
+
23
+ return results
24
+ }
You can’t perform that action at this time.
0 commit comments