Skip to content

Commit

Permalink
Merge pull request #5 from nce/multidayride
Browse files Browse the repository at this point in the history
fix multiday trip creation
  • Loading branch information
nce authored Jul 28, 2024
2 parents 26d95ff + 591adac commit 39600ba
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cmd/newActivity/newActivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewNewCommand() *cobra.Command {
}

func newMtbCommand() *cobra.Command {
var act *activity.Activity
act := activity.Activity{}

cmd := &cobra.Command{
Use: "mtb [name]",
Expand Down Expand Up @@ -68,6 +68,7 @@ func newMtbCommand() *cobra.Command {
cmd.Flags().StringVarP(&dateStr, "date", "d", "", "Date of the activity in the format 'DD.MM.YYYY'")
cmd.Flags().BoolVarP(&act.Meta.StravaSync, "sync", "s", true, "Get activity stats from strava")
cmd.Flags().BoolVarP(&act.Meta.StravaGpxSync, "gpx", "g", true, "Get gpx track from strava")
cmd.Flags().BoolVarP(&act.Meta.Multiday, "mutli", "m", false, "Is part of a multiday activity")
cmd.Flags().BoolVarP(&act.Meta.QueryStartLocation, "start-location", "l", true, "Interactive"+
"query for starting locations")
cmd.Flags().IntVarP(&act.Tb.Rating, "rating", "r", 3, "Rating of the activity in the format '1-5'."+
Expand Down
3 changes: 2 additions & 1 deletion cmd/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ func NewSyncCommand() *cobra.Command {
var (
parsedDate time.Time
dateStr string
act *activity.Activity
)

act := activity.Activity{}

cmd := &cobra.Command{
Use: "sync",
Short: "Sync Strava data to Tourenbuch",
Expand Down
16 changes: 13 additions & 3 deletions pkg/activity/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Meta struct {
StravaGpxSync bool
StravaID int64
QueryStartLocation bool
Multiday bool
}

type Tourenbuch struct {
Expand Down Expand Up @@ -70,9 +71,18 @@ func (a *Activity) createFolder() error {
return err
}

dirs := [2]string{
textPath + a.Meta.Category + "/" + a.Meta.Name + "-" + a.normalizeDate(),
assetPath + a.Meta.Category + "/" + a.Meta.Name + "-" + a.normalizeDate() + "/" + "img",
// this is duplicated and should be refactored
var dirs [2]string
if a.Meta.Multiday {
dirs = [2]string{
textPath + a.Meta.Category + "/" + "multidaytrip/" + a.Meta.Name,
assetPath + a.Meta.Category + "/" + "multidaytrip/" + a.Meta.Name + "/" + "img",
}
} else {
dirs = [2]string{
textPath + a.Meta.Category + "/" + a.Meta.Name + "-" + a.normalizeDate(),
assetPath + a.Meta.Category + "/" + a.Meta.Name + "-" + a.normalizeDate() + "/" + "img",
}
}

for _, dir := range dirs {
Expand Down
10 changes: 8 additions & 2 deletions pkg/activity/mtb.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ func (a *Activity) StravaSync() error {
a.Meta.StravaID = stats.ID
a.Meta.Category = stats.SportType

a.Meta.TextLocation = text + a.Meta.Category + "/" + a.Meta.Name + "-" + a.normalizeDate() + "/"
a.Meta.AssetLocation = asset + a.Meta.Category + "/" + a.Meta.Name + "-" + a.normalizeDate() + "/"
// this is duplicated and should be refactored
if a.Meta.Multiday {
a.Meta.TextLocation = text + a.Meta.Category + "/" + "multidaytrip/" + a.Meta.Name + "/"
a.Meta.AssetLocation = asset + a.Meta.Category + "/" + "multidaytrip/" + a.Meta.Name + "/"
} else {
a.Meta.TextLocation = text + a.Meta.Category + "/" + a.Meta.Name + "-" + a.normalizeDate() + "/"
a.Meta.AssetLocation = asset + a.Meta.Category + "/" + a.Meta.Name + "-" + a.normalizeDate() + "/"
}

if a.Meta.TextLocation == "" {
return fmt.Errorf("found empty: %w", ErrTextLocationNotInitialized)
Expand Down

0 comments on commit 39600ba

Please sign in to comment.