diff --git a/.gitignore b/.gitignore index 1fda395f..4e481cfd 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,4 @@ __debug_bin backend/build/* .DS_Store -tmp \ No newline at end of file +backend/tmp/* \ No newline at end of file diff --git a/backend/go.sum b/backend/go.sum index d6f868c7..e36ed820 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -1,7 +1,5 @@ github.com/99designs/gqlgen v0.17.36 h1:u/o/rv2SZ9s5280dyUOOrkpIIkr/7kITMXYD3rkJ9go= github.com/99designs/gqlgen v0.17.36/go.mod h1:6RdyY8puhCoWAQVr2qzF2OMVfudQzc8ACxzpzluoQm4= -github.com/FlowingSPDG/Got5 v0.0.0-20230804162215-be9dcc00f8cc h1:17qQ5CP6MuPV1Ph48OFgTTq6LNNMAYYhrluBsOraXAI= -github.com/FlowingSPDG/Got5 v0.0.0-20230804162215-be9dcc00f8cc/go.mod h1:GkWSjnJpY62vUUsJPVJXxxa+YDjCR1XfE2FErLaS5aI= github.com/FlowingSPDG/Got5 v0.0.0-20230812005653-63978277bb86 h1:OuiajrB7YO3W4fxIIkyK1LKEMnuySvvLjHBCnqWYYAo= github.com/FlowingSPDG/Got5 v0.0.0-20230812005653-63978277bb86/go.mod h1:7USdCFD/lkTjOqbncjQaBzklCAaM8RauYmL4lfctxXQ= github.com/FlowingSPDG/go-steam v0.0.0-20200304111708-e30ea2f91a83 h1:g3VY8PBeP2ntkCAIs0eTPH9X1q+ZrFcTWmvtioURpcw= @@ -48,8 +46,8 @@ github.com/gofiber/fiber/v2 v2.39.0 h1:uhWpYQ6EHN8J7FOPYbI2hrdBD/KNZBC5CjbuOd4QU github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= diff --git a/backend/graph/generated.go b/backend/graph/generated.go index eccc3a4d..b1e4723a 100644 --- a/backend/graph/generated.go +++ b/backend/graph/generated.go @@ -90,6 +90,7 @@ type ComplexityRoot struct { Mutation struct { AddServer func(childComplexity int, input model.NewGameServer) int + CreateMatch func(childComplexity int, input model.NewMatch) int RegisterTeam func(childComplexity int, input model.NewTeam) int } @@ -166,6 +167,7 @@ type ComplexityRoot struct { type MutationResolver interface { RegisterTeam(ctx context.Context, input model.NewTeam) (*model.Team, error) + CreateMatch(ctx context.Context, input model.NewMatch) (*model.Match, error) AddServer(ctx context.Context, input model.NewGameServer) (*model.GameServer, error) } type QueryResolver interface { @@ -415,6 +417,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.AddServer(childComplexity, args["input"].(model.NewGameServer)), true + case "Mutation.createMatch": + if e.complexity.Mutation.CreateMatch == nil { + break + } + + args, err := ec.field_Mutation_createMatch_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.CreateMatch(childComplexity, args["input"].(model.NewMatch)), true + case "Mutation.registerTeam": if e.complexity.Mutation.RegisterTeam == nil { break @@ -841,6 +855,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec := executionContext{rc, e, 0, 0, make(chan graphql.DeferredResult)} inputUnmarshalMap := graphql.BuildUnmarshalerMap( ec.unmarshalInputNewGameServer, + ec.unmarshalInputNewMatch, ec.unmarshalInputNewPlayer, ec.unmarshalInputNewPlayerForTeam, ec.unmarshalInputNewTeam, @@ -978,6 +993,21 @@ func (ec *executionContext) field_Mutation_addServer_args(ctx context.Context, r return args, nil } +func (ec *executionContext) field_Mutation_createMatch_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 model.NewMatch + if tmp, ok := rawArgs["input"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("input")) + arg0, err = ec.unmarshalNNewMatch2githubᚗcomᚋFlowingSPDGᚋget5loaderᚋbackendᚋgraphᚋmodelᚐNewMatch(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_registerTeam_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -2599,6 +2629,91 @@ func (ec *executionContext) fieldContext_Mutation_registerTeam(ctx context.Conte return fc, nil } +func (ec *executionContext) _Mutation_createMatch(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_createMatch(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().CreateMatch(rctx, fc.Args["input"].(model.NewMatch)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.Match) + fc.Result = res + return ec.marshalNMatch2ᚖgithubᚗcomᚋFlowingSPDGᚋget5loaderᚋbackendᚋgraphᚋmodelᚐMatch(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_createMatch(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "ID": + return ec.fieldContext_Match_ID(ctx, field) + case "userId": + return ec.fieldContext_Match_userId(ctx, field) + case "team1": + return ec.fieldContext_Match_team1(ctx, field) + case "team2": + return ec.fieldContext_Match_team2(ctx, field) + case "winner": + return ec.fieldContext_Match_winner(ctx, field) + case "startedAt": + return ec.fieldContext_Match_startedAt(ctx, field) + case "endedAt": + return ec.fieldContext_Match_endedAt(ctx, field) + case "maxMaps": + return ec.fieldContext_Match_maxMaps(ctx, field) + case "title": + return ec.fieldContext_Match_title(ctx, field) + case "skipVeto": + return ec.fieldContext_Match_skipVeto(ctx, field) + case "team1Score": + return ec.fieldContext_Match_team1Score(ctx, field) + case "team2Score": + return ec.fieldContext_Match_team2Score(ctx, field) + case "forfeit": + return ec.fieldContext_Match_forfeit(ctx, field) + case "mapStats": + return ec.fieldContext_Match_mapStats(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Match", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_createMatch_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Mutation_addServer(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Mutation_addServer(ctx, field) if err != nil { @@ -7289,6 +7404,80 @@ func (ec *executionContext) unmarshalInputNewGameServer(ctx context.Context, obj return it, nil } +func (ec *executionContext) unmarshalInputNewMatch(ctx context.Context, obj interface{}) (model.NewMatch, error) { + var it model.NewMatch + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"team1", "team2", "serverID", "maxMaps", "title", "skipVeto"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "team1": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("team1")) + data, err := ec.unmarshalNID2string(ctx, v) + if err != nil { + return it, err + } + it.Team1 = data + case "team2": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("team2")) + data, err := ec.unmarshalNID2string(ctx, v) + if err != nil { + return it, err + } + it.Team2 = data + case "serverID": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("serverID")) + data, err := ec.unmarshalNID2string(ctx, v) + if err != nil { + return it, err + } + it.ServerID = data + case "maxMaps": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("maxMaps")) + data, err := ec.unmarshalNInt2int(ctx, v) + if err != nil { + return it, err + } + it.MaxMaps = data + case "title": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "skipVeto": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("skipVeto")) + data, err := ec.unmarshalNBoolean2bool(ctx, v) + if err != nil { + return it, err + } + it.SkipVeto = data + } + } + + return it, nil +} + func (ec *executionContext) unmarshalInputNewPlayer(ctx context.Context, obj interface{}) (model.NewPlayer, error) { var it model.NewPlayer asMap := map[string]interface{}{} @@ -7882,6 +8071,13 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { out.Invalids++ } + case "createMatch": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createMatch(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } case "addServer": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { return ec._Mutation_addServer(ctx, field) @@ -9038,6 +9234,11 @@ func (ec *executionContext) unmarshalNNewGameServer2githubᚗcomᚋFlowingSPDG return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNNewMatch2githubᚗcomᚋFlowingSPDGᚋget5loaderᚋbackendᚋgraphᚋmodelᚐNewMatch(ctx context.Context, v interface{}) (model.NewMatch, error) { + res, err := ec.unmarshalInputNewMatch(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNNewPlayerForTeam2ᚖgithubᚗcomᚋFlowingSPDGᚋget5loaderᚋbackendᚋgraphᚋmodelᚐNewPlayerForTeam(ctx context.Context, v interface{}) (*model.NewPlayerForTeam, error) { res, err := ec.unmarshalInputNewPlayerForTeam(ctx, v) return &res, graphql.ErrorOnPath(ctx, err) diff --git a/backend/graph/model/models_gen.go b/backend/graph/model/models_gen.go index efbbe668..f5fa0d61 100644 --- a/backend/graph/model/models_gen.go +++ b/backend/graph/model/models_gen.go @@ -56,6 +56,15 @@ type NewGameServer struct { Public bool `json:"public"` } +type NewMatch struct { + Team1 string `json:"team1"` + Team2 string `json:"team2"` + ServerID string `json:"serverID"` + MaxMaps int `json:"maxMaps"` + Title string `json:"title"` + SkipVeto bool `json:"skipVeto"` +} + type NewPlayer struct { SteamID string `json:"steamId"` Name string `json:"name"` diff --git a/backend/graph/qls/schema.graphqls b/backend/graph/qls/schema.graphqls index 045132ce..9333bf63 100644 --- a/backend/graph/qls/schema.graphqls +++ b/backend/graph/qls/schema.graphqls @@ -111,6 +111,7 @@ type Mutation { registerTeam(input: NewTeam!): Team! # Match op + createMatch(input: NewMatch!): Match! # gameserver op addServer(input: NewGameServer!): GameServer! @@ -134,6 +135,15 @@ type Match { mapStats: [MapStats!]! } +input NewMatch { + team1: ID! + team2: ID! + serverID: ID! + maxMaps: Int! + title: String! + skipVeto: Boolean! +} + # MapStats type MapStats { id: ID! diff --git a/backend/graph/schema.resolvers.go b/backend/graph/schema.resolvers.go index 1be3b899..901114ff 100644 --- a/backend/graph/schema.resolvers.go +++ b/backend/graph/schema.resolvers.go @@ -25,6 +25,19 @@ func (r *mutationResolver) RegisterTeam(ctx context.Context, input model.NewTeam return convertTeam(team), nil } +// CreateMatch is the resolver for the createMatch field. +func (r *mutationResolver) CreateMatch(ctx context.Context, input model.NewMatch) (*model.Match, error) { + token, err := g5ctx.GetUserToken(ctx) + if err != nil { + return nil, err + } + match, err := r.MatchUsecase.CreateMatch(ctx, token.UserID, entity.GameServerID(input.ServerID), entity.TeamID(input.Team1), entity.TeamID(input.Team2), input.MaxMaps, input.Title) + if err != nil { + return nil, err + } + return convertMatch(match), nil +} + // AddServer is the resolver for the addServer field. func (r *mutationResolver) AddServer(ctx context.Context, input model.NewGameServer) (*model.GameServer, error) { token, err := g5ctx.GetUserToken(ctx) diff --git a/backend/tmp/main b/backend/tmp/main deleted file mode 100755 index b1d54ee1..00000000 Binary files a/backend/tmp/main and /dev/null differ