Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4bc17b0f91 | |||
| 06faf1a4b7 |
@@ -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
|
||||
|
||||
@@ -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]{
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user