Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
crlssn committed Nov 23, 2024
1 parent 0acb220 commit 6f2ee49
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 36 deletions.
43 changes: 21 additions & 22 deletions apps/backend/pkg/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion apps/backend/rpc/v1/routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 1 addition & 3 deletions apps/web/src/views/Auth/UserLogin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ const login = async () => {
</div>

<div>
<AppButton type="submit" colour="primary">
Login
</AppButton>
<AppButton type="submit" colour="primary"> Login </AppButton>
</div>
</form>

Expand Down
13 changes: 3 additions & 10 deletions apps/web/src/views/Auth/UserSignup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,15 @@ 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"
/>
</div>
</div>

<div>
<label for="email" class="block text-sm/6 font-medium text-gray-900">Last name</label>
<div class="mt-2">
<input
v-model="lastName"
name="lastname"
type="text"
required
/>
<input v-model="lastName" name="lastname" type="text" required />
</div>
</div>

Expand Down Expand Up @@ -133,9 +128,7 @@ const signup = async () => {
</div>

<div>
<AppButton type="submit" colour="primary">
Sign up
</AppButton>
<AppButton type="submit" colour="primary"> Sign up </AppButton>
</div>
</form>

Expand Down

0 comments on commit 6f2ee49

Please sign in to comment.