connector impl
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
|
||||
"galaxy/model/order"
|
||||
"galaxy/model/report"
|
||||
"galaxy/model/rest"
|
||||
|
||||
e "galaxy/error"
|
||||
@@ -21,6 +22,7 @@ type CommandExecutor interface {
|
||||
GenerateGame([]string) (rest.StateResponse, error)
|
||||
GenerateTurn() (rest.StateResponse, error)
|
||||
GameState() (rest.StateResponse, error)
|
||||
LoadReport(actor string, turn uint) (*report.Report, error)
|
||||
Execute(cmd ...Command) error
|
||||
ValidateOrder(actor string, cmd ...order.DecodableCommand) error
|
||||
}
|
||||
@@ -84,6 +86,10 @@ func (e *executor) GameState() (rest.StateResponse, error) {
|
||||
return stateResponse(s), nil
|
||||
}
|
||||
|
||||
func (e *executor) LoadReport(actor string, turn uint) (*report.Report, error) {
|
||||
return controller.LoadReport(e.cfg, actor, turn)
|
||||
}
|
||||
|
||||
func stateResponse(s game.State) rest.StateResponse {
|
||||
result := &rest.StateResponse{
|
||||
ID: s.ID,
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type reportParam struct {
|
||||
Player string `form:"player" binding:"required,notblank"`
|
||||
Turn int `form:"turn" binding:"gte=0"`
|
||||
}
|
||||
|
||||
func ReportHandler(c *gin.Context, executor CommandExecutor) {
|
||||
p := &reportParam{}
|
||||
err := c.ShouldBindQuery(p)
|
||||
if errorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := executor.LoadReport(p.Player, uint(p.Turn))
|
||||
if errorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, r)
|
||||
}
|
||||
Reference in New Issue
Block a user