mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 18:54:17 +00:00
feat(journey): keep recorded days from a GPX file beside Dawarich
A GPX file is a second source of a journey's recorded days (#3085). The new route POST /api/journeys/:id/recordings/import-gpx (multipart, 15 MB, edit access, no Dawarich needed) and the MCP tool import_journey_gpx_days read the file's track segments through the place import's GPX reader, place every timed point on its local day in the zone of where it was recorded (or in one zone the caller fixes), cut the pieces at gaps, thin them like a Dawarich day and keep one day per date with source gpx in one transaction. Reading the file again replaces only its GPX days and leaves an unchanged day and every Dawarich day alone; a day that changed pings journey:recording:updated. A GPX day is stored with source_kind tracks, so the existing contract still reads it. DELETE :date and delete_journey_recorded_day take an optional source, Dawarich's when left out. The shared map shows a GPX day also without a published entry and prefers it over a Dawarich day of the same date; the list of kept days carries both, ordered by date and source. No migration: source and source_kind are text columns already.
This commit is contained in:
@@ -67,9 +67,13 @@ export class JourneyRecordedDaysRepository extends TrekRepository<JourneyRecorde
|
||||
]);
|
||||
}
|
||||
|
||||
/** The days a journey keeps, earliest first. */
|
||||
/** The days a journey keeps, earliest first, the sources of one day in the order of their names. */
|
||||
async listForJourney(journeyId: number): Promise<JourneyRecordedDayRow[]> {
|
||||
return await this.selectRows().where('d.journey_id', '=', journeyId).orderBy('d.local_date', 'asc').execute();
|
||||
return await this.selectRows()
|
||||
.where('d.journey_id', '=', journeyId)
|
||||
.orderBy('d.local_date', 'asc')
|
||||
.orderBy('d.source', 'asc')
|
||||
.execute();
|
||||
}
|
||||
|
||||
/** The version a journey keeps for one day of one source; undefined while it keeps none. */
|
||||
@@ -112,6 +116,36 @@ export class JourneyRecordedDaysRepository extends TrekRepository<JourneyRecorde
|
||||
return written.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps several days in one statement, each replacing the version kept for
|
||||
* its journey, day and source; a replaced day keeps its id and the time it
|
||||
* was first taken over. Nothing is written for an empty list.
|
||||
*/
|
||||
async upsertDays(days: readonly JourneyRecordedDayWrite[]): Promise<void> {
|
||||
if (days.length === 0) return;
|
||||
const now = dbNow();
|
||||
await this.db()
|
||||
.insertInto('journey_recorded_days')
|
||||
.values(days.map((day) => ({ ...day, created_at: now, updated_at: now })))
|
||||
.onConflict((oc) =>
|
||||
oc.columns(['journey_id', 'local_date', 'source']).doUpdateSet((eb) => ({
|
||||
source_kind: eb.ref('excluded.source_kind'),
|
||||
utc_offset_minutes: eb.ref('excluded.utc_offset_minutes'),
|
||||
window_from: eb.ref('excluded.window_from'),
|
||||
window_to: eb.ref('excluded.window_to'),
|
||||
segments: eb.ref('excluded.segments'),
|
||||
point_count: eb.ref('excluded.point_count'),
|
||||
distance_m: eb.ref('excluded.distance_m'),
|
||||
content_hash: eb.ref('excluded.content_hash'),
|
||||
truncated: eb.ref('excluded.truncated'),
|
||||
fetched_at: eb.ref('excluded.fetched_at'),
|
||||
imported_by: eb.ref('excluded.imported_by'),
|
||||
updated_at: now,
|
||||
})),
|
||||
)
|
||||
.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps a day only while the journey keeps none for that day and source, and
|
||||
* answers its id; undefined when another version was there first. Two takeovers
|
||||
|
||||
Reference in New Issue
Block a user