Skip to content

Commit

Permalink
feat: return gRPC responses indirectly to be more future-proof
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Oct 20, 2019
1 parent 261a3d4 commit 6d303a8
Show file tree
Hide file tree
Showing 8 changed files with 698 additions and 135 deletions.
18 changes: 15 additions & 3 deletions api/pwengine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ service Engine {
// Get current user session, based on JWT token
rpc GetUserSession(Void) returns (UserSessionOutput) { option (google.api.http) = {get: "/user-session"}; };
rpc SetPreferences(SetPreferencesInput) returns (Void) { option (google.api.http) = {post: "/preferences"; body: "*"}; };
rpc ListChallenges(Void) returns (pathwar.db.ChallengeList) { option (google.api.http) = {get: "/challenges"}; };
rpc ListTeams(Void) returns (pathwar.db.TeamList) { option (google.api.http) = {get: "/teams"}; };
rpc ListTournamentTeams(ListTournamentTeamsInput) returns (pathwar.db.TournamentTeamList) { option (google.api.http) = {get: "/tournament/teams"}; };
rpc ListChallenges(Void) returns (ListChallengesOutput) { option (google.api.http) = {get: "/challenges"}; };
rpc ListTeams(Void) returns (ListTeamsOutput) { option (google.api.http) = {get: "/teams"}; };
rpc ListTournamentTeams(ListTournamentTeamsInput) returns (ListTournamentTeamsOutput) { option (google.api.http) = {get: "/tournament/teams"}; };
rpc GetStatus(Void) returns (Status) { option (google.api.http) = {get: "/status"}; }

//
Expand All @@ -121,6 +121,18 @@ message SetPreferencesInput {
// bool dark_mode
}

message ListTournamentTeamsOutput {
repeated pathwar.db.TournamentTeam items = 1;
}

message ListTeamsOutput {
repeated pathwar.db.Team items = 1;
}

message ListChallengesOutput {
repeated pathwar.db.Challenge items = 1;
}

message UserSessionOutput {
message TournamentAndTeam {
pathwar.db.Tournament tournament = 1;
Expand Down
2 changes: 1 addition & 1 deletion docs/gen.sum

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

2 changes: 1 addition & 1 deletion go/gen.sum

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

6 changes: 2 additions & 4 deletions go/pkg/pwengine/api_pub_listchallenges.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package pwengine

import (
"context"

"pathwar.land/go/pkg/pwdb"
)

func (e *engine) ListChallenges(context.Context, *Void) (*pwdb.ChallengeList, error) {
var challenges pwdb.ChallengeList
func (e *engine) ListChallenges(context.Context, *Void) (*ListChallengesOutput, error) {
var challenges ListChallengesOutput
if err := e.db.Set("gorm:auto_preload", true).Find(&challenges.Items).Error; err != nil {
return nil, err
}
Expand Down
6 changes: 2 additions & 4 deletions go/pkg/pwengine/api_pub_listteams.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package pwengine

import (
"context"

"pathwar.land/go/pkg/pwdb"
)

func (e *engine) ListTeams(context.Context, *Void) (*pwdb.TeamList, error) {
var teams pwdb.TeamList
func (e *engine) ListTeams(context.Context, *Void) (*ListTeamsOutput, error) {
var teams ListTeamsOutput
if err := e.db.Set("gorm:auto_preload", true).Find(&teams.Items).Error; err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/pwengine/api_pub_listtournamentteams.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"pathwar.land/go/pkg/pwdb"
)

func (e *engine) ListTournamentTeams(ctx context.Context, in *ListTournamentTeamsInput) (*pwdb.TournamentTeamList, error) {
func (e *engine) ListTournamentTeams(ctx context.Context, in *ListTournamentTeamsInput) (*ListTournamentTeamsOutput, error) {
{ // validation
if in.TournamentID == 0 {
return nil, ErrMissingArgument
Expand All @@ -28,7 +28,7 @@ func (e *engine) ListTournamentTeams(ctx context.Context, in *ListTournamentTeam
}
}

var ret pwdb.TournamentTeamList
var ret ListTournamentTeamsOutput
err := e.db.
Set("gorm:auto_preload", true).
Where(pwdb.TournamentTeam{TournamentID: in.TournamentID}).
Expand Down
747 changes: 651 additions & 96 deletions go/pkg/pwengine/pwengine.pb.go

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions swagger.yaml

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

0 comments on commit 6d303a8

Please sign in to comment.