From 4214e7b79787e36dbad84e799b0383f87af25959 Mon Sep 17 00:00:00 2001 From: BryantHe Date: Tue, 19 Sep 2023 17:15:07 +0800 Subject: [PATCH] feat: add api of today brief --- app/api/v1/exception/interaction.py | 7 ++++++- app/api/v1/interaction.py | 16 ++++++++++++++-- app/api/v1/schema/interaction.py | 12 +++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/api/v1/exception/interaction.py b/app/api/v1/exception/interaction.py index 27458e2..2c7d8bd 100644 --- a/app/api/v1/exception/interaction.py +++ b/app/api/v1/exception/interaction.py @@ -3,4 +3,9 @@ from apiflask import HTTPError class AddInteractionError(HTTPError): status_code = 500 - message = 'add interaction failed.' \ No newline at end of file + message = 'add interaction failed.' + + +class InteractionTodayBriefNotFound(HTTPError): + status_code = 404 + message = '找不到用户对应的食物记录' \ No newline at end of file diff --git a/app/api/v1/interaction.py b/app/api/v1/interaction.py index 04e60ba..f52e1f0 100644 --- a/app/api/v1/interaction.py +++ b/app/api/v1/interaction.py @@ -3,7 +3,7 @@ from flask import session from app import rpc from app.api.v1.exception.interaction import AddInteractionError -from app.api.v1.schema.interaction import InteractionIn +from app.api.v1.schema.interaction import InteractionIn, InteractionTodayIn, InteractionTodayOut from app.util.auth import login_required @@ -25,4 +25,16 @@ def add_interaction(json_data): }) except Exception as e: raise AddInteractionError(extra_data={'error_docs': str(e)}) - return {'msg': 'add interaction successfully'} \ No newline at end of file + return {'msg': 'add interaction successfully'} + + +@interaction.get('/today/brief') +@interaction.doc(summary='查询食物记录列表', description='查询食物记录列表') +@interaction.input(InteractionTodayIn, location='query') +@interaction.output(InteractionTodayOut) +@login_required +def get_interaction_today_brief(query_data): + current_date = query_data.get('current_date', None) + results = rpc.interaction.get_today_brief(session['user_id'], + current_date=current_date) + return results \ No newline at end of file diff --git a/app/api/v1/schema/interaction.py b/app/api/v1/schema/interaction.py index 6974a77..a926cd8 100644 --- a/app/api/v1/schema/interaction.py +++ b/app/api/v1/schema/interaction.py @@ -6,4 +6,14 @@ class InteractionIn(Schema): category = fields.Integer() receiver_id = fields.String() related_party_id = fields.String(allow_none=True) - comment = fields.String(allow_none=True) \ No newline at end of file + comment = fields.String(allow_none=True) + + +class InteractionTodayIn(Schema): + current_date = fields.String() + + +class InteractionTodayOut(Schema): + fire_count = fields.Integer() + heart_count = fields.Integer() + comment_count = fields.Integer() \ No newline at end of file