Files
galaxy-game/internal/router/handler/order.go
T
Ilia Denisov 233c9ebc2a feat: order processing
feat: order commands result save/load
2026-02-20 17:44:41 +02:00

38 lines
818 B
Go

package handler
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
"github.com/iliadenisov/galaxy/internal/model/order"
"github.com/iliadenisov/galaxy/internal/model/rest"
"github.com/iliadenisov/galaxy/internal/repo"
)
func OrderHandler(c *gin.Context, executor CommandExecutor) {
var cmd rest.Command
if errorResponse(c, c.ShouldBindJSON(&cmd)) {
return
}
commands := make([]order.DecodableCommand, len(cmd.Commands))
for i := range cmd.Commands {
command, err := repo.ParseOrder(cmd.Commands[i], validateCommand)
if errorResponse(c, err) {
return
}
commands[i] = command
}
if len(commands) == 0 {
errorResponse(c, errors.New("no commands given"))
return
}
if errorResponse(c, executor.ValidateOrder(cmd.Actor, commands...)) {
return
}
c.Status(http.StatusNoContent)
}