-
Notifications
You must be signed in to change notification settings - Fork 3
Refactor/hooks #630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor/hooks #630
Changes from 16 commits
10c2049
c237f0b
01e21dc
7502bb2
21f6fd7
b44693c
c9f3b04
2990035
3e8582a
e7e0267
1fe4e8b
30e0e03
6f7de9b
c9834b8
ec9dcf1
904fe1f
3cea8dc
6f7bcc7
e621dc1
6c66f9f
7898f41
e84a208
fb911d6
db6e5cc
70f6c91
b1982f1
0eb3a3c
c770992
74c5f96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,17 +76,46 @@ func (repo *gormRepository) GetAllEvents(expr filters.Expr) ([]*domain.Event, er | |
|
|
||
| func createEvent(db *gorm.DB, args domain.UpsertEventArgs) (*Event, error) { | ||
| event := ConvWriteEventParamsToEvent(args) | ||
|
|
||
| err := db.Create(&event).Error | ||
| var err error | ||
| var r *Room | ||
| r, err = getRoom(db, event.RoomID) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| event.Room = *r | ||
| // 対応する Room, Group はService層で確認済み | ||
| event.ID, err = uuid.NewV4() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| err = db.Create(&event).Error | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return &event, err | ||
| } | ||
|
|
||
| func updateEvent(db *gorm.DB, eventID uuid.UUID, args domain.UpsertEventArgs) (*Event, error) { | ||
| event := ConvWriteEventParamsToEvent(args) | ||
| event.ID = eventID | ||
| var err error | ||
| var r *Room | ||
| r, err = getRoom(db, event.RoomID) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| event.Room = *r | ||
|
|
||
| // 対応する Room, Group はService層で確認済み | ||
| err = db.Save(&event).Error | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, admin := range event.Admins { | ||
| db.Save(&admin) | ||
| } | ||
| for _, attendee := range event.Attendees { | ||
| db.Save(&attendee) | ||
| } | ||
Nzt3-gh marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+163
to
+179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 削除された Admin / Attendee / Tag が残り続けます。 今の更新処理は現在の配列を 🤖 Prompt for AI Agents |
||
|
|
||
| err := db.Session(&gorm.Session{FullSaveAssociations: true}). | ||
| Omit("CreatedAt").Save(&event).Error | ||
| return &event, err | ||
| } | ||
|
|
||
|
|
@@ -101,6 +130,14 @@ func addEventTag(db *gorm.DB, eventID uuid.UUID, params domain.EventTagParams) e | |
| } | ||
|
|
||
| func deleteEvent(db *gorm.DB, eventID uuid.UUID) error { | ||
| err := db.Where("event_id = ?", eventID).Delete(&EventTag{}).Error | ||
| if err != nil { | ||
| return err | ||
| } | ||
| err = db.Where("event_id = ?", eventID).Delete(&EventAdmin{}).Error | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return db.Delete(&Event{ID: eventID}).Error | ||
|
Comment on lines
+203
to
211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 依存行削除と Event 本体削除も同一トランザクションにしてください。
🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,7 +97,13 @@ func convSPGroupToSuuidUUID(src []*Group) (dst []uuid.UUID) { | |
|
|
||
| func createGroup(db *gorm.DB, args domain.UpsertGroupArgs) (*Group, error) { | ||
| group := ConvWriteGroupParamsToGroup(args) | ||
| err := db.Create(&group).Error | ||
| // IDを新規発行 | ||
| var err error | ||
| group.ID, err = uuid.NewV4() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| err = db.Create(&group).Error | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -107,8 +113,35 @@ func createGroup(db *gorm.DB, args domain.UpsertGroupArgs) (*Group, error) { | |
| func updateGroup(db *gorm.DB, groupID uuid.UUID, args domain.UpsertGroupArgs) (*Group, error) { | ||
| group := ConvWriteGroupParamsToGroup(args) | ||
| group.ID = groupID | ||
| err := db.Session(&gorm.Session{FullSaveAssociations: true}). | ||
| Omit("CreatedAt").Save(&group).Error | ||
| // groupIDは存在する | ||
| var err error | ||
| // CreatedBy は readonly | ||
| // GroupMember, GroupAdmin も User は readonly | ||
|
|
||
| // err = db.Session(&gorm.Session{FullSaveAssociations: true}). | ||
| // Omit("CreatedAt").Save(&group).Error | ||
|
|
||
| // GroupMenberの削除 | ||
| err = db.Where("group_id = ?", group.ID).Delete(&GroupMember{}).Error | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| // GroupAdminの削除 | ||
| err = db.Where("group_id = ?", group.ID).Delete(&GroupAdmin{}).Error | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| err = db.Omit("CreatedAt").Save(&group).Error | ||
|
|
||
| // GroupMember の更新 | ||
| for member := range group.Members { | ||
| db.Save(&member) | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // GroupAdmin の更新 | ||
| for admin := range group.Admins { | ||
| db.Save(&admin) | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| return &group, err | ||
|
Comment on lines
+145
to
181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ここは 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
@@ -121,14 +154,25 @@ func addMemberToGroup(db *gorm.DB, groupID, userID uuid.UUID) error { | |
| onConflictClause := clause.OnConflict{ | ||
| DoUpdates: clause.AssignmentColumns([]string{"updated_at", "deleted_at"}), | ||
| } | ||
|
|
||
| // groupMemberはhook登録なし | ||
| return db.Clauses(onConflictClause).Create(&groupMember).Error | ||
| } | ||
|
|
||
| func deleteGroup(db *gorm.DB, groupID uuid.UUID) error { | ||
| group := Group{ | ||
| ID: groupID, | ||
| } | ||
| // Group の GroupMember を削除 | ||
| err := db.Where("group_id = ?", group.ID).Delete(&GroupMember{}).Error | ||
| if err != nil { | ||
| return err | ||
| } | ||
| // GroupAdmin を削除 | ||
| err = db.Where("group_id = ?", group.ID).Delete(&GroupAdmin{}).Error | ||
| if err != nil { | ||
| return err | ||
| } | ||
| // Group を削除 | ||
| return db.Delete(&group).Error | ||
|
Comment on lines
+201
to
212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
migration/v8/model.go:106-131 では group 側に 🤖 Prompt for AI Agents |
||
| } | ||
|
Comment on lines
197
to
213
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deleteGroup がトランザクションで囲まれていません
🤖 Prompt for AI Agents |
||
|
|
||
|
|
@@ -137,6 +181,7 @@ func deleteMemberOfGroup(db *gorm.DB, groupID, userID uuid.UUID) error { | |
| GroupID: groupID, | ||
| UserID: userID, | ||
| } | ||
| // 1メンバーの削除 hooksは登録なし | ||
| return db.Delete(&groupMember).Error | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.