From 7c391fb22ef27c9f2103752c38052cdca8ce0df0 Mon Sep 17 00:00:00 2001 From: Hokubu Subway Date: Wed, 19 Aug 2026 22:02:46 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=99=82=E3=81=AB?= =?UTF-8?q?=E9=83=A8=E5=B1=8B=E3=82=92=E5=89=8A=E9=99=A4=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=8B=E3=82=89=E4=BD=9C=E6=88=90=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/room.go | 4 ++-- go.mod | 2 +- go.sum | 2 ++ router/presentation/room.go | 2 +- router/rooms.go | 2 +- service/event_impl.go | 4 ++-- service/room_impl.go | 10 ++++++++-- 7 files changed, 17 insertions(+), 9 deletions(-) diff --git a/domain/room.go b/domain/room.go index c9630fc2..38d4995b 100644 --- a/domain/room.go +++ b/domain/room.go @@ -145,7 +145,7 @@ func (r *Room) AdminsValidation() bool { type WriteRoomParams struct { Place string - // Verifeid indicates if the room has been verified by privileged users. + // Verified indicates if the room has been verified by privileged users. TimeStart time.Time TimeEnd time.Time @@ -157,7 +157,7 @@ func (r *WriteRoomParams) TimeConsistency() bool { } type RoomService interface { - CreateUnVerifiedRoom(ctx context.Context, reqID uuid.UUID, params WriteRoomParams) (*Room, error) + CreateUnVerifiedRoom(ctx context.Context, reqID uuid.UUID, params WriteRoomParams, update bool, oldRoom uuid.UUID) (*Room, error) CreateVerifiedRoom(ctx context.Context, reqID uuid.UUID, params WriteRoomParams) (*Room, error) UpdateRoom(ctx context.Context, reqID uuid.UUID, roomID uuid.UUID, params WriteRoomParams) (*Room, error) diff --git a/go.mod b/go.mod index 8e541043..144b253d 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/ory/dockertest/v3 v3.12.0 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/robfig/cron/v3 v3.0.1 - github.com/samber/lo v1.52.0 + github.com/samber/lo v1.53.0 github.com/stretchr/testify v1.11.1 github.com/traPtitech/go-traq v0.0.0-20251201015624-285ca186fc5e go.uber.org/zap v1.27.1 diff --git a/go.sum b/go.sum index 2b3aa0a5..80849ff1 100644 --- a/go.sum +++ b/go.sum @@ -128,6 +128,8 @@ github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0t github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/samber/lo v1.52.0 h1:Rvi+3BFHES3A8meP33VPAxiBZX/Aws5RxrschYGjomw= github.com/samber/lo v1.52.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0= +github.com/samber/lo v1.53.0 h1:t975lj2py4kJPQ6haz1QMgtId2gtmfktACxIXArw3HM= +github.com/samber/lo v1.53.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/router/presentation/room.go b/router/presentation/room.go index 88137ced..4d6e3527 100644 --- a/router/presentation/room.go +++ b/router/presentation/room.go @@ -33,7 +33,7 @@ type StartEndTime struct { type RoomRes struct { ID uuid.UUID `json:"roomId"` - // Verifeid indicates if the room has been verified by privileged users. + // Verified indicates if the room has been verified by privileged users. Verified bool `json:"verified"` RoomReq FreeTimes []StartEndTime `json:"freeTimes" cvt:"-"` diff --git a/router/rooms.go b/router/rooms.go index 3fedb9db..3c2b0a61 100644 --- a/router/rooms.go +++ b/router/rooms.go @@ -19,7 +19,7 @@ func (h *Handlers) HandlePostRoom(c echo.Context) error { roomParams := presentation.ConvRoomReqTodomainWriteRoomParams(req) ctx := c.Request().Context() reqID := c.Get(userIDKey).(uuid.UUID) - room, err := h.Service.CreateUnVerifiedRoom(ctx, reqID, roomParams) + room, err := h.Service.CreateUnVerifiedRoom(ctx, reqID, roomParams, false, uuid.Nil) if err != nil { return judgeErrorResponse(err) } diff --git a/service/event_impl.go b/service/event_impl.go index 9ab3e084..dfda59ce 100644 --- a/service/event_impl.go +++ b/service/event_impl.go @@ -35,7 +35,7 @@ func (s *service) CreateEvent(ctx context.Context, reqID uuid.UUID, params domai } // UnVerifiedを仮定 var r *domain.Room - r, err = s.CreateUnVerifiedRoom(ctx, reqID, roomParams) + r, err = s.CreateUnVerifiedRoom(ctx, reqID, roomParams, false, uuid.Nil) if err != nil { return err } @@ -107,7 +107,7 @@ func (s *service) UpdateEvent(ctx context.Context, reqID uuid.UUID, eventID uuid } // UnVerifiedを仮定 var r *domain.Room - r, err = s.CreateUnVerifiedRoom(ctx, reqID, roomParams) + r, err = s.CreateUnVerifiedRoom(ctx, reqID, roomParams, true, currentEvent.Room.ID) if err != nil { return err } diff --git a/service/room_impl.go b/service/room_impl.go index 9f4429c5..1c3c4673 100644 --- a/service/room_impl.go +++ b/service/room_impl.go @@ -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,7 +19,13 @@ 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 }) From fa2037204bd3ff1003770002a0f70e4802e376b7 Mon Sep 17 00:00:00 2001 From: Hokubu Subway Date: Wed, 26 Aug 2026 21:19:50 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Verified/Unverified=20=E3=81=AE=E5=88=A4?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/room.go | 1 - service/event_impl.go | 8 ++++++-- service/room_impl.go | 11 ++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/domain/room.go b/domain/room.go index 38d4995b..af11360a 100644 --- a/domain/room.go +++ b/domain/room.go @@ -145,7 +145,6 @@ func (r *Room) AdminsValidation() bool { type WriteRoomParams struct { Place string - // Verified indicates if the room has been verified by privileged users. TimeStart time.Time TimeEnd time.Time diff --git a/service/event_impl.go b/service/event_impl.go index dfda59ce..7df33151 100644 --- a/service/event_impl.go +++ b/service/event_impl.go @@ -105,9 +105,13 @@ func (s *service) UpdateEvent(ctx context.Context, reqID uuid.UUID, eventID uuid TimeEnd: params.TimeEnd, Admins: params.Admins, } - // UnVerifiedを仮定 + // UnVerified か Verified かを判定 var r *domain.Room - r, err = s.CreateUnVerifiedRoom(ctx, reqID, roomParams, true, currentEvent.Room.ID) + if currentEvent.Room.Verified { + r, err = s.CreateVerifiedRoom(ctx, reqID, roomParams, true, currentEvent.Room.ID) + } else { + r, err = s.CreateUnVerifiedRoom(ctx, reqID, roomParams, true, currentEvent.Room.ID) + } if err != nil { return err } diff --git a/service/room_impl.go b/service/room_impl.go index 1c3c4673..e1ca2766 100644 --- a/service/room_impl.go +++ b/service/room_impl.go @@ -32,8 +32,7 @@ func (s *service) CreateUnVerifiedRoom(ctx context.Context, reqID uuid.UUID, par 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 } @@ -48,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 + } + } roomResp, err = s.GormRepo.CreateRoom(ctx, p) return err }) From d6641568178138897909c806adba06df6c877a63 Mon Sep 17 00:00:00 2001 From: Hokubu Subway Date: Wed, 26 Aug 2026 21:22:19 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=AE=E8=AA=A4=E3=82=8A=20(Verified=20=E3=83=95=E3=82=A3?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E3=83=89=E3=81=AF=E5=AD=98=E5=9C=A8=E3=81=97?= =?UTF-8?q?=E3=81=AA=E3=81=84)=20=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/room.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/domain/room.go b/domain/room.go index af11360a..d29cd7d8 100644 --- a/domain/room.go +++ b/domain/room.go @@ -157,7 +157,7 @@ func (r *WriteRoomParams) TimeConsistency() bool { type RoomService interface { CreateUnVerifiedRoom(ctx context.Context, reqID uuid.UUID, params WriteRoomParams, update bool, oldRoom uuid.UUID) (*Room, error) - CreateVerifiedRoom(ctx context.Context, reqID uuid.UUID, params WriteRoomParams) (*Room, error) + CreateVerifiedRoom(ctx context.Context, reqID uuid.UUID, params WriteRoomParams, update bool, oldRoom uuid.UUID) (*Room, error) UpdateRoom(ctx context.Context, reqID uuid.UUID, roomID uuid.UUID, params WriteRoomParams) (*Room, error) VerifyRoom(ctx context.Context, reqID uuid.UUID, roomID uuid.UUID) error From dd8336d14f0cb5f61e2f1b60ea48a279d91dcc86 Mon Sep 17 00:00:00 2001 From: Hokubu Subway Date: Wed, 26 Aug 2026 21:23:54 +0900 Subject: [PATCH 4/4] =?UTF-8?q?CI=20=E3=82=92=E9=80=9A=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/rooms.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router/rooms.go b/router/rooms.go index 3c2b0a61..442935e8 100644 --- a/router/rooms.go +++ b/router/rooms.go @@ -49,7 +49,7 @@ func (h *Handlers) HandleCreateVerifedRooms(c echo.Context) error { return badRequest(err) } - room, err := h.Service.CreateVerifiedRoom(ctx, reqID, *params) + room, err := h.Service.CreateVerifiedRoom(ctx, reqID, *params, false, uuid.Nil) if err != nil { return judgeErrorResponse(err) }