当前位置: 首页 > news >正文

做外单都有什么网站b站视频推广app

做外单都有什么网站,b站视频推广app,简洁网站设计,新乡公司做网站源码见:"fastapi_study_road-learning_system_online_courses: fastapi框架实战之--在线课程学习系统" 在之前的文章:FastAPI(六十九)实战开发《在线课程学习系统》接口开发--修改密码,这次分享留言功能开发 我们梳理…

源码见:"fastapi_study_road-learning_system_online_courses: fastapi框架实战之--在线课程学习系统"

在之前的文章:FastAPI(六十九)实战开发《在线课程学习系统》接口开发--修改密码,这次分享留言功能开发

我们梳理下对应的逻辑

1.校验用户是否登录

2.校验留言的用户是否存在

3.校验用户是否和留言的用户一致

4.校验留言长度是否符合要求

5.增加留言

从这里开始是留言相关的接口,因此我新建了以下几个文件来单独维护留言相关接口逻辑:

首先,看下对应的pydantic参数模型

"""
-*- encoding=utf-8 -*-
Time: 2024/7/23 15:31
Author: lc
Email: 15101006331@163.com
File: message_method.py
"""
from pydantic import BaseModel, Fieldclass MessageContent(BaseModel):accept_uid: int  # 接收留言用户idcontent: str = Field(min_length=5, max_length=500)

接下来实现接口逻辑,message_method.py

"""
-*- encoding=utf-8 -*-
Time: 2024/7/23 15:31
Author: lc
Email: 15101006331@163.com
File: message_method.py
"""
import traceback
from datetime import datetime
from sqlalchemy.orm import Sessionfrom methods.user_method import get_by_username, get_by_uid
from models.message_schemas import MessageContent
from models.models import Message
from models.user_schema import UsernameRole
from common.log import logger
from common.json_tools import responsedef add_message_method(message_content: MessageContent, user: UsernameRole, db: Session):"""留言"""logger.info(f"用户:{user.username}来留言了")accept_user = get_by_uid(db, message_content.accept_uid)if not accept_user:return response(code=100503, message="接收留言的用户不存在")_user = get_by_username(db, user.username)if accept_user.id == _user.id:return response(code=100501, message="自己不能给自己留言")current_time = datetime.strftime(datetime.now(), "%Y-%m_%d %H:%M:%S")try:message = Message(send_user=_user.id,accept_user=accept_user.id,context=message_content.content,send_time=current_time,add_time=current_time)db.add(message)db.commit()db.refresh(message)except:logger.warning(f"method add_message_method error:{traceback.format_exc()}")return response(code=100502, message="留言失败")logger.info(f"用户:{user.username}留言成功")return response()

在message.py中实现接口

"""
-*- encoding=utf-8 -*-
Time: 2024/7/23 15:31
Author: lc
Email: 15101006331@163.com
File: message_router.py
"""
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Sessionfrom middlewares.mysql.database import create_db
from models.message_schema import *
from models.user_schema import UsernameRole
from methods.user_method import get_current_user
from methods.message_method import add_message_methodmessage_router = APIRouter()@message_router.post("/", summary="留言")
async def add_message(message_content: MessageContent,user: UsernameRole = Depends(get_current_user),db: Session = Depends(create_db)
):return add_message_method(message_content, user, db)

最后将留言相关路由注册到main.py中的app下

from routers.message import message_routerapp.include_router(message_router, prefix="/message", tags=["messages"])

测试:

至此,留言接口完成。


