update docs and api endpoints

This commit is contained in:
Sam 2019-07-19 12:02:49 +02:00
parent 1247e2253a
commit 715da8fc64
21 changed files with 148 additions and 3 deletions

View File

@ -1,6 +1,8 @@
Authentication
##############
work in progress
.. autoflask:: fittrackee_api:create_app()
:endpoints:
auth.register_user,

View File

@ -1,6 +1,8 @@
Records
#######
work in progress
.. autoflask:: fittrackee_api:create_app()
:endpoints:
records.get_records

View File

@ -1,6 +1,8 @@
Sports
######
work in progress
.. autoflask:: fittrackee_api:create_app()
:endpoints:
sports.get_sports,

View File

@ -1,6 +1,8 @@
Statistics
##########
work in progress
.. autoflask:: fittrackee_api:create_app()
:endpoints:
stats.get_activities_by_sport,

View File

@ -1,6 +1,8 @@
Users
#####
work in progress
.. autoflask:: fittrackee_api:create_app()
:endpoints:
users.get_users,

View File

@ -121,6 +121,49 @@
<div class="section" id="authentication">
<h1>Authentication<a class="headerlink" href="#authentication" title="Permalink to this headline"></a></h1>
<p>work in progress</p>
<dl class="post">
<dt id="post--api-auth-register">
<code class="sig-name descname">POST </code><code class="sig-name descname">/api/auth/register</code><a class="headerlink" href="#post--api-auth-register" title="Permalink to this definition"></a></dt>
<dd><p>register a user</p>
</dd></dl>
<dl class="post">
<dt id="post--api-auth-login">
<code class="sig-name descname">POST </code><code class="sig-name descname">/api/auth/login</code><a class="headerlink" href="#post--api-auth-login" title="Permalink to this definition"></a></dt>
<dd><p>user login</p>
</dd></dl>
<dl class="get">
<dt id="get--api-auth-logout">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/auth/logout</code><a class="headerlink" href="#get--api-auth-logout" title="Permalink to this definition"></a></dt>
<dd><p>user logout</p>
</dd></dl>
<dl class="get">
<dt id="get--api-auth-profile">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/auth/profile</code><a class="headerlink" href="#get--api-auth-profile" title="Permalink to this definition"></a></dt>
<dd><p>get authenticated user info</p>
</dd></dl>
<dl class="post">
<dt id="post--api-auth-profile-edit">
<code class="sig-name descname">POST </code><code class="sig-name descname">/api/auth/profile/edit</code><a class="headerlink" href="#post--api-auth-profile-edit" title="Permalink to this definition"></a></dt>
<dd><p>edit authenticated user</p>
</dd></dl>
<dl class="post">
<dt id="post--api-auth-picture">
<code class="sig-name descname">POST </code><code class="sig-name descname">/api/auth/picture</code><a class="headerlink" href="#post--api-auth-picture" title="Permalink to this definition"></a></dt>
<dd><p>update authenticated user picture</p>
</dd></dl>
<dl class="delete">
<dt id="delete--api-auth-picture">
<code class="sig-name descname">DELETE </code><code class="sig-name descname">/api/auth/picture</code><a class="headerlink" href="#delete--api-auth-picture" title="Permalink to this definition"></a></dt>
<dd><p>delete authenticated user picture</p>
</dd></dl>
</div>

View File

@ -121,6 +121,7 @@
<div class="section" id="records">
<h1>Records<a class="headerlink" href="#records" title="Permalink to this headline"></a></h1>
<p>work in progress</p>
<dl class="get">
<dt id="get--api-records">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/records</code><a class="headerlink" href="#get--api-records" title="Permalink to this definition"></a></dt>

View File

@ -121,6 +121,7 @@
<div class="section" id="sports">
<h1>Sports<a class="headerlink" href="#sports" title="Permalink to this headline"></a></h1>
<p>work in progress</p>
<dl class="get">
<dt id="get--api-sports">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/sports</code><a class="headerlink" href="#get--api-sports" title="Permalink to this definition"></a></dt>

View File

