nquest/pkg/controller/game.go

33 lines
614 B
Go
Raw Normal View History

2023-11-01 23:21:12 +03:00
package controller
import (
"net/http"
"github.com/labstack/echo/v4"
"gitrepo.ru/neonxp/nquest/api"
2023-11-01 23:21:12 +03:00
"gitrepo.ru/neonxp/nquest/pkg/service"
)
type Game struct {
GameService *service.Game
}
// (GET /games)
func (g *Game) GetGames(ctx echo.Context) error {
games, err := g.GameService.List(ctx.Request().Context())
2023-11-01 23:21:12 +03:00
if err != nil {
return err
}
resp := make(api.GameListResponse, 0, len(games))
for _, game := range games {
resp = append(resp, api.GameView{
Id: int(game.ID),
Title: game.Title,
Description: game.Description,
})
}
2023-11-01 23:21:12 +03:00
return ctx.JSON(http.StatusOK, resp)
2023-11-01 23:21:12 +03:00
}