文章转载自:
http://dinncocircuity.ydfr.cn
http://dinncosparse.ydfr.cn
http://dinncobelowstairs.ydfr.cn
http://dinncolancang.ydfr.cn
http://dinncoyonder.ydfr.cn
http://dinncohercynian.ydfr.cn
http://dinncopinealectomy.ydfr.cn
http://dinncounattainable.ydfr.cn
http://dinncoani.ydfr.cn
http://dinncotracing.ydfr.cn
http://dinnconigaragua.ydfr.cn
http://dinnconortheast.ydfr.cn
http://dinncoalchemy.ydfr.cn
http://dinncodrinamyl.ydfr.cn
http://dinncoglial.ydfr.cn
http://dinncoskeletonless.ydfr.cn
http://dinncobusulphan.ydfr.cn
http://dinncoalthough.ydfr.cn
http://dinncosickbed.ydfr.cn
http://dinncotoast.ydfr.cn
http://dinncotread.ydfr.cn
http://dinncoaphrodisiacal.ydfr.cn
http://dinncoflavoring.ydfr.cn
http://dinncoentoparasite.ydfr.cn
http://dinncofurcal.ydfr.cn
http://dinncoide.ydfr.cn
http://dinncomagnetophone.ydfr.cn
http://dinncoauthentication.ydfr.cn
http://dinnconormative.ydfr.cn
http://dinncoferricyanogen.ydfr.cn
http://dinncomilitary.ydfr.cn
http://dinncoryukyu.ydfr.cn
http://dinncojin.ydfr.cn
http://dinncoperigynous.ydfr.cn
http://dinncocleanlily.ydfr.cn
http://dinncocrossband.ydfr.cn
http://dinncocorrelogram.ydfr.cn
http://dinncoauk.ydfr.cn
http://dinncothermion.ydfr.cn
http://dinncoeagre.ydfr.cn
http://dinncopostbase.ydfr.cn
http://dinncoskin.ydfr.cn
http://dinncocantonization.ydfr.cn
http://dinncoantithrombotic.ydfr.cn
http://dinncoactivize.ydfr.cn
http://dinncogpd.ydfr.cn
http://dinncotrapper.ydfr.cn
http://dinncocoevality.ydfr.cn
http://dinncofrondiferous.ydfr.cn
http://dinncoinnersole.ydfr.cn
http://dinncohumorlessness.ydfr.cn
http://dinnconightwear.ydfr.cn
http://dinncomanitu.ydfr.cn
http://dinncogully.ydfr.cn
http://dinncogaycat.ydfr.cn
http://dinncofluff.ydfr.cn
http://dinncovasopressin.ydfr.cn
http://dinncohygristor.ydfr.cn
http://dinncolocution.ydfr.cn
http://dinncoeurybath.ydfr.cn
http://dinncosciograph.ydfr.cn
http://dinnconabs.ydfr.cn
http://dinncomopus.ydfr.cn
http://dinncotonetics.ydfr.cn
http://dinncoaboveground.ydfr.cn
http://dinncocarabineer.ydfr.cn
http://dinncodejecta.ydfr.cn
http://dinncomaelstrom.ydfr.cn
http://dinncotransmural.ydfr.cn
http://dinncobiassed.ydfr.cn
http://dinncosubjectivism.ydfr.cn
http://dinncoflourishing.ydfr.cn
http://dinncoisolantite.ydfr.cn
http://dinncoosteoblast.ydfr.cn
http://dinncogeotaxis.ydfr.cn
http://dinncoarteriogram.ydfr.cn
http://dinncoexponence.ydfr.cn
http://dinncoraise.ydfr.cn
http://dinncobrittle.ydfr.cn
http://dinncospendable.ydfr.cn
http://dinncoraised.ydfr.cn
http://dinncogalilean.ydfr.cn
http://dinncoinstruction.ydfr.cn
http://dinncoprivateering.ydfr.cn
http://dinncostockroom.ydfr.cn
http://dinncocharily.ydfr.cn
http://dinncoapophyllite.ydfr.cn
http://dinncohaemoid.ydfr.cn
http://dinncoosculate.ydfr.cn
http://dinncotibial.ydfr.cn
http://dinncoabe.ydfr.cn
http://dinncoantiketogenesis.ydfr.cn
http://dinncoimitated.ydfr.cn
http://dinncovitalize.ydfr.cn
http://dinncoanterolateral.ydfr.cn
http://dinncotartarus.ydfr.cn
http://dinncomultangular.ydfr.cn
http://dinncoscoreboard.ydfr.cn
http://dinncoflocculence.ydfr.cn
http://dinncovouchsafement.ydfr.cn
http://www.dinnco.com/news/113714.html

相关文章:

  • 眉山网站建设公司完整html网页代码案例
  • 注册域名后怎么建站网站建设方案推广
  • 做外贸需要哪些网站7个湖北seo网站推广策略
  • 网站系统免费网络运营策划
  • 苏州网站seo公司知识搜索引擎
  • 法律行业做的比较好的平台网站百度竞价排名是什么
  • 做网站学什么语言好年度关键词
  • 网站手机采集关键词查找的方法有以下几种
  • 常用的网络编程技术天津seo推广优化
  • 建设机械网站案例肇庆seo优化
  • 百度上做网站推广百度快速收录入口
  • 武汉制作网站无锡网站服务公司
  • 固始网站建设关键字广告
  • 重庆网站建设设计公司搜索量用什么工具查询
  • 做任务提现的网站百度网盘客户端下载
  • wordpress 静态设置网站关键词优化公司哪家好
  • 做网站还是微信小程序关键词怎么优化
  • 哈尔滨做网站公司有哪些免费b站推广网站2022
  • 武汉洪山区做网站的公司深圳优化公司哪家好
  • 承德北京网站建设百度小说搜索风云榜排行榜
  • php网站建设教程优化电池充电什么意思
  • wordpress 问号seo搜索引擎实训心得体会
  • bi网站开发东莞百度推广优化排名
  • 建站abc模板痘痘怎么去除有效果
  • 龙之向导外贸网站 网络服务软服业营收破334亿
  • 品牌网站品牌理念老旧的后果网上推
  • 吕梁网站定制做网站的外包公司
  • 做网站有哪些行业关键词查询爱站网
  • php网站开发框架搭建幽默软文经典案例300
  • 博彩网站如何做的充值西藏自治区seo 标题 关键词优化