From b86ef1376e9f7a427ae862c59c70342ddfd93609 Mon Sep 17 00:00:00 2001 From: BryantHe Date: Sat, 26 Aug 2023 11:05:45 +0800 Subject: [PATCH] feat: add api of delete one --- app/api/v1/record.py | 14 +++++++++++++- app/api/v1/schema/record.py | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/api/v1/record.py b/app/api/v1/record.py index 3f34b6e..c902c68 100644 --- a/app/api/v1/record.py +++ b/app/api/v1/record.py @@ -4,7 +4,7 @@ from flask import session from app import rpc from app.api.v1.exception.record import AddBodyRecordError, BodyRecordNotFound, BodyRecordChartError from app.api.v1.schema.record import BodyRecordIn, BodyRecordOut, BodyRecordsOut, BodyRecordsIn, BodyRecordChartIn, \ - BodyRecordChartOut + BodyRecordChartOut, BodyRecordIdIn from app.util.auth import login_required record = APIBlueprint('record', __name__) @@ -39,6 +39,18 @@ def get_record(record_id): return result +@record.delete('/') +@record.doc(summary='删除单条身体记录', description='删除单条身体记录') +@record.input(BodyRecordIdIn, location='json') +@login_required +def delete_record(json_data): + try: + rpc.body_record.delete_one(json_data['record_id']) + except Exception as e: + raise BodyRecordNotFound(extra_data={'error_docs': str(e)}) + return {'msg': ' delete body record success'} + + @record.get('/list') @record.doc(summary='查询身体记录列表', description='查询身体记录列表') @record.input(BodyRecordsIn, location='query') diff --git a/app/api/v1/schema/record.py b/app/api/v1/schema/record.py index e021ba5..e4545bc 100644 --- a/app/api/v1/schema/record.py +++ b/app/api/v1/schema/record.py @@ -8,6 +8,10 @@ class BodyRecordIn(Schema): bmi = fields.Float() +class BodyRecordIdIn(Schema): + record_id = fields.String(required=True) + + class BodyRecordOut(Schema): record_id = fields.String(attribute='_id') height = fields.Float()