From 5bc9e25c7a19e14ca848d242c3a6f4f5c4883dcc Mon Sep 17 00:00:00 2001 From: BryantHe Date: Wed, 20 Sep 2023 11:59:51 +0800 Subject: [PATCH] feat: add api of get_interaction_list --- app/api/v1/interaction.py | 24 +++++++++++++++++++----- app/api/v1/schema/interaction.py | 22 +++++++++++++++++++--- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/app/api/v1/interaction.py b/app/api/v1/interaction.py index ec8fa0f..d6d720a 100644 --- a/app/api/v1/interaction.py +++ b/app/api/v1/interaction.py @@ -3,7 +3,8 @@ from flask import session from app import rpc from app.api.v1.exception.interaction import AddInteractionError -from app.api.v1.schema.interaction import InteractionIn, InteractionTodayIn, InteractionTodayOut +from app.api.v1.schema.interaction import (InteractionIn, InteractionBriefIn, InteractionListIn, + InteractionBriefOut, InteractionListOut) from app.util.auth import login_required @@ -29,12 +30,25 @@ def add_interaction(json_data): @interaction.get('/brief') -@interaction.doc(summary='查询食物记录列表', description='查询食物记录列表') -@interaction.input(InteractionTodayIn, location='query') -@interaction.output(InteractionTodayOut) +@interaction.doc(summary='查询互动简要数据', description='查询互动简要数据') +@interaction.input(InteractionBriefIn, location='query') +@interaction.output(InteractionBriefOut) @login_required -def get_interaction_today_brief(query_data): +def get_interaction_brief(query_data): current_date = query_data.get('current_date', None) results = rpc.interaction.get_interaction_brief(session['user_id'], current_date=current_date) return results + + +@interaction.get('/list') +@interaction.doc(summary='查询互动列表数据', description='查询互动列表数据') +@interaction.input(InteractionListIn, location='query') +@interaction.output(InteractionListOut) +@login_required +def get_interaction_list(query_data): + current_date = query_data.get('current_date', None) + results = rpc.interaction.get_interaction_list(session['user_id'], + category=query_data['category'], + current_date=current_date) + return results diff --git a/app/api/v1/schema/interaction.py b/app/api/v1/schema/interaction.py index a926cd8..a6a3667 100644 --- a/app/api/v1/schema/interaction.py +++ b/app/api/v1/schema/interaction.py @@ -9,11 +9,27 @@ class InteractionIn(Schema): comment = fields.String(allow_none=True) -class InteractionTodayIn(Schema): +class InteractionBriefIn(Schema): current_date = fields.String() -class InteractionTodayOut(Schema): +class InteractionListIn(Schema): + current_date = fields.String() + category = fields.Integer(required=True) + + +class InteractionBriefOut(Schema): fire_count = fields.Integer() heart_count = fields.Integer() - comment_count = fields.Integer() \ No newline at end of file + comment_count = fields.Integer() + + +class InteractionOut(Schema): + nickname = fields.String() + avatar_url = fields.String() + comment = fields.String() + create_time = fields.String() + + +class InteractionListOut(Schema): + interactions = fields.List(fields.Nested(InteractionOut)) \ No newline at end of file