2024-09-01 19:22:00 +00:00
|
|
|
import 'reflect-metadata'
|
|
|
|
|
import type { Controller } from '$lib/server/api/common/interfaces/controller.interface'
|
|
|
|
|
import { CollectionsService } from '$lib/server/api/services/collections.service'
|
|
|
|
|
import { Hono } from 'hono'
|
|
|
|
|
import { inject, injectable } from 'tsyringe'
|
|
|
|
|
import { requireAuth } from '../middleware/auth.middleware'
|
|
|
|
|
import type { HonoTypes } from '../types'
|
2024-08-23 02:26:22 +00:00
|
|
|
|
|
|
|
|
@injectable()
|
|
|
|
|
export class CollectionController implements Controller {
|
2024-09-01 19:22:00 +00:00
|
|
|
controller = new Hono<HonoTypes>()
|
2024-08-23 02:26:22 +00:00
|
|
|
|
2024-09-01 19:22:00 +00:00
|
|
|
constructor(@inject(CollectionsService) private readonly collectionsService: CollectionsService) {}
|
2024-08-23 02:26:22 +00:00
|
|
|
|
|
|
|
|
routes() {
|
|
|
|
|
return this.controller
|
|
|
|
|
.get('/', requireAuth, async (c) => {
|
2024-09-01 19:22:00 +00:00
|
|
|
const user = c.var.user
|
|
|
|
|
const collections = await this.collectionsService.findAllByUserId(user.id)
|
2024-08-23 02:26:22 +00:00
|
|
|
console.log('collections service', collections)
|
2024-09-01 19:22:00 +00:00
|
|
|
return c.json({ collections })
|
2024-08-23 02:26:22 +00:00
|
|
|
})
|
|
|
|
|
.get('/:cuid', requireAuth, async (c) => {
|
2024-09-01 19:22:00 +00:00
|
|
|
const cuid = c.req.param('cuid')
|
|
|
|
|
const collection = await this.collectionsService.findOneByCuid(cuid)
|
|
|
|
|
return c.json({ collection })
|
|
|
|
|
})
|
2024-08-23 02:26:22 +00:00
|
|
|
}
|
|
|
|
|
}
|