Commit 12405512 authored by 杨明橙's avatar 杨明橙

修改swagger

parent 5e4af2f5
......@@ -3,7 +3,7 @@ from api import bill, nav, fund, group, node, scheduler, price
api_router = APIRouter()
api_router.include_router(bill.router, prefix="/bill", tags=["账单"])
api_router.include_router(bill.router, prefix="/bill")
api_router.include_router(nav.router, prefix="/nav", tags=["净值"])
api_router.include_router(fund.router, prefix="/fund", tags=["基金"])
api_router.include_router(node.router, prefix="/node", tags=["节点"])
......
from typing import Union, List, Any
from loguru import logger
from fastapi import APIRouter, Depends, Query
from motor.core import AgnosticCollection
from pymongo.operations import UpdateOne
from dependencies import get_current_user, get_fund_collect, get_bill_collect
from exception.api import APIError
from exception.db import NotFundError
from model import Response, Page, PageResponse, SortParams, FilterTime
from model.bill import PCFBill, ExchangeBill, AdjustBill, StakingBill
from schema.bill import CreatePCFBill, PCFBillType, CreateExchangeBill, CreateAdjustBill, CreateStakingBill, \
UpdatePCFBill, UpdateExchangeBill, UpdateStakingBill, UpdateAdjustBill, AllBillType
from schema.fund import FundStatus
from service.bill import update_bill, create_staking
from service.bill import update_bill
from service.fund import query_fund_assets, update_assets
from tools.jwt_tools import User
......@@ -21,23 +17,23 @@ router = APIRouter()
@router.post('/pcf/',
response_model=Response[PCFBill],
tags=['新增'],
summary='添加[申购/赎回]账目',
description='添加申购赎回账目')
tags=['[申购/赎回]'],
summary='[添加]',
description='[添加]申购赎回账目')
async def create_pcf(
item: CreatePCFBill,
create_pcf_bill: CreatePCFBill,
user: User = Depends(get_current_user),
fund_collect: AgnosticCollection = Depends(get_fund_collect),
bill_collect: AgnosticCollection = Depends(get_bill_collect),
):
inc = item.volume if item.bill_type == PCFBillType.sub else -item.volume
inc = create_pcf_bill.volume if create_pcf_bill.bill_type == PCFBillType.sub else -create_pcf_bill.volume
assets, adjust_assets, pending_assets, staking_assets = await query_fund_assets(fund_collect, item.fund_id, user.id,
assets, adjust_assets, pending_assets, staking_assets = await query_fund_assets(fund_collect, create_pcf_bill.fund_id, user.id,
FundStatus.active)
assets.setdefault(item.currency, 0)
assets.setdefault(create_pcf_bill.currency, 0)
# 如果是赎回 判断余额是否够
assert assets[item.currency] + inc >= 0, "余额不足"
assets[item.currency] += inc
assert assets[create_pcf_bill.currency] + inc >= 0, "余额不足"
assets[create_pcf_bill.currency] += inc
# if item.currency in assets:
# inc = item.volume if item.bill_type == PCFBillType.sub else -item.volume
......@@ -46,17 +42,17 @@ async def create_pcf(
# else:
# assert item.bill_type == PCFBillType.sub, "余额不足"
# assets.update({item.currency: item.volume})
await update_assets(fund_collect, item.fund_id, assets=assets)
pcf = PCFBill(user_id=user.id, **item.dict())
await update_assets(fund_collect, create_pcf_bill.fund_id, assets=assets)
pcf = PCFBill(user_id=user.id, **create_pcf_bill.dict())
await bill_collect.insert_one(pcf.dict())
return Response[PCFBill](data=pcf.dict())
@router.post('/exchange/',
response_model=Response[ExchangeBill],
tags=['新增'],
summary='添加置换币账目',
description='添加置换币账目')
tags=['置换币种'],
summary='[添加]',
description='[添加]置换币账目')
async def create_exchange(
create_exchange_bill: CreateExchangeBill,
user: User = Depends(get_current_user),
......@@ -107,9 +103,9 @@ async def create_exchange(
@router.post('/adjust/',
response_model=Response[AdjustBill],
tags=['新增'],
summary='添加调整账目',
description='添加调整账目')
tags=['调整'],
summary='[添加]',
description='[添加]调整账目')
async def create_adjust(
create_adjust_bill: CreateAdjustBill,
user: User = Depends(get_current_user),
......@@ -144,9 +140,9 @@ async def create_adjust(
@router.post('/staking/',
response_model=Response[StakingBill],
tags=['新增'],
summary='添加质押账目',
description='添加质押账目')
tags=['质押'],
summary='[添加]',
description='[添加]质押账目')
async def create_staking_api(
create_staking_bill: CreateStakingBill,
user: User = Depends(get_current_user),
......@@ -173,10 +169,10 @@ async def create_staking_api(
@router.put('/pcf/{fund_id}/',
tags=['更新'],
tags=['[申购/赎回]'],
response_model=Response[PCFBill],
summary='更新申购赎回记录',
description='')
summary='[更新]',
description='[更新]申购赎回记录')
async def update_pcf_bill(
bill_id: str,
fund_id: str,
......@@ -198,10 +194,10 @@ async def update_pcf_bill(
@router.put('/exchange/{fund_id}/',
tags=['更新'],
tags=['置换币种'],
response_model=Response[ExchangeBill],
summary='更新置换记录',
description='')
summary='[更新]',
description='[更新]置换币种记录')
async def update_exchange_bill(
bill_id: str,
fund_id: str,
......@@ -222,15 +218,15 @@ async def update_exchange_bill(
return response
@router.put('/staking/{fund_id}/',
tags=['更新'],
response_model=Response[StakingBill],
summary='更新质押记录',
description='')
async def update_staking_bill(
@router.put('/adjust/{fund_id}/',
tags=['调整'],
response_model=Response[AdjustBill],
summary='[更新]',
description='[更新]调整记录')
async def update_adjust_bill(
bill_id: str,
fund_id: str,
update_item: UpdateStakingBill,
update_item: UpdateAdjustBill,
user: User = Depends(get_current_user),
fund_collect: AgnosticCollection = Depends(get_fund_collect),
bill_collect: AgnosticCollection = Depends(get_bill_collect),
......@@ -242,20 +238,20 @@ async def update_staking_bill(
update_data=update_item,
fund_collect=fund_collect,
bill_collect=bill_collect,
res_model=StakingBill
res_model=AdjustBill
)
return response
@router.put('/adjust/{fund_id}/',
tags=['更新'],
response_model=Response[AdjustBill],
summary='更新调整记录',
description='')
async def update_adjust_bill(
@router.put('/staking/{fund_id}/',
tags=['质押'],
response_model=Response[StakingBill],
summary='[更新]',
description='[更新]质押记录')
async def update_staking_bill(
bill_id: str,
fund_id: str,
update_item: UpdateAdjustBill,
update_item: UpdateStakingBill,
user: User = Depends(get_current_user),
fund_collect: AgnosticCollection = Depends(get_fund_collect),
bill_collect: AgnosticCollection = Depends(get_bill_collect),
......@@ -267,13 +263,13 @@ async def update_adjust_bill(
update_data=update_item,
fund_collect=fund_collect,
bill_collect=bill_collect,
res_model=AdjustBill
res_model=StakingBill
)
return response
@router.get('/{fund_id}/',
tags=["查询"],
tags=["查询账目"],
response_model=PageResponse[Union[PCFBill, ExchangeBill, StakingBill, AdjustBill]],
summary='查询账单记录',
description='查询账单记录')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment