nquest/pkg/controller/admin.go

33 lines
713 B
Go
Raw Normal View History

2023-11-19 22:54:54 +03:00
package controller
import (
"net/http"
"github.com/labstack/echo/v4"
"gitrepo.ru/neonxp/nquest/api"
"gitrepo.ru/neonxp/nquest/pkg/contextlib"
"gitrepo.ru/neonxp/nquest/pkg/service"
)
type Admin struct {
GameService *service.Game
}
func (a *Admin) GetAdminGames(ctx echo.Context) error {
user := contextlib.GetUser(ctx)
games, err := a.GameService.ListByAuthor(ctx.Request().Context(), user)
if err != nil {
return err
}
result := make(api.GameAdminList, 0, len(games))
for _, g := range games {
result = append(result, api.GameAdminListItem{
Id: int(g.ID),
Title: g.Title,
CreatedAt: g.CreatedAt.Format("02.01.06 15:04"),
})
}
return ctx.JSON(http.StatusOK, result)
}