From 50b700a4c94e797d3b290b02bd8ffad3ff95ecd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Fri, 4 Nov 2022 16:13:12 +0100 Subject: [PATCH] Add a bit logging --- graph/model/models_stringers.go | 28 ++++++++++++++++++++++++++++ graph/schema.resolvers.go | 12 +++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 graph/model/models_stringers.go diff --git a/graph/model/models_stringers.go b/graph/model/models_stringers.go new file mode 100644 index 0000000..eea2f25 --- /dev/null +++ b/graph/model/models_stringers.go @@ -0,0 +1,28 @@ +package model + +import ( + "fmt" + "strings" +) + +func (input UserInput) String() string { + var e []string + + if input.Avatar != nil { + e = append(e, "Avatar") + } + + if input.Elo != nil { + e = append(e, fmt.Sprintf("Elo %d", *input.Elo)) + } + + if input.Name != nil { + e = append(e, fmt.Sprintf("Name %q", *input.Name)) + } + + if input.TeamspeakID != nil { + e = append(e, fmt.Sprintf("TeamspeakID %q", *input.TeamspeakID)) + } + + return strings.Join(e, ", ") +} diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go index 098ef38..ca31056 100644 --- a/graph/schema.resolvers.go +++ b/graph/schema.resolvers.go @@ -67,6 +67,7 @@ func (r *mutationResolver) CreateUser(ctx context.Context, input model.NewUser) return "", database.CheckErrorCode(err) } + r.Logger.Infof("Created user %q (Elo: %d).", input.SteamID, elo.Elo) return "Created", nil } @@ -74,7 +75,13 @@ func (r *mutationResolver) CreateUser(ctx context.Context, input model.NewUser) func (r *mutationResolver) DeleteUser(ctx context.Context, id int) (string, error) { query := `DELETE FROM "User" WHERE id = $1` _, err := r.DB.DB.Exec(query, id) - return "Deleted", err + + if err != nil { + return "", err + } + + r.Logger.Infof("Deleted user with ID %d.", id) + return "Deleted", nil } // UpdateUser is the resolver for the updateUser field. @@ -146,6 +153,7 @@ func (r *mutationResolver) UpdateUser(ctx context.Context, id int, input model.U return nil, err } + r.Logger.Infof("Updated user with ID %d: %v", id, input) return &user, nil } @@ -406,6 +414,8 @@ func (r *mutationResolver) FinishMatch(ctx context.Context, winner string) (stri if err != nil { return "FinishFail", err } + r.Logger.Infof("%s won the match.", winner) + r.Logger.Debugf("Team 1 got %d Elo, Team 2 got %d Elo.", delta1, delta2) return "FinishSuccess", nil } -- 2.44.0