From 152829b1510c18b342360740b69ca97319b92f2c Mon Sep 17 00:00:00 2001 From: taminororo <169162271+taminororo@users.noreply.github.com> Date: Thu, 25 Jun 2026 01:57:05 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20shift=5Fusecase=20=E3=81=AE=20Find?= =?UTF-8?q?=E2=86=92Scan=20=E9=80=A3=E9=8E=96=E3=81=A7=E3=81=AE=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E6=8F=A1=E3=82=8A=E6=BD=B0=E3=81=97=E3=82=92?= =?UTF-8?q?=E8=A7=A3=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/lib/usecase/shift_usecase.go | 39 ++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/api/lib/usecase/shift_usecase.go b/api/lib/usecase/shift_usecase.go index bad9e81..ccc4ee0 100755 --- a/api/lib/usecase/shift_usecase.go +++ b/api/lib/usecase/shift_usecase.go @@ -73,7 +73,6 @@ func (a ByTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByTime) Less(i, j int) bool { return a[i].Time.ID < a[j].Time.ID } func (a *shiftUseCase) GetUsersByShift(c context.Context, task string, year string, date string, time string, weather string) (entity.ShiftUsers, error) { - users := entity.User{} var shiftUsers entity.ShiftUsers @@ -109,14 +108,23 @@ func (a *shiftUseCase) GetUsersByShift(c context.Context, task string, year stri } row, err := a.yearRep.Find(c, year) + if err != nil { + return shiftUsers, err + } err = row.Scan( &shiftUsers.Year.ID, &shiftUsers.Year.Year, &shiftUsers.Year.CreatedAt, &shiftUsers.Year.UpdatedAt, ) + if err != nil { + return shiftUsers, err + } row, err = a.dateRep.Find(c, date) + if err != nil { + return shiftUsers, err + } err = row.Scan( &shiftUsers.Date.ID, &shiftUsers.Date.YearID, @@ -125,14 +133,26 @@ func (a *shiftUseCase) GetUsersByShift(c context.Context, task string, year stri &shiftUsers.Date.CreatedAt, &shiftUsers.Date.UpdatedAt, ) + if err != nil { + return shiftUsers, err + } row, err = a.timeRep.Find(c, time) + if err != nil { + return shiftUsers, err + } err = row.Scan( &shiftUsers.Time.ID, &shiftUsers.Time.Time, &shiftUsers.Time.CreatedAt, &shiftUsers.Time.UpdatedAt, ) + if err != nil { + return shiftUsers, err + } row, err = a.weatherRep.Find(c, weather) + if err != nil { + return shiftUsers, err + } err = row.Scan( &shiftUsers.Weather.ID, &shiftUsers.Weather.Weather, @@ -152,6 +172,9 @@ func (a *shiftUseCase) GetUsersByShift(c context.Context, task string, year stri func (a *shiftUseCase) GetShiftAdminByID(c context.Context, id string) (entity.ShiftAdmin, error) { var shift entity.ShiftAdmin row, err := a.rep.Find(c, id) + if err != nil { + return shift, err + } err = row.Scan( &shift.ID, &shift.TaskID, @@ -174,7 +197,13 @@ func (a *shiftUseCase) GetShiftAdminByID(c context.Context, id string) (entity.S func (u *shiftUseCase) CreateShiftAdmin(c context.Context, taskID string, userID string, yearID string, dateID string, timeID string, weatherID string, isAttendance string) (entity.ShiftAdmin, error) { var latastShift entity.ShiftAdmin err := u.rep.Create(c, taskID, userID, yearID, dateID, timeID, weatherID, isAttendance) + if err != nil { + return latastShift, err + } row, err := u.rep.FindLatestRecord(c) + if err != nil { + return latastShift, err + } err = row.Scan( &latastShift.ID, &latastShift.TaskID, @@ -190,7 +219,7 @@ func (u *shiftUseCase) CreateShiftAdmin(c context.Context, taskID string, userID if err != nil { return latastShift, err } - return latastShift, err + return latastShift, nil } func (u *shiftUseCase) UpdateShiftAdmin(c context.Context, id string, taskID string, userID string, yearID string, dateID string, timeID string, weatherID string, isAttendance string) (entity.ShiftAdmin, error) { @@ -198,6 +227,9 @@ func (u *shiftUseCase) UpdateShiftAdmin(c context.Context, id string, taskID str var shift entity.ShiftAdmin row, err := u.rep.Find(c, id) + if err != nil { + return updatedShift, err + } err = row.Scan( &shift.ID, &shift.TaskID, @@ -218,6 +250,9 @@ func (u *shiftUseCase) UpdateShiftAdmin(c context.Context, id string, taskID str return updatedShift, err } row, err = u.rep.Find(c, id) + if err != nil { + return updatedShift, err + } err = row.Scan( &updatedShift.ID, &updatedShift.TaskID, From b78e59ee9bde52543fb5a0f8eca762c0e74bda02 Mon Sep 17 00:00:00 2001 From: taminororo <169162271+taminororo@users.noreply.github.com> Date: Thu, 25 Jun 2026 02:21:44 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20CreateShiftAdmin=20=E3=82=92=20Creat?= =?UTF-8?q?eAndReturnID+Find=20=E3=81=AB=E5=A4=89=E6=9B=B4=E3=81=97?= =?UTF-8?q?=E4=B8=A6=E8=A1=8C=E4=BD=9C=E6=88=90=E6=99=82=E3=81=AE=E8=A1=8C?= =?UTF-8?q?=E5=8F=96=E3=82=8A=E9=81=95=E3=81=88=E3=82=92=E8=A7=A3=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/lib/usecase/shift_usecase.go | 43 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/api/lib/usecase/shift_usecase.go b/api/lib/usecase/shift_usecase.go index ccc4ee0..abe7d96 100755 --- a/api/lib/usecase/shift_usecase.go +++ b/api/lib/usecase/shift_usecase.go @@ -195,31 +195,30 @@ func (a *shiftUseCase) GetShiftAdminByID(c context.Context, id string) (entity.S } func (u *shiftUseCase) CreateShiftAdmin(c context.Context, taskID string, userID string, yearID string, dateID string, timeID string, weatherID string, isAttendance string) (entity.ShiftAdmin, error) { - var latastShift entity.ShiftAdmin - err := u.rep.Create(c, taskID, userID, yearID, dateID, timeID, weatherID, isAttendance) + var createdShift entity.ShiftAdmin + id, err := u.rep.CreateAndReturnID(c, taskID, userID, yearID, dateID, timeID, weatherID, isAttendance) if err != nil { - return latastShift, err + return createdShift, errors.Wrapf(err, "シフト作成に失敗: %v", err) } - row, err := u.rep.FindLatestRecord(c) + row, err := u.rep.Find(c, strconv.Itoa(id)) if err != nil { - return latastShift, err - } - err = row.Scan( - &latastShift.ID, - &latastShift.TaskID, - &latastShift.UserID, - &latastShift.YearID, - &latastShift.DateID, - &latastShift.TimeID, - &latastShift.WeatherID, - &latastShift.IsAttendance, - &latastShift.CreatedAt, - &latastShift.UpdatedAt, - ) - if err != nil { - return latastShift, err - } - return latastShift, nil + return createdShift, errors.Wrapf(err, "作成したシフトの取得に失敗: %v", err) + } + if err := row.Scan( + &createdShift.ID, + &createdShift.TaskID, + &createdShift.UserID, + &createdShift.YearID, + &createdShift.DateID, + &createdShift.TimeID, + &createdShift.WeatherID, + &createdShift.IsAttendance, + &createdShift.CreatedAt, + &createdShift.UpdatedAt, + ); err != nil { + return createdShift, errors.Wrapf(err, "作成したシフトのScanに失敗: %v", err) + } + return createdShift, nil } func (u *shiftUseCase) UpdateShiftAdmin(c context.Context, id string, taskID string, userID string, yearID string, dateID string, timeID string, weatherID string, isAttendance string) (entity.ShiftAdmin, error) {