~xenrox/10man-api

e644baa0348079cf947bb81f92fb81b9e9ddf77a — Thorben Günther 10 months ago 3a8a4ff
mutation: start-/cancelQueue id -> teamspeakID

While the website gets steamID and through login with that teamspeakID
and id, the teamspeak bot only knows about the teamspeakID.
3 files changed, 30 insertions(+), 30 deletions(-)

M graph/generated/generated.go
M graph/schema.graphqls
M graph/schema.resolvers.go
M graph/generated/generated.go => graph/generated/generated.go +20 -20
@@ 44,12 44,12 @@ type DirectiveRoot struct {
type ComplexityRoot struct {
	Mutation struct {
		CancelMatch func(childComplexity int, id int) int
		CancelQueue func(childComplexity int, id int) int
		CancelQueue func(childComplexity int, teamspeakID string) int
		CreateMatch func(childComplexity int) int
		CreateUser  func(childComplexity int, input model.NewUser) int
		DeleteUser  func(childComplexity int, id int) int
		FinishMatch func(childComplexity int, id int, winner string) int
		StartQueue  func(childComplexity int, id int) int
		StartQueue  func(childComplexity int, teamspeakID string) int
		UpdateUser  func(childComplexity int, id int, input model.UserInput) int
	}



@@ 73,8 73,8 @@ type MutationResolver interface {
	CreateUser(ctx context.Context, input model.NewUser) (string, error)
	DeleteUser(ctx context.Context, id int) (string, error)
	UpdateUser(ctx context.Context, id int, input model.UserInput) (*model.User, error)
	StartQueue(ctx context.Context, id int) (int, error)
	CancelQueue(ctx context.Context, id int) (int, error)
	StartQueue(ctx context.Context, teamspeakID string) (int, error)
	CancelQueue(ctx context.Context, teamspeakID string) (int, error)
	CreateMatch(ctx context.Context) (int, error)
	CancelMatch(ctx context.Context, id int) (string, error)
	FinishMatch(ctx context.Context, id int, winner string) (string, error)


@@ 121,7 121,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
			return 0, false
		}

		return e.complexity.Mutation.CancelQueue(childComplexity, args["id"].(int)), true
		return e.complexity.Mutation.CancelQueue(childComplexity, args["teamspeakID"].(string)), true

	case "Mutation.createMatch":
		if e.complexity.Mutation.CreateMatch == nil {


@@ 176,7 176,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
			return 0, false
		}

		return e.complexity.Mutation.StartQueue(childComplexity, args["id"].(int)), true
		return e.complexity.Mutation.StartQueue(childComplexity, args["teamspeakID"].(string)), true

	case "Mutation.updateUser":
		if e.complexity.Mutation.UpdateUser == nil {


@@ 360,8 360,8 @@ type Mutation {
    createUser(input: NewUser!): String!
    deleteUser(id: Int!): String!
    updateUser(id: Int!, input: UserInput!): User
    startQueue(id: Int!): Int!
    cancelQueue(id: Int!): Int!
    startQueue(teamspeakID: String!): Int!
    cancelQueue(teamspeakID: String!): Int!
    createMatch: Int!
    cancelMatch(id: Int!): String!
    finishMatch(id: Int!, winner: String!): String!


@@ 392,15 392,15 @@ func (ec *executionContext) field_Mutation_cancelMatch_args(ctx context.Context,
func (ec *executionContext) field_Mutation_cancelQueue_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
	var err error
	args := map[string]interface{}{}
	var arg0 int
	if tmp, ok := rawArgs["id"]; ok {
		ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id"))
		arg0, err = ec.unmarshalNInt2int(ctx, tmp)
	var arg0 string
	if tmp, ok := rawArgs["teamspeakID"]; ok {
		ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("teamspeakID"))
		arg0, err = ec.unmarshalNString2string(ctx, tmp)
		if err != nil {
			return nil, err
		}
	}
	args["id"] = arg0
	args["teamspeakID"] = arg0
	return args, nil
}



@@ 461,15 461,15 @@ func (ec *executionContext) field_Mutation_finishMatch_args(ctx context.Context,
func (ec *executionContext) field_Mutation_startQueue_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) {
	var err error
	args := map[string]interface{}{}
	var arg0 int
	if tmp, ok := rawArgs["id"]; ok {
		ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id"))
		arg0, err = ec.unmarshalNInt2int(ctx, tmp)
	var arg0 string
	if tmp, ok := rawArgs["teamspeakID"]; ok {
		ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("teamspeakID"))
		arg0, err = ec.unmarshalNString2string(ctx, tmp)
		if err != nil {
			return nil, err
		}
	}
	args["id"] = arg0
	args["teamspeakID"] = arg0
	return args, nil
}



@@ 728,7 728,7 @@ func (ec *executionContext) _Mutation_startQueue(ctx context.Context, field grap
	fc.Args = args
	resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
		ctx = rctx // use context from middleware stack in children
		return ec.resolvers.Mutation().StartQueue(rctx, args["id"].(int))
		return ec.resolvers.Mutation().StartQueue(rctx, args["teamspeakID"].(string))
	})
	if err != nil {
		ec.Error(ctx, err)


@@ 770,7 770,7 @@ func (ec *executionContext) _Mutation_cancelQueue(ctx context.Context, field gra
	fc.Args = args
	resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
		ctx = rctx // use context from middleware stack in children
		return ec.resolvers.Mutation().CancelQueue(rctx, args["id"].(int))
		return ec.resolvers.Mutation().CancelQueue(rctx, args["teamspeakID"].(string))
	})
	if err != nil {
		ec.Error(ctx, err)

M graph/schema.graphqls => graph/schema.graphqls +2 -2
@@ 31,8 31,8 @@ type Mutation {
    createUser(input: NewUser!): String!
    deleteUser(id: Int!): String!
    updateUser(id: Int!, input: UserInput!): User
    startQueue(id: Int!): Int!
    cancelQueue(id: Int!): Int!
    startQueue(teamspeakID: String!): Int!
    cancelQueue(teamspeakID: String!): Int!
    createMatch: Int!
    cancelMatch(id: Int!): String!
    finishMatch(id: Int!, winner: String!): String!

M graph/schema.resolvers.go => graph/schema.resolvers.go +8 -8
@@ 144,7 144,7 @@ func (r *mutationResolver) UpdateUser(ctx context.Context, id int, input model.U
	return &user, nil
}

func (r *mutationResolver) StartQueue(ctx context.Context, id int) (int, error) {
func (r *mutationResolver) StartQueue(ctx context.Context, teamspeakID string) (int, error) {
	players, err := database.PlayersInQueue()
	if err != nil {
		return players, err


@@ 173,8 173,8 @@ func (r *mutationResolver) StartQueue(ctx context.Context, id int) (int, error) 
	query := `
		UPDATE "User"
		SET queueing = true
		WHERE id = $1 AND NOT queueing`
	result, err := database.DB.Exec(query, id)
		WHERE teamspeak_id = $1 AND NOT queueing`
	result, err := database.DB.Exec(query, teamspeakID)
	if err != nil {
		return players, fmt.Errorf("QueueFail: %w", err)
	}


@@ 190,8 190,8 @@ func (r *mutationResolver) StartQueue(ctx context.Context, id int) (int, error) 
		query = `
			SELECT queueing
			FROM "User"
			WHERE id = $1`
		err = database.DB.QueryRow(query, id).Scan(&queueing)
			WHERE teamspeak_id = $1`
		err = database.DB.QueryRow(query, teamspeakID).Scan(&queueing)
		if errors.Is(err, sql.ErrNoRows) {
			return players, errors.New("id does not exist")
		} else if err != nil {


@@ 209,12 209,12 @@ func (r *mutationResolver) StartQueue(ctx context.Context, id int) (int, error) 
	return players, nil
}

func (r *mutationResolver) CancelQueue(ctx context.Context, id int) (int, error) {
func (r *mutationResolver) CancelQueue(ctx context.Context, teamspeakID string) (int, error) {
	query := `
		UPDATE "User"
		SET queueing = false
		WHERE id = $1 AND queueing`
	result, err := database.DB.Exec(query, id)
		WHERE teamspeak_id = $1 AND queueing`
	result, err := database.DB.Exec(query, teamspeakID)
	if err != nil {
		return -1, err
	}