diff --git a/apps/backend/pkg/repo/repo.go b/apps/backend/pkg/repo/repo.go index ff6930b5..cc88a302 100644 --- a/apps/backend/pkg/repo/repo.go +++ b/apps/backend/pkg/repo/repo.go @@ -348,7 +348,7 @@ func (r *Repo) CreateRoutine(ctx context.Context, p CreateRoutineParams) (*orm.R return fmt.Errorf("routine exercises set: %w", err) } - if err = tx.UpdateRoutineExerciseOrder(ctx, routine.ID, p.ExerciseIDs); err != nil { + if err = tx.UpdateRoutine(ctx, routine.ID, UpdateRoutineExerciseOrder(p.ExerciseIDs)); err != nil { return fmt.Errorf("routine update: %w", err) } return nil @@ -465,11 +465,22 @@ func (r *Repo) ListRoutines(ctx context.Context, opts ...ListRoutineOpt) (orm.Ro return routines, nil } -type UpdateRoutineOpt func() orm.M +type UpdateRoutineOpt func() (orm.M, error) func UpdateRoutineName(name string) UpdateRoutineOpt { - return func() orm.M { - return orm.M{orm.RoutineColumns.Title: name} + return func() (orm.M, error) { + return orm.M{orm.RoutineColumns.Title: name}, nil + } +} + +func UpdateRoutineExerciseOrder(exerciseIDs []string) UpdateRoutineOpt { + return func() (orm.M, error) { + bytes, err := json.Marshal(exerciseIDs) + if err != nil { + return nil, fmt.Errorf("exercise IDs marshal: %w", err) + } + + return orm.M{orm.RoutineColumns.ExerciseOrder: bytes}, nil } } @@ -478,7 +489,12 @@ var errDuplicateColumn = fmt.Errorf("duplicate column") func (r *Repo) UpdateRoutine(ctx context.Context, routineID string, opts ...UpdateRoutineOpt) error { columns := orm.M{} for _, opt := range opts { - for key, value := range opt() { + column, err := opt() + if err != nil { + return fmt.Errorf("routine update opt: %w", err) + } + + for key, value := range column { if columns[key] != nil { return fmt.Errorf("%w: %s", errDuplicateColumn, key) } @@ -683,20 +699,3 @@ func (r *Repo) DeleteWorkout(ctx context.Context, opts ...DeleteWorkoutOpt) erro return nil }) } - -func (r *Repo) UpdateRoutineExerciseOrder(ctx context.Context, routineID string, exerciseIDs []string) error { - bytes, err := json.Marshal(exerciseIDs) - if err != nil { - return fmt.Errorf("exercise IDs marshal: %w", err) - } - - routine := &orm.Routine{ - ID: routineID, - ExerciseOrder: bytes, - } - if _, err = routine.Update(ctx, r.executor(), boil.Whitelist(orm.RoutineColumns.ExerciseOrder)); err != nil { - return fmt.Errorf("routine update: %w", err) - } - - return nil -} diff --git a/apps/backend/rpc/v1/routine.go b/apps/backend/rpc/v1/routine.go index 730c6387..8bea07e6 100644 --- a/apps/backend/rpc/v1/routine.go +++ b/apps/backend/rpc/v1/routine.go @@ -277,7 +277,7 @@ func (h *routineHandler) UpdateExerciseOrder(ctx context.Context, req *connect.R } } - if err = h.repo.UpdateRoutineExerciseOrder(ctx, routine.ID, req.Msg.GetExerciseIds()); err != nil { + if err = h.repo.UpdateRoutine(ctx, routine.ID, repo.UpdateRoutineExerciseOrder(req.Msg.GetExerciseIds())); err != nil { log.Error("update routine failed", zap.Error(err)) return nil, connect.NewError(connect.CodeInternal, nil) } diff --git a/apps/web/src/views/Auth/UserLogin.vue b/apps/web/src/views/Auth/UserLogin.vue index be12e064..348a4e33 100644 --- a/apps/web/src/views/Auth/UserLogin.vue +++ b/apps/web/src/views/Auth/UserLogin.vue @@ -99,9 +99,7 @@ const login = async () => {
- - Login - + Login
diff --git a/apps/web/src/views/Auth/UserSignup.vue b/apps/web/src/views/Auth/UserSignup.vue index 530bf3df..fb4ac62f 100644 --- a/apps/web/src/views/Auth/UserSignup.vue +++ b/apps/web/src/views/Auth/UserSignup.vue @@ -67,7 +67,7 @@ const signup = async () => { name="firstname" type="text" required - class="block w-full rounded-md border-0 bg-white/5 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm/6" + class="block w-full rounded-md border-0 bg-white/5 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm/6" /> @@ -75,12 +75,7 @@ const signup = async () => {
- +
@@ -133,9 +128,7 @@ const signup = async () => {
- - Sign up - + Sign up