2 Commits

Author SHA1 Message Date
4bc17b0f91 remove unused line
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is passing
2026-02-18 20:16:59 -06:00
06faf1a4b7 Test out what datastore key playerdata-[ID] returns
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is failing
2026-02-18 20:00:18 -06:00
3 changed files with 32 additions and 6 deletions

View File

@@ -14,10 +14,11 @@ type UserRankFilter struct {
} // @name UserRankFilter
type User struct {
ID int64 `json:"id"`
Username string `json:"username"`
StateID int32 `json:"state_id"`
Muted bool `json:"muted"`
ID int64 `json:"id"`
Username string `json:"username"`
StateID int32 `json:"state_id"`
Muted bool `json:"muted"`
PlayerData map[string]any `json:"data"`
} // @name User
// FromGRPC converts a users.UserResponse protobuf message to a User domain object

View File

@@ -1,6 +1,10 @@
package handlers
import (
"net/http"
"strconv"
"git.itzana.me/strafesnet/go-grpc/datastore"
"git.itzana.me/strafesnet/go-grpc/ranks"
"git.itzana.me/strafesnet/go-grpc/users"
"git.itzana.me/strafesnet/public-api/pkg/api/dto"
@@ -8,8 +12,6 @@ import (
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"net/http"
"strconv"
)
// UserHandler handles HTTP requests related to users.
@@ -72,9 +74,26 @@ func (h *UserHandler) Get(ctx *gin.Context) {
return
}
dataStoreData, err := datastore.NewDatastoreServiceClient(h.dataClient).Get(ctx, &datastore.KeyMessage{
Key: "playerdata-" + strconv.FormatInt(userID, 10),
})
if err != nil {
statusCode := http.StatusInternalServerError
errorMessage := "Failed to get playerdata from data store"
ctx.JSON(statusCode, dto.Error{
Error: errorMessage,
})
log.WithError(err).Error(
"Failed to get playerdata data store",
)
return
}
// Convert gRPC UserResponse object to dto.UserData object
var user dto.User
result := user.FromGRPC(userData)
result.PlayerData = dataStoreData.Data.AsMap()
// Return the user data
ctx.JSON(http.StatusOK, dto.Response[dto.User]{

View File

@@ -31,6 +31,12 @@ func NewApiCommand() *cli.Command {
EnvVars: []string{"DATA_RPC_HOST"},
Value: "data-service:9000",
},
&cli.StringFlag{
Name: "datastore-rpc-host",
Usage: "Host of datastore rpc",
EnvVars: []string{"DATASTORE_RPC_HOST"},
Value: "datastore-service:9000",
},
},
}
}