Skip to content

Commit

Permalink
Start working on new /session/start
Browse files Browse the repository at this point in the history
  • Loading branch information
klydra committed Feb 20, 2023
1 parent f75c0f6 commit 5877d51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 11 additions & 1 deletion server/helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import "github.com/pocketbase/pocketbase/apis"
import (
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/models"
)

// ---------------------------------------------------------------
// Find methods
Expand Down Expand Up @@ -57,3 +60,10 @@ func resetCard(card string) string {

return card
}

func participating(player *models.Record) *apis.ApiError {
if len(player.GetString("game")) == 0 {
return apis.NewBadRequestError("You are not participating in this game.", err)
}
return nil
}
12 changes: 7 additions & 5 deletions server/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"github.com/labstack/echo/v5"
"github.com/labstack/echo/v5/middleware"
"github.com/oklog/ulid/v2"
Expand All @@ -11,6 +12,7 @@ import (
"github.com/pocketbase/pocketbase/plugins/migratecmd"
"log"
_ "main/migrations"
"math/rand"
"net/http"
"os"
)
Expand Down Expand Up @@ -282,15 +284,15 @@ func main() {
return c.JSON(http.StatusOK, Status{Status: "ok"})
})

/*e.Router.POST("/session/start", func(c echo.Context) error {
e.Router.POST("/session/start", func(c echo.Context) error {
// Retrieve target user
user, err := app.Dao().FindRecordById("players", c.Request().Header.Get("token"))
player, err := getPlayerRecordByToken(app, c.Request().Header.Get("token"))
if err != nil {
return apis.NewBadRequestError("Can't find user.", err)
return err
}

if len(user.GetString("game")) == 0 {
return apis.NewBadRequestError("You are not participating in this game.", err)
if err := participating(player); err != nil {
return err
}

game, err := app.Dao().FindRecordById("games", user.GetString("game"))
Expand Down

0 comments on commit 5877d51

Please sign in to comment.