Skip to content

Commit

Permalink
komoot planned vs completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Beutel committed Feb 14, 2025
1 parent 6b3fbfd commit a2ad4a4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
11 changes: 7 additions & 4 deletions db/integrations/komoot/komoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ func SyncKomoot(app *pocketbase.PocketBase) error {

userId := i.GetString("user")
komootString := i.GetString("komoot")
var komootIntegration KomootIntegration
komootIntegration := KomootIntegration{
Planned: true,
Completed: true,
}
json.Unmarshal([]byte(komootString), &komootIntegration)

if !komootIntegration.Active || komootIntegration.Email == "" || komootIntegration.Password == "" {
Expand Down Expand Up @@ -67,7 +70,7 @@ func SyncKomoot(app *pocketbase.PocketBase) error {
break
}

hasNewTours, err = syncTrailWithTours(app, k, userId, tours)
hasNewTours, err = syncTrailWithTours(app, k, komootIntegration, userId, tours)
if err != nil {
warning := fmt.Sprintf("error syncing komoot tours with trails: %v\n", err)
fmt.Print(warning)
Expand Down Expand Up @@ -172,14 +175,14 @@ func (k *KomootApi) fetchDetailedTour(tour KomootTour) (*DetailedKomootTour, err
return data, nil
}

func syncTrailWithTours(app *pocketbase.PocketBase, k *KomootApi, user string, tours []KomootTour) (bool, error) {
func syncTrailWithTours(app *pocketbase.PocketBase, k *KomootApi, i KomootIntegration, user string, tours []KomootTour) (bool, error) {
hasNewTours := false
for _, tour := range tours {
trails, err := app.Dao().FindRecordsByFilter("trails", "external_id = {:id}", "", 1, 0, dbx.Params{"id": strconv.Itoa(int(tour.ID))})
if err != nil {
return hasNewTours, err
}
if len(trails) != 0 {
if len(trails) != 0 || (tour.Type == "tour_planned" && !i.Planned) || (tour.Type == "tour_recorded" && !i.Completed) {
continue
}
hasNewTours = true
Expand Down
8 changes: 5 additions & 3 deletions db/integrations/komoot/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package komoot
import "time"

type KomootIntegration struct {
Active bool `json:"active"`
Email string `json:"email"`
Password string `json:"password"`
Active bool `json:"active"`
Email string `json:"email"`
Password string `json:"password"`
Planned bool `json:"planned"`
Completed bool `json:"completed"`
}

type LoginResponse struct {
Expand Down
5 changes: 4 additions & 1 deletion db/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,10 @@ func bootstrapMeilisearchTrails(app *pocketbase.PocketBase, client meilisearch.S
return err
}

client.Index("trails").DeleteAllDocuments()
_, err := client.Index("trails").DeleteAllDocuments()
if err != nil {
return err
}
for _, trail := range trails {
author, err := app.Dao().FindRecordById("users", trail.GetString(("author")))
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import Modal from "$lib/components/base/modal.svelte";
import TextField from "$lib/components/base/text_field.svelte";
import Toggle from "$lib/components/base/toggle.svelte";
import { KomootSchema } from "$lib/models/api/integration_schema";
import type {
Integration,
Expand All @@ -20,7 +21,7 @@
let modal: Modal;
export function openModal() {
errors.set({})
errors.set({});
modal.openModal();
}
Expand All @@ -32,13 +33,15 @@
initialValues: {
email: integration?.komoot?.email ?? "",
password: integration?.komoot?.password ?? "",
completed: integration?.komoot?.completed ?? true,
planned: integration?.komoot?.planned ?? true,
active: integration?.komoot?.active ?? false,
},
extend: validator({
schema: KomootSchema,
}),
onSubmit: async (form) => {
form.active = integration?.komoot?.active ?? form.active
form.active = integration?.komoot?.active ?? form.active;
onsave?.(form);
modal.closeModal();
},
Expand Down Expand Up @@ -66,6 +69,14 @@
type="password"
error={$errors.password}
></TextField>
<div class="flex gap-x-4">
<Toggle name="planned" label={$_("completed-tours", { values: { n: 2 } })}
></Toggle>
<Toggle
name="completed"
label={$_("planned-tours", { values: { n: 2 } })}
></Toggle>
</div>
</form>
{/snippet}
{#snippet footer()}
Expand Down

0 comments on commit a2ad4a4

Please sign in to comment.