|
@ -4,6 +4,7 @@ import ( |
|
|
"context" |
|
|
"context" |
|
|
|
|
|
|
|
|
"git.aiterp.net/rpdata/api/internal/session" |
|
|
"git.aiterp.net/rpdata/api/internal/session" |
|
|
|
|
|
"git.aiterp.net/rpdata/api/resolver/types" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// LoginArgs is args
|
|
|
// LoginArgs is args
|
|
@ -13,12 +14,12 @@ type LoginArgs struct { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Session resolves query.session
|
|
|
// Session resolves query.session
|
|
|
func (r *QueryResolver) Session(ctx context.Context) (*SessionResolver, error) { |
|
|
|
|
|
return &SessionResolver{S: session.FromContext(ctx)}, nil |
|
|
|
|
|
|
|
|
func (r *QueryResolver) Session(ctx context.Context) (*types.SessionResolver, error) { |
|
|
|
|
|
return &types.SessionResolver{S: session.FromContext(ctx)}, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Login resolves mutation.login
|
|
|
// Login resolves mutation.login
|
|
|
func (r *MutationResolver) Login(ctx context.Context, args *LoginArgs) (*SessionResolver, error) { |
|
|
|
|
|
|
|
|
func (r *MutationResolver) Login(ctx context.Context, args *LoginArgs) (*types.SessionResolver, error) { |
|
|
session := session.FromContext(ctx) |
|
|
session := session.FromContext(ctx) |
|
|
|
|
|
|
|
|
err := session.Login(args.Username, args.Password) |
|
|
err := session.Login(args.Username, args.Password) |
|
@ -26,26 +27,13 @@ func (r *MutationResolver) Login(ctx context.Context, args *LoginArgs) (*Session |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return &SessionResolver{S: session}, nil |
|
|
|
|
|
|
|
|
return &types.SessionResolver{S: session}, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Logout resolves mutation.logout
|
|
|
// Logout resolves mutation.logout
|
|
|
func (r *MutationResolver) Logout(ctx context.Context) (*SessionResolver, error) { |
|
|
|
|
|
|
|
|
func (r *MutationResolver) Logout(ctx context.Context) (*types.SessionResolver, error) { |
|
|
session := session.FromContext(ctx) |
|
|
session := session.FromContext(ctx) |
|
|
session.Logout() |
|
|
session.Logout() |
|
|
|
|
|
|
|
|
return &SessionResolver{S: session}, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// SessionResolver resolves Session
|
|
|
|
|
|
type SessionResolver struct{ S *session.Session } |
|
|
|
|
|
|
|
|
|
|
|
// User resolves Session.user
|
|
|
|
|
|
func (r *SessionResolver) User() *UserResolver { |
|
|
|
|
|
user := r.S.User() |
|
|
|
|
|
if user == nil { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return &UserResolver{U: user} |
|
|
|
|
|
|
|
|
return &types.SessionResolver{S: session}, nil |
|
|
} |
|
|
} |