@ -121,10 +121,17 @@
<div class="section" id="statistics">
<h1>Statistics<a class="headerlink" href="#statistics" title="Permalink to this headline"></a></h1>
<p>work in progress</p>
<dl class="get">
<dt id="get--api-stats-(int-user_id)-by_sport">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/stats/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">user_id</em><span class="sig-paren">)</span><code class="sig-name descname">/by_sport</code><a class="headerlink" href="#get--api-stats-(int-user_id)-by_sport" title="Permalink to this definition"></a></dt>
<dd><p>Get activities statistics for a user by sport</p>
</dd></dl>
<dl class="get">
<dt id="get--api-stats-(int-user_id)-by_time">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/stats/</code><span class="sig-paren">(</span><em class="property">int: </em><em class="sig-param">user_id</em><span class="sig-paren">)</span><code class="sig-name descname">/by_time</code><a class="headerlink" href="#get--api-stats-(int-user_id)-by_time" title="Permalink to this definition"></a></dt>
<dd><p>Get activities statistics for a user</p>
<dd><p>Get activities statistics for a user by time</p>
</dd></dl>
</div>

View File

@ -121,6 +121,7 @@
<div class="section" id="users">
<h1>Users<a class="headerlink" href="#users" title="Permalink to this headline"></a></h1>
<p>work in progress</p>
<dl class="get">
<dt id="get--api-users">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/users</code><a class="headerlink" href="#get--api-users" title="Permalink to this definition"></a></dt>
@ -133,6 +134,18 @@
<dd><p>Get single user details</p>
</dd></dl>
<dl class="get">
<dt id="get--api-users-(user_id)-picture">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/users/</code><span class="sig-paren">(</span><em class="sig-param">user_id</em><span class="sig-paren">)</span><code class="sig-name descname">/picture</code><a class="headerlink" href="#get--api-users-(user_id)-picture" title="Permalink to this definition"></a></dt>
<dd><p>get user picture</p>
</dd></dl>
<dl class="get">
<dt id="get--api-ping">
<code class="sig-name descname">GET </code><code class="sig-name descname">/api/ping</code><a class="headerlink" href="#get--api-ping" title="Permalink to this definition"></a></dt>
<dd><p>health check endpoint</p>
</dd></dl>
</div>

View File

@ -145,6 +145,21 @@
<td>
<a href="api/activities.html#get--api-activities-map-(map_id)"><code class="xref">GET /api/activities/map/(map_id)</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
<a href="api/auth.html#get--api-auth-logout"><code class="xref">GET /api/auth/logout</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
<a href="api/auth.html#get--api-auth-profile"><code class="xref">GET /api/auth/profile</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
<a href="api/users.html#get--api-ping"><code class="xref">GET /api/ping</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
@ -160,6 +175,11 @@
<td>
<a href="api/sports.html#get--api-sports-(int-sport_id)"><code class="xref">GET /api/sports/(int:sport_id)</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
<a href="api/stats.html#get--api-stats-(int-user_id)-by_sport"><code class="xref">GET /api/stats/(int:user_id)/by_sport</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
@ -175,6 +195,11 @@
<td>
<a href="api/users.html#get--api-users-(user_id)"><code class="xref">GET /api/users/(user_id)</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
<a href="api/users.html#get--api-users-(user_id)-picture"><code class="xref">GET /api/users/(user_id)/picture</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
@ -185,6 +210,26 @@
<td>
<a href="api/activities.html#post--api-activities-no_gpx"><code class="xref">POST /api/activities/no_gpx</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
<a href="api/auth.html#post--api-auth-login"><code class="xref">POST /api/auth/login</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
<a href="api/auth.html#post--api-auth-picture"><code class="xref">POST /api/auth/picture</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
<a href="api/auth.html#post--api-auth-profile-edit"><code class="xref">POST /api/auth/profile/edit</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
<a href="api/auth.html#post--api-auth-register"><code class="xref">POST /api/auth/register</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
@ -195,6 +240,11 @@
<td>
<a href="api/activities.html#delete--api-activities-(int-activity_id)"><code class="xref">DELETE /api/activities/(int:activity_id)</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>
<a href="api/auth.html#delete--api-auth-picture"><code class="xref">DELETE /api/auth/picture</code></a></td><td>
<em></em></td></tr>
<tr>
<td></td>
<td>

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,8 @@
Authentication
##############
work in progress
.. autoflask:: fittrackee_api:create_app()
:endpoints:
auth.register_user,

