Python Rest API user registration bassed on FastAPI framework

I’m wrote an API for dating service. This is part related to user authentification, authorization, login and etc.
FastAPI, in turn, is based on starlette web server.
You may wonder what is fastapi.Depends... -It’s interanly calling a passed function when endpoint is requested to satisfy shes dependencies. I’m don’t know what is a problem to satisfy a dependencies manually, but just using it.

Here is my code, please give me any feedback.

imports ...


app = fastapi.FastAPI(title='api', description='A very verbose API.', version='0.1')

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="login", auto_error=False)  # Add GUI from to login

fastapi_http_errors = {

    'no_token_401': fastapi.HTTPException(
        status_code=fastapi.status.HTTP_401_UNAUTHORIZED,
        detail="Invalid token",
        headers={"WWW-Authenticate": "Bearer"}),

    'wrong_token_403': fastapi.HTTPException(
        status_code=fastapi.status.HTTP_403_FORBIDDEN,
        detail="Wrong email or password",  # TODO wrong token ?
        headers={"WWW-Authenticate": "Bearer"}, ),

    'not_found_404': fastapi.HTTPException(
        status_code=fastapi.status.HTTP_404_NOT_FOUND,
        detail="Interest not found"),

    'email_already_exists_409': fastapi.HTTPException(
        status_code=fastapi.status.HTTP_409_CONFLICT,
        detail="Email already exists"),

    'double_voting_409': fastapi.HTTPException(
        status_code=fastapi.status.HTTP_409_CONFLICT,
        detail="Same vote for the same interest"),

    'expired_410': fastapi.HTTPException(
        status_code=fastapi.status.HTTP_410_GONE,
        detail="Confirmation link is expired"),

    'fatal_error_503': fastapi.HTTPException(
        status_code=fastapi.status.HTTP_503_SERVICE_UNAVAILABLE,
        detail="Unknown error"),
}


@app.post("/register", status_code=201, )
def register(
        user_log_in: schemas.UserLogIn,
        db: Session = fastapi.Depends(database.get_db)):
    try:
        if not crud.read_user_by(db, column='email', value=user_log_in.email):  # If email is new
            token = services.create_access_token(email=user_log_in.email,
                                                 expires_min=config.ACCESS_TOKEN_EXPIRE_MINUTES)
            services.send_email_confirm_link(token=token, endpoint='http://127.0.0.1:8000/confirm-email')
            return crud.create_user(db=db, user=user_log_in, token=token)
        else:
            return fastapi_http_errors('email_already_exists_409')
    except Exception as e:
        raise fastapi_http_errors('fatal_error_503')


@app.get("/confirm-email", status_code=303, )
def confirm_email(
        token: str = fastapi.Query(...,
                                   min_length=64, max_length=256,
                                   description="jwt_token placed in url",
                                   example='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkc2IzMjFtcEBnbWFpbC5jb20iLCJleHAiOjE2MTAzNjY1MDV9.ZT0G5bHSNBdrh-onuAp4Q6m8mqWxfjBWbIg6GLJEAgk'),
        db: Session = fastapi.Depends(database.get_db)):
    try:
        if user := services.get_user_by_token(db=db, token=token):
            if user.created_datetime + timedelta(minutes=30) > datetime.now():  # TODO change minutes to days
                crud.update_user(db=db, user=user, column='is_active', value=True)
                return fastapi.responses.RedirectResponse(url=f"http://127.0.0.1:8000/users/me?token={token}")
            else:
                return fastapi_http_errors('expired_410')
        else:
            return fastapi_http_errors('wrong_token_403')
    except Exception as e:
        raise fastapi_http_errors('fatal_error_503')


@app.post("/login", response_model=schemas.Token)
def grant_token(
        form_data: OAuth2PasswordRequestForm = fastapi.Depends(),
        db: Session = fastapi.Depends(database.get_db)):
    try:
        if token := services.grant_token(db=db, email=form_data.username, password=form_data.password):
            return token
        else:
            return fastapi_http_errors('wrong_token_403')
    except Exception as e:
        raise fastapi_http_errors('fatal_error_503')


@app.post("/refresh-token",
          response_model=schemas.Token)
def refresh_token(
        token: str = fastapi.Depends(oauth2_scheme),
        db: Session = fastapi.Depends(database.get_db)):
    try:
        if token:
            if user := services.get_user_by_token(db=db, token=token):
                access_token = services.create_access_token(
                    email=user.email, expires_min=config.ACCESS_TOKEN_EXPIRE_MINUTES)
                crud.update_user(db=db, user=user, column='current_token', value=access_token)
                return 'Token successfully refreshed'
            else:
                return fastapi_http_errors('wrong_token_403')
        else:
            return fastapi_http_errors('no_token_401')
    except Exception as e:
        raise fastapi_http_errors('fatal_error_503')


@app.post("/logout")
def logout(token: str, db: Session = fastapi.Depends(database.get_db)):
    try:
        if token:
            if user := services.get_user_by_token(db=db, token=token):
                crud.update_user(db=db, user=user, column='current_token', value=None)  # Set token to None
                return f'Successfully logout user_id {user.id}'
            else:
                return fastapi_http_errors('wrong_token_403')
        else:
            return fastapi_http_errors('no_token_401')
    except Exception as e:
        raise fastapi_http_errors('fatal_error_503')


@app.get("/users/me", status_code=200)  # response model
def read_users_me(
        token: str = fastapi.Query(None),
        jwt_token: str = fastapi.Depends(oauth2_scheme),
        db: Session = fastapi.Depends(database.get_db)):
    """
      token: url_token indeed! REST requiring '-' instead of '_' in url,
      but python variable can't contain '-', unfortunately FastAPI doesn't converting it.
    """
    try:
        if token := (jwt_token or token):
            if user := services.get_user_by_token(db=db, token=token):
                return user
            else:
                return fastapi_http_errors('wrong_token_403')
        else:
            return fastapi_http_errors('no_token_401')
    except Exception as e:
        raise fastapi_http_errors('fatal_error_503')


@app.patch("/users/me", status_code=200)  # See PATCH vs PUT in module annotation.
def patch_users_me(
        column: str = fastapi.Query(..., description="Column to patch", example='email'),  # TODO restrict some columns
        value: str = fastapi.Query(..., description="New value", example='foo@gmail.com'),
        token: str = fastapi.Depends(oauth2_scheme),
        db: Session = fastapi.Depends(database.get_db)):
    try:
        if token:
            if user := services.get_user_by_token(db=db, token=token):
                crud.update_user(db=db, user=user, column=column, value=value)  # TODO test it
                return 'User successfully updated'
            else:
                return fastapi_http_errors('wrong_token_403')
        else:
            return fastapi_http_errors('no_token_401')
    except Exception as e:
        raise fastapi_http_errors('fatal_error_503')


@app.put("/users/me", status_code=200)  # See PATCH vs PUT in file annotation.
def put_users_me():
    pass


@app.delete("/users/me", status_code=200)  # response model
def delete_users_me(
        token: str = fastapi.Depends(oauth2_scheme),
        db: Session = fastapi.Depends(database.get_db)):
    try:
        if token := token:
            if user := services.get_user_by_token(db=db, token=token):
                crud.delete_user(db=db, user=user)
                return 'User successfully deleted'
            else:
                return fastapi_http_errors('wrong_token_403')
        else:
            return fastapi_http_errors('no_token_401')
    except Exception as e:
        raise fastapi_http_errors('fatal_error_503')


if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)