55 lines
1,012 B
Go
55 lines
1,012 B
Go
package controller
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
"gitrepo.ru/neonxp/nquest/pkg/contextlib"
|
|
"gitrepo.ru/neonxp/nquest/pkg/models"
|
|
"gitrepo.ru/neonxp/nquest/pkg/service"
|
|
)
|
|
|
|
type Engine struct {
|
|
GameService *service.Game
|
|
}
|
|
|
|
func (ec *Engine) Get(c echo.Context) error {
|
|
user := contextlib.GetUser(c)
|
|
team := user.Team.Team
|
|
gameID, err := strconv.Atoi(c.Param("ID"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
game, err := ec.GameService.GetByID(c.Request().Context(), uint(gameID))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
state, err := ec.GameService.GetState(c.Request().Context(), game, team)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
history, err := ec.GameService.GetHistory(c.Request().Context(), game, team)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return c.Render(
|
|
http.StatusOK,
|
|
"engine_view",
|
|
&GetReponse{
|
|
Game: game,
|
|
State: state,
|
|
History: history,
|
|
},
|
|
)
|
|
}
|
|
|
|
type GetReponse struct {
|
|
Game *models.Game
|
|
State *models.GamePassing
|
|
History []*models.GamePassing
|
|
}
|