Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/pkg/errors v0.9.1
github.com/reearth/orb v0.0.0-20250123044717-f6f70ce16355
github.com/reearth/reearth-accounts/server v0.0.0-20260128022722-507516979112
github.com/reearth/reearth-accounts/server v0.0.0-20260331032127-27f24451e735
github.com/reearth/reearthx v0.0.0-20260303053047-71650b1e0cb5 // ref => https://github.com/reearth/reearthx/tree/fix/metadate-for-visualizer
github.com/samber/lo v1.52.0
github.com/spf13/afero v1.15.0
Expand Down
4 changes: 2 additions & 2 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ github.com/ravilushqa/otelgqlgen v0.19.0 h1:LbgdvOeZLW3y6qJoZHu2qd1srsB2aYRDiY8m
github.com/ravilushqa/otelgqlgen v0.19.0/go.mod h1:89WViMNkh5tnf6PYQGDFQDyLdhpQSlDdQ2/lYkdnlHg=
github.com/reearth/orb v0.0.0-20250123044717-f6f70ce16355 h1:hmQfd74d4+CdE7vz72n8OPAFocOwVo6yoczZ8eLYKi4=
github.com/reearth/orb v0.0.0-20250123044717-f6f70ce16355/go.mod h1:YWoaA2PfCxtfLyH9+pz5tZh9kwKbPEbRoaIA/DSCt10=
github.com/reearth/reearth-accounts/server v0.0.0-20260128022722-507516979112 h1:sO2AjUC7WLAypEnf2cD0V3X3wz7y2SgmSNUFX+tBEA4=
github.com/reearth/reearth-accounts/server v0.0.0-20260128022722-507516979112/go.mod h1:QsSV8aNxPZG0hk7gX/h3oOdeBwqwd5jqqT+6Z9JcvW4=
github.com/reearth/reearth-accounts/server v0.0.0-20260331032127-27f24451e735 h1:yBVU6oui/5bupamuOTug1FgmgfkGwZMAqY5bMsL1OJI=
github.com/reearth/reearth-accounts/server v0.0.0-20260331032127-27f24451e735/go.mod h1:SQX77AQKJWrQENu2DEnN1cKlqb+9ZLeqV1eJ2FDDYEQ=
github.com/reearth/reearthx v0.0.0-20260303053047-71650b1e0cb5 h1:5ARG8AaKVtHZ2QmWzwLIoqdX/5IZ94GFtF/hDv/WuG4=
github.com/reearth/reearthx v0.0.0-20260303053047-71650b1e0cb5/go.mod h1:z4JjOCy4MZZglLSrJx+btJ1ZLltESDZfSWJCnONwRS4=
github.com/rodaine/protogofakeit v0.1.1 h1:ZKouljuRM3A+TArppfBqnH8tGZHOwM/pjvtXe9DaXH8=
Expand Down
2 changes: 2 additions & 0 deletions server/gql/user.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Me {
lang: Lang!
theme: Theme!
metadata: UserMetadata
latestLogoutAt: DateTime
myWorkspaceId: ID!
auths: [String!]!
workspaces: [Workspace!]!
Expand Down Expand Up @@ -52,4 +53,5 @@ extend type Query {

extend type Mutation {
updateMe(input: UpdateMeInput!): UpdateMePayload
logout: Me
}
129 changes: 119 additions & 10 deletions server/internal/adapter/gql/generated.go

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

23 changes: 16 additions & 7 deletions server/internal/adapter/gql/gqlmodel/convert_user.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gqlmodel

import (
"time"

accountsUser "github.com/reearth/reearth-accounts/server/pkg/user"
"github.com/reearth/reearthx/util"
"github.com/samber/lo"
Expand Down Expand Up @@ -58,14 +60,21 @@ func ToMe(u *accountsUser.User) *Me {
theme = accountsUser.ThemeDefault
}

var latestLogoutAt *time.Time
if !u.LatestLogoutAt().IsZero() {
t := u.LatestLogoutAt()
latestLogoutAt = &t
}

return &Me{
ID: IDFrom(u.ID()),
Name: u.Name(),
Email: u.Email(),
Lang: lang,
Theme: Theme(theme),
Metadata: userMetadata,
MyWorkspaceID: IDFrom(u.Workspace()),
ID: IDFrom(u.ID()),
Name: u.Name(),
Email: u.Email(),
Lang: lang,
Theme: Theme(theme),
Metadata: userMetadata,
LatestLogoutAt: latestLogoutAt,
MyWorkspaceID: IDFrom(u.Workspace()),
Auths: util.Map(u.Auths(), func(a accountsUser.Auth) string {
return a.Provider
}),
Expand Down
21 changes: 11 additions & 10 deletions server/internal/adapter/gql/gqlmodel/models_gen.go

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

26 changes: 23 additions & 3 deletions server/internal/adapter/gql/resolver_mutation_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ func (r *mutationResolver) UpdateMe(ctx context.Context, input gqlmodel.UpdateMe
return &gqlmodel.UpdateMePayload{Me: gqlmodel.ToMe(u)}, nil
}

func (r *mutationResolver) Logout(ctx context.Context) (*gqlmodel.Me, error) {
userModel, err := r.AccountsAPIClient.UserRepo.Logout(ctx)
if err != nil {
return nil, err
}

u, err := buildAccountDomainUserFromAccountsUserModel(ctx, userModel)
if err != nil {
log.Errorfc(ctx, "failed to build user from accounts model: %v", err)
return nil, err
}

return gqlmodel.ToMe(u), nil
}

func buildAccountDomainUserFromAccountsUserModel(ctx context.Context, userModel *accountsUser.User) (*accountsUser.User, error) {
uId, _ := accountsUser.IDFrom(userModel.ID().String())
wid, _ := accountsWorkspace.IDFrom(userModel.Workspace().String())
Expand All @@ -65,15 +80,20 @@ func buildAccountDomainUserFromAccountsUserModel(ctx context.Context, userModel
auths = append(auths, accountsUser.AuthFrom(authStr.String()))
}

u, err := accountsUser.New().
b := accountsUser.New().
ID(uId).
Name(userModel.Name()).
Alias(userModel.Alias()).
Email(userModel.Email()).
Metadata(usermetadata).
Workspace(wid).
Auths(auths).
Build()
Auths(auths)

if !userModel.LatestLogoutAt().IsZero() {
b = b.LatestLogoutAt(userModel.LatestLogoutAt())
}

u, err := b.Build()

if err != nil {
log.Errorfc(ctx, "failed to build user: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions server/internal/adapter/gql/resolver_mutation_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (r *mutationResolver) UpdateWorkspace(ctx context.Context, input gqlmodel.U
if r.AccountsAPIClient != nil {
res, err := r.AccountsAPIClient.WorkspaceRepo.UpdateWorkspace(ctx, gqlclientWorkspace.UpdateWorkspaceInput{
WorkspaceID: tid.String(),
Name: input.Name,
Name: &input.Name,
Comment thread
soneda-yuya marked this conversation as resolved.
})
if err != nil {
return nil, err
Expand All @@ -88,7 +88,7 @@ func (r *mutationResolver) AddMemberToWorkspace(ctx context.Context, input gqlmo
role := gqlmodel.FromRole(input.Role)
res, err := r.AccountsAPIClient.WorkspaceRepo.AddUsersToWorkspace(ctx, gqlclientWorkspace.AddUsersToWorkspaceInput{
WorkspaceID: tid.String(),
Users: []gqlclientWorkspace.MemberInput{
Users: []gqlclientWorkspace.WorkspaceMemberInput{
Comment thread
soneda-yuya marked this conversation as resolved.
{UserID: uid.String(), Role: string(role)},
},
})
Expand Down
Loading
Loading