View File

@ -1,6 +1,8 @@
Records
#######
work in progress
.. autoflask:: fittrackee_api:create_app()
:endpoints:
records.get_records

View File

@ -1,6 +1,8 @@
Sports
######
work in progress
.. autoflask:: fittrackee_api:create_app()
:endpoints:
sports.get_sports,

View File

@ -1,6 +1,8 @@
Statistics
##########
work in progress
.. autoflask:: fittrackee_api:create_app()
:endpoints:
stats.get_activities_by_sport,

View File

@ -1,6 +1,8 @@
Users
#####
work in progress
.. autoflask:: fittrackee_api:create_app()
:endpoints:
users.get_users,

View File

@ -130,11 +130,12 @@ def get_activities(user_id, filter_type):
@stats_blueprint.route('/stats/<int:user_id>/by_time', methods=['GET'])
@authenticate
def get_activities_by_time(auth_user_id, user_id):
"""Get activities statistics for a user"""
"""Get activities statistics for a user by time"""
return get_activities(user_id, 'by_time')
@stats_blueprint.route('/stats/<int:user_id>/by_sport', methods=['GET'])
@authenticate
def get_activities_by_sport(auth_user_id, user_id):
"""Get activities statistics for a user by sport"""
return get_activities(user_id, 'by_sport')

View File

@ -15,6 +15,7 @@ auth_blueprint = Blueprint('auth', __name__)
@auth_blueprint.route('/auth/register', methods=['POST'])
def register_user():
""" register a user """
# get post data
post_data = request.get_json()
if not post_data or post_data.get('username') is None \
@ -91,6 +92,7 @@ def register_user():
@auth_blueprint.route('/auth/login', methods=['POST'])
def login_user():
""" user login """
# get post data
post_data = request.get_json()
if not post_data:
@ -133,6 +135,7 @@ def login_user():
@auth_blueprint.route('/auth/logout', methods=['GET'])
@authenticate
def logout_user(user_id):
""" user logout """
# get auth token
auth_header = request.headers.get('Authorization')
if auth_header:
@ -161,6 +164,7 @@ def logout_user(user_id):
@auth_blueprint.route('/auth/profile', methods=['GET'])
@authenticate
def get_user_status(user_id):
""" get authenticated user info """
user = User.query.filter_by(id=user_id).first()
response_object = {
'status': 'success',
@ -172,6 +176,7 @@ def get_user_status(user_id):
@auth_blueprint.route('/auth/profile/edit', methods=['POST'])
@authenticate
def edit_user(user_id):
""" edit authenticated user """
# get post data
post_data = request.get_json()
if not post_data:
@ -237,6 +242,7 @@ def edit_user(user_id):
@auth_blueprint.route('/auth/picture', methods=['POST'])
@authenticate
def edit_picture(user_id):
""" update authenticated user picture """
code = 400
response_object = verify_extension('picture', request)
if response_object['status'] != 'success':
@ -287,6 +293,7 @@ def edit_picture(user_id):
@auth_blueprint.route('/auth/picture', methods=['DELETE'])
@authenticate
def del_picture(user_id):
""" delete authenticated user picture """
try:
user = User.query.filter_by(id=user_id).first()
picture_path = get_absolute_file_path(user.picture)

View File

@ -42,6 +42,7 @@ def get_single_user(user_id):
@users_blueprint.route('/users/<user_id>/picture', methods=['GET'])
def get_picture(user_id):
""" get user picture """
response_object = {
'status': 'fail',
'message': 'User does not exist'
@ -59,6 +60,7 @@ def get_picture(user_id):
@users_blueprint.route('/ping', methods=['GET'])
def ping_pong():
""" health check endpoint """
return jsonify({
'status': 'success',
'message': 'pong!'