Skip to content

Instantly share code, notes, and snippets.

@gabbyprecious
Last active May 26, 2020 21:06
Show Gist options
  • Save gabbyprecious/05da2ef3088a9f86267957909a61ca33 to your computer and use it in GitHub Desktop.
Save gabbyprecious/05da2ef3088a9f86267957909a61ca33 to your computer and use it in GitHub Desktop.
from fastapi import APIRouter
from fastapi_sqlalchemy import db
from model import Follower as ModelFollower
from schema import FollowerCreate as SchemaFollower #Used to create validate Following and send to the model
from schema import Follower as Followers #Used to return Following
router = APIRouter()
@router.post("/follow", response_model=Followers)
async def follow(following: SchemaFollower):
Follower = ModelFollower(userId=following.userId, FollowerId=following.FollowerId)
db.session.add(Follower)
db.session.commit()
db.session.refresh(Follower)
return Follower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment