2024-09-01 19:22:00 +00:00
|
|
|
import 'reflect-metadata'
|
|
|
|
|
import type { Controller } from '$lib/server/api/common/interfaces/controller.interface'
|
|
|
|
|
import { UsersService } from '$lib/server/api/services/users.service'
|
|
|
|
|
import { Hono } from 'hono'
|
|
|
|
|
import { inject, injectable } from 'tsyringe'
|
|
|
|
|
import { requireAuth } from '../middleware/auth.middleware'
|
|
|
|
|
import type { HonoTypes } from '../types'
|
2024-07-29 01:39:42 +00:00
|
|
|
|
2024-08-01 16:26:42 +00:00
|
|
|
@injectable()
|
|
|
|
|
export class UserController implements Controller {
|
2024-09-01 19:22:00 +00:00
|
|
|
controller = new Hono<HonoTypes>()
|
2024-07-29 01:39:42 +00:00
|
|
|
|
2024-09-01 19:22:00 +00:00
|
|
|
constructor(@inject(UsersService) private readonly usersService: UsersService) {}
|
2024-08-01 16:26:42 +00:00
|
|
|
|
|
|
|
|
routes() {
|
|
|
|
|
return this.controller
|
2024-08-08 19:38:17 +00:00
|
|
|
.get('/', async (c) => {
|
2024-09-01 19:22:00 +00:00
|
|
|
const user = c.var.user
|
|
|
|
|
return c.json({ user })
|
2024-08-01 16:26:42 +00:00
|
|
|
})
|
2024-08-08 19:38:17 +00:00
|
|
|
.get('/:id', requireAuth, async (c) => {
|
2024-09-01 19:22:00 +00:00
|
|
|
const id = c.req.param('id')
|
|
|
|
|
const user = await this.usersService.findOneById(id)
|
|
|
|
|
return c.json({ user })
|
2024-08-08 19:38:17 +00:00
|
|
|
})
|
|
|
|
|
.get('/username/:userName', requireAuth, async (c) => {
|
2024-09-01 19:22:00 +00:00
|
|
|
const userName = c.req.param('userName')
|
|
|
|
|
const user = await this.usersService.findOneByUsername(userName)
|
|
|
|
|
return c.json({ user })
|
|
|
|
|
})
|
2024-08-01 16:26:42 +00:00
|
|
|
}
|
|
|
|
|
}
|