2024-09-01 19:22:00 +00:00
|
|
|
import 'reflect-metadata'
|
2024-09-04 23:04:41 +00:00
|
|
|
import { Controller } from '$lib/server/api/common/types/controller'
|
2024-09-01 19:22:00 +00:00
|
|
|
import { CollectionsService } from '$lib/server/api/services/collections.service'
|
|
|
|
|
import { inject, injectable } from 'tsyringe'
|
|
|
|
|
import { requireAuth } from '../middleware/auth.middleware'
|
2024-08-23 02:26:22 +00:00
|
|
|
|
|
|
|
|
@injectable()
|
2024-09-04 23:04:41 +00:00
|
|
|
export class CollectionController extends Controller {
|
|
|
|
|
constructor(@inject(CollectionsService) private readonly collectionsService: CollectionsService) {
|
|
|
|
|
super()
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
}
|