Skip to content

Commit cd742b2

Browse files
authored
Merge pull request #33 from cweidner3/develop
Develop
2 parents 3a27d05 + 8ff782d commit cd742b2

File tree

10 files changed

+1826
-90
lines changed

10 files changed

+1826
-90
lines changed

api/src/bp/hikes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,19 @@ def one_hike(hike_id: int):
166166
return flask.jsonify(hike)
167167

168168

169+
@bp_hikes.get('/<int:hike_id>/waypoints')
170+
def get_hike_waypoints(hike_id: int):
171+
''' Get waypoints associated with the hike. '''
172+
with Session(engine) as session:
173+
wpts = session.execute(
174+
select(Waypoint)
175+
.where(Waypoint.parent == hike_id)
176+
.order_by(Waypoint.time)
177+
).scalars()
178+
wpts = list(map(lambda x: x.json, map(flask.jsonify, wpts)))
179+
return {'data': wpts}
180+
181+
169182
####################################################################################################
170183
# Restricted Routes
171184

api/src/bp/pics.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ def get_pic(pic_id: int):
7878
raise ValueError(f'Unhandled request method type "{flask.request.method}"')
7979

8080

81+
@bp_pics.get('/<int:pic_id>.<fmt>')
82+
def get_pic_data(pic_id: int, fmt: str):
83+
''' Return list of tracks. '''
84+
with Session(engine) as session:
85+
pic = session.execute(
86+
select(Picture.data)
87+
.where(Picture.id == pic_id)
88+
).one()
89+
return pic[0]
90+
91+
@bp_pics.get('/hike/<int:hike_id>')
92+
def get_pics_for_hike(hike_id: int):
93+
''' Get info on the pictures related to a hike. '''
94+
with Session(engine) as session:
95+
pics = session.execute(
96+
select(Picture)
97+
.where(Picture.parent == hike_id)
98+
.order_by(Picture.time)
99+
).scalars()
100+
pics = list(map(lambda x: x.json, map(flask.jsonify, pics)))
101+
return {"data": pics}
102+
81103
####################################################################################################
82104
# Restricted Routes
83105

api/src/bp/tracks.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sqlalchemy.orm import Session
44

55
from src.db.core import engine
6-
from src.db.models import Track, TrackData, TrackSegment
6+
from src.db.models import Hike, Track, TrackData, TrackSegment
77
from src.middleware import auth_as_admin
88

99
bp_tracks = flask.Blueprint('tracks', __name__, url_prefix='/tracks')
@@ -68,6 +68,36 @@ def list_track_points(track_id: int, segment_id: int):
6868
return points
6969

7070

71+
@bp_tracks.get('/hike/<int:hike_id>')
72+
def tracks_from_hike(hike_id: int):
73+
''' Manage a track instance. '''
74+
with Session(engine) as session:
75+
tracks = session.execute(
76+
select(Track)
77+
.where(Track.parent == hike_id)
78+
).scalars()
79+
80+
def _get_points(item):
81+
points = item.points
82+
points = map(lambda x: x.serialized, points)
83+
return list(points)
84+
85+
def _get_segments(item):
86+
segments = item.segments
87+
segments = map(_get_points, segments)
88+
segments = list(segments)
89+
return segments
90+
91+
def _format_track(item):
92+
obj = item.serialized
93+
obj['segments'] = _get_segments(item)
94+
return obj
95+
96+
tracks = map(_format_track, tracks)
97+
tracks = list(tracks)
98+
return {'data': tracks}
99+
100+
71101
####################################################################################################
72102
# Restricted Routes
73103

api/src/db/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def serialized(self) -> dict:
4444
'description': self.description,
4545
'tracks': list(map(lambda x: x.id, self.tracks)),
4646
'waypoints': list(map(lambda x: x.id, self.waypoints)),
47-
'pictures': list(map(lambda x: (x.id, f'{x.name}.{x.fmt}'), self.pictures)),
47+
'pictures': list(map(lambda x: (x.id, x.name), self.pictures)),
4848
}
4949
return ret
5050

api/tests/scripts/upload_test_hike.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ def _ts_w_tz(date_time: str, timezone: str) -> str:
3333
'zone': 'America/New_York',
3434
'title': 'My Test Hike',
3535
'brief': '3-day Hike Along North Chick Creek (Cumberland Trail)',
36+
'description': '''\
37+
This hike was **awesome**!!!
38+
39+
### Day 1
40+
41+
We started our hike on the trail after checking in with some rangers who were doing their rounds and
42+
we topped off our bottles with filtered water from the creek.
43+
44+
### Day 2
45+
46+
We considered continuing on the trail, but ended up coming to the conclusion that we wanted to make
47+
day 2 to be a _chill_ day.
48+
49+
### Day 3
50+
51+
We made our way back to the car and encountered many ticks along the way...
52+
'''
3653
}
3754

3855
TRACKS = list(Path(HERE, 'hike_data').glob('*.gpx'))

0 commit comments

Comments
 (0)