Skip to content

Commit

Permalink
Merge pull request #33 from cweidner3/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
cweidner3 authored Dec 12, 2022
2 parents 3a27d05 + 8ff782d commit cd742b2
Show file tree
Hide file tree
Showing 10 changed files with 1,826 additions and 90 deletions.
13 changes: 13 additions & 0 deletions api/src/bp/hikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ def one_hike(hike_id: int):
return flask.jsonify(hike)


@bp_hikes.get('/<int:hike_id>/waypoints')
def get_hike_waypoints(hike_id: int):
''' Get waypoints associated with the hike. '''
with Session(engine) as session:
wpts = session.execute(
select(Waypoint)
.where(Waypoint.parent == hike_id)
.order_by(Waypoint.time)
).scalars()
wpts = list(map(lambda x: x.json, map(flask.jsonify, wpts)))
return {'data': wpts}


####################################################################################################
# Restricted Routes

Expand Down
22 changes: 22 additions & 0 deletions api/src/bp/pics.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ def get_pic(pic_id: int):
raise ValueError(f'Unhandled request method type "{flask.request.method}"')


@bp_pics.get('/<int:pic_id>.<fmt>')
def get_pic_data(pic_id: int, fmt: str):
''' Return list of tracks. '''
with Session(engine) as session:
pic = session.execute(
select(Picture.data)
.where(Picture.id == pic_id)
).one()
return pic[0]

@bp_pics.get('/hike/<int:hike_id>')
def get_pics_for_hike(hike_id: int):
''' Get info on the pictures related to a hike. '''
with Session(engine) as session:
pics = session.execute(
select(Picture)
.where(Picture.parent == hike_id)
.order_by(Picture.time)
).scalars()
pics = list(map(lambda x: x.json, map(flask.jsonify, pics)))
return {"data": pics}

####################################################################################################
# Restricted Routes

Expand Down
32 changes: 31 additions & 1 deletion api/src/bp/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy.orm import Session

from src.db.core import engine
from src.db.models import Track, TrackData, TrackSegment
from src.db.models import Hike, Track, TrackData, TrackSegment
from src.middleware import auth_as_admin

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


@bp_tracks.get('/hike/<int:hike_id>')
def tracks_from_hike(hike_id: int):
''' Manage a track instance. '''
with Session(engine) as session:
tracks = session.execute(
select(Track)
.where(Track.parent == hike_id)
).scalars()

def _get_points(item):
points = item.points
points = map(lambda x: x.serialized, points)
return list(points)

def _get_segments(item):
segments = item.segments
segments = map(_get_points, segments)
segments = list(segments)
return segments

def _format_track(item):
obj = item.serialized
obj['segments'] = _get_segments(item)
return obj

tracks = map(_format_track, tracks)
tracks = list(tracks)
return {'data': tracks}


####################################################################################################
# Restricted Routes

Expand Down
2 changes: 1 addition & 1 deletion api/src/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def serialized(self) -> dict:
'description': self.description,
'tracks': list(map(lambda x: x.id, self.tracks)),
'waypoints': list(map(lambda x: x.id, self.waypoints)),
'pictures': list(map(lambda x: (x.id, f'{x.name}.{x.fmt}'), self.pictures)),
'pictures': list(map(lambda x: (x.id, x.name), self.pictures)),
}
return ret

Expand Down
17 changes: 17 additions & 0 deletions api/tests/scripts/upload_test_hike.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ def _ts_w_tz(date_time: str, timezone: str) -> str:
'zone': 'America/New_York',
'title': 'My Test Hike',
'brief': '3-day Hike Along North Chick Creek (Cumberland Trail)',
'description': '''\
This hike was **awesome**!!!
### Day 1
We started our hike on the trail after checking in with some rangers who were doing their rounds and
we topped off our bottles with filtered water from the creek.
### Day 2
We considered continuing on the trail, but ended up coming to the conclusion that we wanted to make
day 2 to be a _chill_ day.
### Day 3
We made our way back to the car and encountered many ticks along the way...
'''
}

TRACKS = list(Path(HERE, 'hike_data').glob('*.gpx'))
Expand Down
Loading

0 comments on commit cd742b2

Please sign in to comment.