Skip to content
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

Add support for workouts #21

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tom-dudley
Copy link

This PR adds support for workouts (create, get, list, update and delete) and the ability to schedule them (create, list and delete). I've attached some docs at the end of the PR.

I've opted for a bunch of pointers in the Workout struct mainly to handle nil/null. This does mean consuming isn't 100% ideal, but seemed the best compromise (over pulling in other dependencies or leaving "" all over).

Happy to hear feedback and adjust accordingly.

API

Create workout

See below for example workout

workoutResponse, err := client.CreateWorkout(workout)

Get workout

workout, err := client.GetWorkout(workoutId)

Update workout

err = client.UpdateWorkout(workout)

Delete workout

client.DeleteScheduledWorkout(workoutScheduleId)

List workouts

workouts, err := client.Workout()

Schedule workout

workoutSchedule, err := client.ScheduleWorkout(workout, time.Date(...))

Get scheduled workouts

workoutSchedules, err := client.WorkoutSchedule(year, month)

Example workout

workoutToCreate := &connect.Workout{
    SportType: &connect.SportType{
        SportTypeId:  1,
        SportTypeKey: "running",
    },
    WorkoutName: "Test12345",
    WorkoutSegments: []*connect.WorkoutSegment{
        {
            SegmentOrder: 1,
            SportType: connect.SportType{
                SportTypeId:  1,
                SportTypeKey: "running",
            },
            WorkoutSteps: []connect.WorkoutStep{
                {
                    StepId:    1,
                    Type:      "ExecutableStepDTO",
                    StepOrder: 1,
                    StepType: &connect.StepType{
                        StepTypeId:  1,
                        StepTypeKey: "warmup",
                    },
                    EndCondition: &connect.EndCondition{
                        ConditionTypeId:  1,
                        ConditionTypeKey: "lap.button",
                    },
                    TargetType: &connect.TargetType{
                        WorkoutTargetTypeId:  1,
                        WorkoutTargetTypeKey: "no.target",
                    },
                },
            },
        },
    },
    AvgTrainingSpeed: 3.0,
}

@tom-dudley tom-dudley marked this pull request as draft February 22, 2023 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant