Convert backend from submodule to regular directory
Some checks failed
Deploy to NAS / deploy (push) Failing after 4s
Some checks failed
Deploy to NAS / deploy (push) Failing after 4s
Remove submodule tracking; backend is now a plain directory in the repo. Also update deploy workflow: remove --recurse-submodules. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
60
backend/internal/db/stops.go
Normal file
60
backend/internal/db/stops.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"github.com/jacek/pamietnik/backend/internal/domain"
|
||||
)
|
||||
|
||||
type StopStore struct {
|
||||
pool *pgxpool.Pool
|
||||
}
|
||||
|
||||
func NewStopStore(pool *pgxpool.Pool) *StopStore {
|
||||
return &StopStore{pool: pool}
|
||||
}
|
||||
|
||||
func (s *StopStore) ListByDate(ctx context.Context, userID, date string) ([]domain.Stop, error) {
|
||||
rows, err := s.pool.Query(ctx, `
|
||||
SELECT st.stop_id, st.device_id, st.trip_id,
|
||||
st.start_ts, st.end_ts,
|
||||
st.center_lat, st.center_lon, st.duration_s,
|
||||
COALESCE(st.place_label, ''),
|
||||
st.place_details
|
||||
FROM stops st
|
||||
JOIN devices d ON d.device_id = st.device_id
|
||||
WHERE d.user_id = $1
|
||||
AND DATE(st.start_ts AT TIME ZONE 'UTC') = $2::date
|
||||
ORDER BY st.start_ts`,
|
||||
userID, date,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
return pgx.CollectRows(rows, func(row pgx.CollectableRow) (domain.Stop, error) {
|
||||
var st domain.Stop
|
||||
err := row.Scan(
|
||||
&st.StopID, &st.DeviceID, &st.TripID,
|
||||
&st.StartTS, &st.EndTS,
|
||||
&st.CenterLat, &st.CenterLon, &st.DurationS,
|
||||
&st.PlaceLabel, &st.PlaceDetails,
|
||||
)
|
||||
return st, err
|
||||
})
|
||||
}
|
||||
|
||||
func (s *StopStore) Insert(ctx context.Context, st domain.Stop) error {
|
||||
_, err := s.pool.Exec(ctx, `
|
||||
INSERT INTO stops (stop_id, device_id, trip_id, start_ts, end_ts,
|
||||
center_lat, center_lon, duration_s, place_label, place_details)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)
|
||||
ON CONFLICT (stop_id) DO NOTHING`,
|
||||
st.StopID, st.DeviceID, st.TripID, st.StartTS, st.EndTS,
|
||||
st.CenterLat, st.CenterLon, st.DurationS, st.PlaceLabel, st.PlaceDetails,
|
||||
)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user