Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Lint and Check Formatting

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint:
name: Lint and Check Formatting
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v5

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
cache: true

- name: Install dependencies
run: go mod download

- name: Generate GraphQL code
run: go generate .

- name: Lint with golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest

- name: Run gofumpt
run: go tool gofumpt -d -l .
9 changes: 8 additions & 1 deletion cmd/backend/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/database-playground/backend-v2/internal/events"
"github.com/database-playground/backend-v2/internal/graphql/apq"
"github.com/database-playground/backend-v2/internal/httputils"
"github.com/database-playground/backend-v2/internal/ranking"
"github.com/database-playground/backend-v2/internal/sqlrunner"
"github.com/database-playground/backend-v2/internal/submission"
"github.com/database-playground/backend-v2/internal/useraccount"
Expand Down Expand Up @@ -84,9 +85,10 @@ func GqlgenHandler(
useraccount *useraccount.Context,
eventService *events.EventService,
submissionService *submission.SubmissionService,
rankingService *ranking.Service,
apqCache graphql.Cache[string],
) *handler.Server {
srv := handler.New(graph.NewSchema(entClient, storage, sqlrunner, useraccount, eventService, submissionService))
srv := handler.New(graph.NewSchema(entClient, storage, sqlrunner, useraccount, eventService, submissionService, rankingService))

srv.AddTransport(transport.Options{})
srv.AddTransport(transport.GET{})
Expand Down Expand Up @@ -120,6 +122,11 @@ func SubmissionService(entClient *ent.Client, eventService *events.EventService,
return submission.NewSubmissionService(entClient, eventService, sqlrunner)
}

// RankingService creates a ranking.Service.
func RankingService(entClient *ent.Client) *ranking.Service {
return ranking.NewService(entClient)
}

// AuthService creates an auth service.
func AuthService(entClient *ent.Client, storage auth.Storage, config config.Config, useraccount *useraccount.Context) httpapi.Service {
return authservice.NewAuthService(entClient, storage, config, useraccount)
Expand Down
1 change: 1 addition & 0 deletions cmd/backend/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func main() {
EventService,
SubmissionService,
ApqCache,
RankingService,
PostHogClient,
AnnotateService(AuthService),
GqlgenHandler,
Expand Down
1 change: 1 addition & 0 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ package main

//go:generate go run -mod=mod ./ent/entc.go
//go:generate go tool gqlgen generate
//go:generate go tool gofumpt -w ./graph
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ require (
google.golang.org/grpc v1.76.0 // indirect
google.golang.org/protobuf v1.36.10 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
mvdan.cc/gofumpt v0.9.1 // indirect
)

tool (
entgo.io/ent/cmd/ent
github.com/99designs/gqlgen
github.com/99designs/gqlgen/graphql/introspection
mvdan.cc/gofumpt
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.28.0 h1:Q7ibns33JjyW48gHkuFT91qX48KG0ktULL6FgHdG688=
github.com/go-playground/validator/v10 v10.28.0/go.mod h1:GoI6I1SjPBh9p7ykNE/yj3fFYbyDOpwMn5KXd+m2hUU=
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
Expand Down Expand Up @@ -373,3 +375,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
mvdan.cc/gofumpt v0.9.1 h1:p5YT2NfFWsYyTieYgwcQ8aKV3xRvFH4uuN/zB2gBbMQ=
mvdan.cc/gofumpt v0.9.1/go.mod h1:3xYtNemnKiXaTh6R4VtlqDATFwBbdXI8lJvH/4qk7mw=
10 changes: 6 additions & 4 deletions graph/ent.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

189 changes: 189 additions & 0 deletions graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions graph/rank.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
extend type Query {
"""
Get the ranking.
"""
ranking(first: Int, after: Cursor, filter: RankingFilter!): RankingConnection! @scope(scope: "user:read")
}

input RankingFilter {
by: RankingBy!
order: RankingOrder!
period: RankingPeriod!
}

enum RankingBy {
POINTS
COMPLETED_QUESTIONS
}

enum RankingOrder {
ASC
DESC
}

enum RankingPeriod {
DAILY
WEEKLY
}

type RankingConnection {
edges: [RankingEdge!]!
pageInfo: PageInfo!
totalCount: Int!
}

type RankingEdge {
# User in the ranking
node: User!
cursor: Cursor!
}
17 changes: 17 additions & 0 deletions graph/rank.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading