-
Notifications
You must be signed in to change notification settings - Fork 3
UpdateEventの動作を変更する #447
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
base: main
Are you sure you want to change the base?
UpdateEventの動作を変更する #447
Changes from all commits
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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
| "github.com/traPtitech/knoQ/domain" | ||
| "github.com/traPtitech/knoQ/domain/filter" | ||
| "github.com/traPtitech/knoQ/infra/db" | ||
| "golang.org/x/exp/slices" | ||
| ) | ||
|
|
||
| func (repo *Repository) CreateEvent(params domain.WriteEventParams, info *domain.ConInfo) (*domain.Event, error) { | ||
|
|
@@ -49,22 +50,48 @@ func (repo *Repository) UpdateEvent(eventID uuid.UUID, params domain.WriteEventP | |
| WriteEventParams: params, | ||
| CreatedBy: info.ReqUserID, | ||
| } | ||
|
|
||
| event, err := repo.GormRepo.UpdateEvent(eventID, p) | ||
| if err != nil { | ||
| return nil, defaultErrorHandling(err) | ||
| } | ||
|
|
||
| // groupが変更されていないとき | ||
| if currentEvent.Group.ID == params.GroupID { | ||
| return repo.GetEvent(event.ID, info) | ||
| } | ||
|
|
||
| attendeesMap := make(map[uuid.UUID]domain.ScheduleStatus) | ||
| for _, attendee := range currentEvent.Attendees { | ||
| attendeesMap[attendee.UserID] = attendee.Schedule | ||
| } | ||
|
Comment on lines
+63
to
+67
Contributor
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. これより後ろの処理はグループが変わらなかったら行わなくても良い処理だと思うので、ここらへんで早期リターンするとよさそうです
Member
Author
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. 変更前の主催者メンバー全員が変更後の主催者メンバーであるとき早期リターンします 具体的には
Contributor
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.
Member
Author
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. たしかにそっちのほうがわかりやすそうです 一方で、 みたいな状況のときもできそうです。
Contributor
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. なるほど
をチェックしたいから1つ目をboolでもって
Member
Author
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.
あと、一番最初にras0qさんが変更を入れてほしいとおっしゃられた場所と、実際に私が
Member
Author
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. 今の変更点で不味そうなところがあったら、教えていただきたいです。
Contributor
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. 返信が遅くなってすみません
Contributor
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. - // 変更前のグループメンバー全員が変更後のグループメンバーであるとき
+ // 変更後に参加者から除外されるメンバーがいないときとかにするといいのかな |
||
|
|
||
| count := 0 | ||
| for _, groupMember := range group.Members { | ||
| exist := false | ||
| for _, currentAttendee := range currentEvent.Attendees { | ||
| if currentAttendee.UserID == groupMember.ID { | ||
| exist = true | ||
| } | ||
| } | ||
| if !exist { | ||
| if _, ok := attendeesMap[groupMember.ID]; !ok { | ||
| // 新しくグループメンバーになった人をPendingにする | ||
| _ = repo.GormRepo.UpsertEventSchedule(event.ID, groupMember.ID, domain.Pending) | ||
| count++ | ||
| } | ||
| } | ||
|
|
||
| // 変更前のグループメンバー全員が変更後のグループメンバーであるとき | ||
| // (変更前グループメンバーの数) = (変更後グループメンバーの数) - (変更後グループメンバーの中で新規グループメンバーの数) | ||
| if len(attendeesMap) == (len(group.Members) - count) { | ||
| return repo.GetEvent(event.ID, info) | ||
| } | ||
|
|
||
| for attendeeUserId, schedule := range attendeesMap { | ||
| ok := slices.ContainsFunc(group.Members, func(m domain.User) bool { | ||
| return m.ID == attendeeUserId | ||
| }) | ||
| // グループ外参加不可でグループメンバーから外れた人を削除 | ||
| // グループ外参加可でグループメンバーから外れた人でPendingだった人を削除 | ||
| if !ok && (!event.AllowTogether || schedule == domain.Pending) { | ||
| _ = repo.GormRepo.DeleteEventSchedule(event.ID, attendeeUserId) | ||
| } | ||
| } | ||
|
|
||
| return repo.GetEvent(event.ID, info) | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.