server implementation prototype

This commit is contained in:
Quaternions 2024-11-26 14:03:47 -08:00
parent ca0fac97d0
commit 6a3d9da2e9

View File

@ -5,46 +5,19 @@ import (
"log" "log"
"net/http" "net/http"
"git.itzana.me/strafesnet/go-grpc/ranks" "git.itzana.me/strafesnet/maps-service/api"
"git.itzana.me/strafesnet/go-grpc/times" "git.itzana.me/strafesnet/maps-service/internal/controller/submissions"
"git.itzana.me/strafesnet/go-grpc/users" "git.itzana.me/strafesnet/maps-service/internal/controller/users"
"git.itzana.me/strafesnet/public-api/api"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
) )
type apiServer struct { type apiServer struct {
client *grpc.ClientConn submissions *submissions.Submissions
users *users.Users
} }
// GetUserRank implements api.Handler. // GetUserRank implements api.Handler.
func (m *apiServer) GetUserRank(ctx context.Context, params api.GetUserRankParams) (*api.Rank, error) { func (m *apiServer) GetSubmission(ctx context.Context, params api.GetSubmissionParams) (*api.Submission, error) {
client := ranks.NewRanksServiceClient(m.client) return m.submissions.Get(params.SubmissionID)
response, err := client.Get(ctx, &ranks.GetRequest{
UserID: params.UserID,
StyleID: params.StyleID,
ModeID: params.ModeID,
GameID: params.GameID,
})
if err != nil {
return nil, err
}
return &api.Rank{
ID: api.NewOptInt64(response.ID),
User: api.NewOptUser(api.User{
ID: api.NewOptInt64(response.User.ID),
Username: api.NewOptString(response.User.Username),
StateID: api.NewOptInt32(response.User.StateID),
}),
StyleID: api.NewOptInt32(response.StyleID),
ModeID: api.NewOptInt32(response.ModeID),
GameID: api.NewOptInt32(response.GameID),
Rank: api.NewOptFloat64(response.Rank),
Skill: api.NewOptFloat64(response.Skill),
UpdatedAt: api.NewOptInt64(response.UpdatedAt),
}, nil
} }
// NewError implements api.Handler. // NewError implements api.Handler.