Skip to content

Commit

Permalink
Merge pull request #29 from fy23-gw-gackathon/fix/#28_GetUsers_query
Browse files Browse the repository at this point in the history
ref #28 fix GetUsers & insert organization data
  • Loading branch information
gari8 committed May 12, 2023
2 parents c85d5b2 + 5169f46 commit c9284ed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions data/init/2_insert.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
INSERT INTO `organizations` (`id`, `name`, `code`, `mission`, `vision`, `value`) VALUES
('01GZR0ZEMY9W4GP74E3G6GYEWY', '新卒研修部', 'NewGraduateTraining', 'ミッション', 'ビジョン', 'バリュー'),
('01GZR2TYVGFJKWH35BF2J5Z38E', '新卒研修部_後編', 'NewGraduateTraining2', 'ミッション', 'ビジョン', 'バリュー');
('01GZR2TYVGFJKWH35BF2J5Z38E', '技術統括部エンジニアリング室新卒研修', 'fy23-eng-training', '一人ひとりに想像を超えるDelightを', 'DeNAは、インターネットやAIを自在に駆使しながら 一人ひとりの人生を豊かにするエンターテインメント領域と 日々の生活を営む空間と時間をより快適にする社会課題領域の 両軸の事業を展開するユニークな特性を生かし 挑戦心豊かな社員それぞれの個性を余すことなく発揮することで 世界に通用する新しいDelightを提供し続けます', 'DeNA Promise');

INSERT INTO `users` (`id`, `cognito_id`, `name`, `email`) VALUES ('01GZT0HJAX3CM9P1V66T9GYM95', '28f155b7-860f-49c4-b059-5eed51a4ce4c', 'test.local', 'test.local@gmail.com');
INSERT INTO `r_organization_users` (`user_id`, `organization_id`, `role`) VALUES ('01GZT0HJAX3CM9P1V66T9GYM95', '01GZR2TYVGFJKWH35BF2J5Z38E', 1);
4 changes: 2 additions & 2 deletions infrastructure/persistence/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (p UserPersistence) GetUsers(ctx context.Context, organizationID string) ([
var record *model.Organization
if err := db.
Where("id = ?", organizationID).
Preload("Users").
Preload("Users.OrganizationUsers").
Find(&record).Error; err != nil {
return nil, err
}
Expand All @@ -51,7 +51,7 @@ func (p UserPersistence) GetUsers(ctx context.Context, organizationID string) ([
func (p UserPersistence) GetOrganizationUser(ctx context.Context, organizationCode string, userID string) (*entity.OrganizationUser, error) {
db, _ := ctx.Value(driver.TxKey).(*gorm.DB)
var record *model.OrganizationUser
if err := db.Preload("User", "id = ?", userID).Preload("Organization", "code = ?", organizationCode).First(&record).Error; err != nil {
if err := db.Where("user_id = ?", userID).Preload("User").Preload("Organization", "code = ?", organizationCode).First(&record).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, entity.NewError(http.StatusNotFound, err)
}
Expand Down

0 comments on commit c9284ed

Please sign in to comment.