-
Notifications
You must be signed in to change notification settings - Fork 3
WIP: 更新時に部屋を削除してから作成するように変更 #665
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?
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 |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ import ( | |
| "github.com/traPtitech/knoQ/domain" | ||
| ) | ||
|
|
||
| func (s *service) CreateUnVerifiedRoom(ctx context.Context, reqID uuid.UUID, params domain.WriteRoomParams) (*domain.Room, error) { | ||
| func (s *service) CreateUnVerifiedRoom(ctx context.Context, reqID uuid.UUID, params domain.WriteRoomParams, update bool, oldRoom uuid.UUID) (*domain.Room, error) { | ||
| if !params.TimeConsistency() { | ||
| return nil, ErrTimeConsistency | ||
| } | ||
|
|
@@ -19,15 +19,20 @@ func (s *service) CreateUnVerifiedRoom(ctx context.Context, reqID uuid.UUID, par | |
| } | ||
| var roomResp *domain.Room | ||
| err := s.TxManager.Do(ctx, func(ctx context.Context) error { | ||
| var err error | ||
| var err, err2 error | ||
| if update { | ||
| err2 = s.GormRepo.DeleteRoom(ctx, oldRoom) | ||
| if err2 != nil { | ||
| return err2 | ||
| } | ||
| } | ||
| roomResp, err = s.GormRepo.CreateRoom(ctx, p) | ||
| return err | ||
| }) | ||
| return roomResp, defaultErrorHandling(err) | ||
| } | ||
|
|
||
| func (s *service) CreateVerifiedRoom(ctx context.Context, reqID uuid.UUID, params domain.WriteRoomParams) (*domain.Room, error) { | ||
|
|
||
| func (s *service) CreateVerifiedRoom(ctx context.Context, reqID uuid.UUID, params domain.WriteRoomParams, update bool, oldRoom uuid.UUID) (*domain.Room, error) { | ||
| if !s.IsPrivilege(ctx, reqID) { | ||
| return nil, domain.ErrForbidden | ||
| } | ||
|
|
@@ -42,7 +47,13 @@ func (s *service) CreateVerifiedRoom(ctx context.Context, reqID uuid.UUID, param | |
|
|
||
| var roomResp *domain.Room | ||
| err := s.TxManager.Do(ctx, func(ctx context.Context) error { | ||
| var err error | ||
| var err, err2 error | ||
| if update { | ||
| err2 = s.GormRepo.DeleteRoom(ctx, oldRoom) | ||
| if err2 != nil { | ||
| return err2 | ||
| } | ||
| } | ||
|
Comment on lines
+51
to
+56
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. 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- changed hunk ---'
git diff -- service/room_impl.go
printf '%s\n' '--- room implementation ---'
cat -n service/room_impl.go | sed -n '1,140p'
printf '%s\n' '--- bound symbols and callers ---'
rg -n -C 4 'DeleteRoom|UpdateEvent|TxManager|type Room|Events \[\]Event|CreateRoom|Allow|overlap|shared' service --glob '*.go'Repository: traPtitech/knoQ Length of output: 18467 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- repository and domain definitions ---'
rg -n -C 5 'func .*DeleteRoom|DeleteRoom\(|type Room struct|Events .*Event|RoomID|CreateUnVerifiedRoom|CreateVerifiedRoom' . --glob '*.go' --glob '!vendor/**'
printf '%s\n' '--- transaction manager definitions ---'
rg -n -C 8 'type .*TransactionManager|func .* Do\(|TransactionManager struct|BeginTx|Transaction' . --glob '*.go' --glob '!vendor/**'Repository: traPtitech/knoQ Length of output: 39911 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- room repository operations ---'
cat -n infra/db/room.go | sed -n '1,90p'
printf '%s\n' '--- event update path ---'
cat -n service/event_impl.go | sed -n '67,145p'
printf '%s\n' '--- transaction context resolution ---'
cat -n infra/db/transaction.go | sed -n '1,60p'
printf '%s\n' '--- room/event query and migration constraints ---'
rg -n -C 8 'func (getRoom|deleteRoom|updateEvent)|Preload\\("Events"|foreignKey:RoomID|OnDelete:CASCADE|AutoMigrate' infra/db migration --glob '*.go'Repository: traPtitech/knoQ Length of output: 7587 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- room CRUD implementation ---'
sed -n '78,180p' infra/db/room.go
printf '%s\n' '--- event CRUD implementation ---'
sed -n '100,180p' infra/db/event.go
printf '%s\n' '--- model relations ---'
sed -n '80,100p' infra/db/model.go
sed -n '160,180p' infra/db/model.goRepository: traPtitech/knoQ Length of output: 6363 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- database model base and migration setup ---'
sed -n '1,85p' infra/db/model.go
sed -n '1,90p' infra/db/db.go
printf '%s\n' '--- migration references to room/event constraints ---'
rg -n -C 5 'AutoMigrate|CreateConstraint|RoomID|OnDelete|foreign key|ForeignKey' migration infra/db --glob '*.go'Repository: traPtitech/knoQ Length of output: 25298 🌐 Web query:
💡 Result: In GORM, soft delete is a feature that allows you to mark records as deleted rather than permanently removing them from the database [1][2]. This is automatically enabled for any model that includes the gorm.DeletedAt field, which is part of the standard gorm.Model struct [1][3]. When a model has a gorm.DeletedAt field, the following behaviors apply: Delete Operations: Calling db.Delete does not execute a SQL DELETE statement. Instead, it performs an UPDATE statement that sets the DeletedAt field to the current timestamp [1][2]. Query Operations: Standard query methods (e.g., Find, First) automatically include a filter to exclude records where DeletedAt is not null (e.g., WHERE deleted_at IS NULL), effectively hiding soft-deleted data [1][4][2]. Accessing Soft-Deleted Records: To retrieve soft-deleted records, you must use the Unscoped method, which bypasses the automatic filter [5]. Example usage: type User struct { ID uint Name string DeletedAt gorm.DeletedAt Citations:
共有中の
🤖 Prompt for AI Agents |
||
| roomResp, err = s.GormRepo.CreateRoom(ctx, p) | ||
| return err | ||
| }) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: traPtitech/knoQ
Length of output: 16581
🏁 Script executed:
Repository: traPtitech/knoQ
Length of output: 32918
Verified ルームの更新認可を分離してください。
場所または時刻を変更すると、
UpdateEventはCreateVerifiedRoomを呼び出します。CreateVerifiedRoomはIsPrivilegeが false の場合にdomain.ErrForbiddenを返すため、非特権のイベント管理者はイベントを更新できません。許可が仕様の場合は、イベント管理者の認可を維持してください。🤖 Prompt for AI Agents