Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.

Commit 8f0c894

Browse files
authored
Merge pull request #85 from ProgrammingLab/gedorinku/fix_update_profile
プロフィールの更新でrole_idがnullになるのを修正
2 parents f2cd80c + 2d95dba commit 8f0c894

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

app/server/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func CreateTestUsers(ctx context.Context, s di.StoreComponent) ([]*record.User,
4141
ProfileScope: null.IntFrom(int(scope)),
4242
}
4343

44-
err := ps.CreateOrUpdateProfile(model.UserID(u.ID), p)
44+
err := ps.CreateOrUpdateProfile(model.UserID(u.ID), p, true)
4545
if err != nil {
4646
return nil, err
4747
}

app/server/users_server.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (s *userServiceServerImpl) UpdateUserRole(ctx context.Context, req *api_pb.
151151
}
152152

153153
ps := s.ProfileStore(ctx)
154-
err = ps.CreateOrUpdateProfile(model.UserID(u.ID), p)
154+
err = ps.CreateOrUpdateProfile(model.UserID(u.ID), p, true)
155155
if err != nil {
156156
return nil, err
157157
}
@@ -254,18 +254,13 @@ func (s *userServiceServerImpl) UpdateUserProfile(ctx context.Context, req *api_
254254
AtcoderUserName: null.StringFrom(req.GetAtcoderUserName()),
255255
DisplayName: null.StringFrom(req.GetDisplayName()),
256256
}
257-
if id := req.GetRoleId(); id == 0 {
258-
p.RoleID = null.NewInt64(0, false)
259-
} else {
260-
p.RoleID = null.Int64From(int64(id))
261-
}
262257
if id := req.GetDepartmentId(); id == 0 {
263258
p.DepartmentID = null.NewInt64(0, false)
264259
} else {
265260
p.DepartmentID = null.Int64From(int64(id))
266261
}
267262

268-
err = ps.CreateOrUpdateProfile(model.UserID(u.ID), p)
263+
err = ps.CreateOrUpdateProfile(model.UserID(u.ID), p, false)
269264
if err != nil {
270265
return nil, err
271266
}

infra/store/profile/profile_store.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewProfileStore(ctx context.Context, db *sqlutil.DB) store.ProfileStore {
2727
}
2828
}
2929

30-
func (s *profileStoreImpl) CreateOrUpdateProfile(userID model.UserID, profile *record.Profile) error {
30+
func (s *profileStoreImpl) CreateOrUpdateProfile(userID model.UserID, profile *record.Profile, updateRole bool) error {
3131
err := s.db.Watch(s.ctx, func(ctx context.Context, tx *sql.Tx) error {
3232
if profile.ID == 0 {
3333
err := profile.Insert(s.ctx, tx, boil.Infer())
@@ -43,7 +43,12 @@ func (s *profileStoreImpl) CreateOrUpdateProfile(userID model.UserID, profile *r
4343
return errors.WithStack(err)
4444
}
4545
} else {
46-
_, err := profile.Update(s.ctx, tx, boil.Infer())
46+
cols := []string{"updated_at", "description", "grade", "left", "department_id", "twitter_screen_name", "github_user_name", "profile_scope", "display_name", "atcoder_user_name"}
47+
if updateRole {
48+
cols = append(cols, "role_id")
49+
}
50+
li := boil.Whitelist(cols...)
51+
_, err := profile.Update(s.ctx, tx, li)
4752
if err != nil {
4853
return errors.WithStack(err)
4954
}

infra/store/profile_store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ import (
77

88
// ProfileStore accesses profiles data
99
type ProfileStore interface {
10-
CreateOrUpdateProfile(userID model.UserID, profile *record.Profile) error
10+
CreateOrUpdateProfile(userID model.UserID, profile *record.Profile, updateRole bool) error
1111
}

0 commit comments

Comments
 (0)