Skip to content

Commit 23be9ac

Browse files
authored
Merge pull request #23 from database-playground/pan93412/dbp-90-實作真正的排行榜
DBP-90: 實作真正的排行榜
2 parents f6dd72a + ffb3812 commit 23be9ac

File tree

19 files changed

+2210
-12
lines changed

19 files changed

+2210
-12
lines changed

.github/workflows/lint.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Lint and Check Formatting
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
lint:
11+
name: Lint and Check Formatting
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v5
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version-file: "go.mod"
21+
cache: true
22+
23+
- name: Install dependencies
24+
run: go mod download
25+
26+
- name: Generate GraphQL code
27+
run: go generate .
28+
29+
- name: Lint with golangci-lint
30+
uses: golangci/golangci-lint-action@v8
31+
with:
32+
version: latest
33+
34+
- name: Run gofumpt
35+
run: go tool gofumpt -d -l .

cmd/backend/dependencies.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/database-playground/backend-v2/internal/events"
2525
"github.com/database-playground/backend-v2/internal/graphql/apq"
2626
"github.com/database-playground/backend-v2/internal/httputils"
27+
"github.com/database-playground/backend-v2/internal/ranking"
2728
"github.com/database-playground/backend-v2/internal/sqlrunner"
2829
"github.com/database-playground/backend-v2/internal/submission"
2930
"github.com/database-playground/backend-v2/internal/useraccount"
@@ -84,9 +85,10 @@ func GqlgenHandler(
8485
useraccount *useraccount.Context,
8586
eventService *events.EventService,
8687
submissionService *submission.SubmissionService,
88+
rankingService *ranking.Service,
8789
apqCache graphql.Cache[string],
8890
) *handler.Server {
89-
srv := handler.New(graph.NewSchema(entClient, storage, sqlrunner, useraccount, eventService, submissionService))
91+
srv := handler.New(graph.NewSchema(entClient, storage, sqlrunner, useraccount, eventService, submissionService, rankingService))
9092

9193
srv.AddTransport(transport.Options{})
9294
srv.AddTransport(transport.GET{})
@@ -120,6 +122,11 @@ func SubmissionService(entClient *ent.Client, eventService *events.EventService,
120122
return submission.NewSubmissionService(entClient, eventService, sqlrunner)
121123
}
122124

125+
// RankingService creates a ranking.Service.
126+
func RankingService(entClient *ent.Client) *ranking.Service {
127+
return ranking.NewService(entClient)
128+
}
129+
123130
// AuthService creates an auth service.
124131
func AuthService(entClient *ent.Client, storage auth.Storage, config config.Config, useraccount *useraccount.Context) httpapi.Service {
125132
return authservice.NewAuthService(entClient, storage, config, useraccount)

cmd/backend/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func main() {
2020
EventService,
2121
SubmissionService,
2222
ApqCache,
23+
RankingService,
2324
PostHogClient,
2425
AnnotateService(AuthService),
2526
GqlgenHandler,

generate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ package main
22

33
//go:generate go run -mod=mod ./ent/entc.go
44
//go:generate go tool gqlgen generate
5+
//go:generate go tool gofumpt -w ./graph

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ require (
149149
google.golang.org/grpc v1.76.0 // indirect
150150
google.golang.org/protobuf v1.36.10 // indirect
151151
gopkg.in/yaml.v3 v3.0.1 // indirect
152+
mvdan.cc/gofumpt v0.9.1 // indirect
152153
)
153154

154155
tool (
155156
entgo.io/ent/cmd/ent
156157
github.com/99designs/gqlgen
157158
github.com/99designs/gqlgen/graphql/introspection
159+
mvdan.cc/gofumpt
158160
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
108108
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
109109
github.com/go-playground/validator/v10 v10.28.0 h1:Q7ibns33JjyW48gHkuFT91qX48KG0ktULL6FgHdG688=
110110
github.com/go-playground/validator/v10 v10.28.0/go.mod h1:GoI6I1SjPBh9p7ykNE/yj3fFYbyDOpwMn5KXd+m2hUU=
111+
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
112+
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
111113
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
112114
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
113115
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
@@ -373,3 +375,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
373375
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
374376
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
375377
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
378+
mvdan.cc/gofumpt v0.9.1 h1:p5YT2NfFWsYyTieYgwcQ8aKV3xRvFH4uuN/zB2gBbMQ=
379+
mvdan.cc/gofumpt v0.9.1/go.mod h1:3xYtNemnKiXaTh6R4VtlqDATFwBbdXI8lJvH/4qk7mw=

graph/ent.resolvers.go

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graph/model/models_gen.go

Lines changed: 189 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graph/rank.graphqls

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
extend type Query {
2+
"""
3+
Get the ranking.
4+
"""
5+
ranking(first: Int, after: Cursor, filter: RankingFilter!): RankingConnection! @scope(scope: "user:read")
6+
}
7+
8+
input RankingFilter {
9+
by: RankingBy!
10+
order: RankingOrder!
11+
period: RankingPeriod!
12+
}
13+
14+
enum RankingBy {
15+
POINTS
16+
COMPLETED_QUESTIONS
17+
}
18+
19+
enum RankingOrder {
20+
ASC
21+
DESC
22+
}
23+
24+
enum RankingPeriod {
25+
DAILY
26+
WEEKLY
27+
}
28+
29+
type RankingConnection {
30+
edges: [RankingEdge!]!
31+
pageInfo: PageInfo!
32+
totalCount: Int!
33+
}
34+
35+
type RankingEdge {
36+
# User in the ranking
37+
node: User!
38+
cursor: Cursor!
39+
}

graph/rank.resolvers.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)