57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
|
|
from fastapi import (
|
||
|
|
APIRouter,
|
||
|
|
Depends,
|
||
|
|
status,
|
||
|
|
HTTPException
|
||
|
|
)
|
||
|
|
from fastapi.responses import JSONResponse
|
||
|
|
from fastapi.encoders import jsonable_encoder
|
||
|
|
from fastapi.security import OAuth2PasswordRequestForm
|
||
|
|
from src.settings import db, ACCESS_TOKEN_EXPIRE_MINUTES
|
||
|
|
from ..models.history_find import *
|
||
|
|
from typing import List
|
||
|
|
from datetime import datetime, timedelta
|
||
|
|
|
||
|
|
from ..models.models import (
|
||
|
|
UserModel,
|
||
|
|
ShowUserModel,
|
||
|
|
UpdateUserModel
|
||
|
|
)
|
||
|
|
from ..dependecies import (
|
||
|
|
get_current_user,
|
||
|
|
authenticate_user,
|
||
|
|
create_access_token,
|
||
|
|
get_password_hash
|
||
|
|
)
|
||
|
|
import re
|
||
|
|
|
||
|
|
history = APIRouter()
|
||
|
|
##############################POST###############################################
|
||
|
|
@history.post("/create_history", response_description="Add new user", response_model=HistoryFindModel)
|
||
|
|
async def create_history(history: HistoryFindModel, current_user: ShowUserModel = Depends(get_current_user)):
|
||
|
|
datetime_now = datetime.now()
|
||
|
|
post.created_at = datetime_now.strftime("%m/%d/%y %H:%M:%S")
|
||
|
|
post = jsonable_encoder(post)
|
||
|
|
new_post = await db["history_find"].insert_one(post)
|
||
|
|
created = await db["history_find"].find_one({"_id": new_post.inserted_id})
|
||
|
|
return JSONResponse(status_code=status.HTTP_201_CREATED, content=created)
|
||
|
|
|
||
|
|
@history.get(
|
||
|
|
"/list_history", response_description="List all posts", response_model=List[HistoryFindModel]
|
||
|
|
)
|
||
|
|
async def list_post(current_user: ShowUserModel = Depends(get_current_user)):
|
||
|
|
history_find = await db["history_find"].find().to_list(1000)
|
||
|
|
return history_find
|
||
|
|
|
||
|
|
|
||
|
|
# @post.get(
|
||
|
|
# "/get_post_by_name", response_description="Get a single posot", response_model=PostModel
|
||
|
|
# )
|
||
|
|
# async def show_post(id: str):
|
||
|
|
# print(id)
|
||
|
|
# post = await db["posts"].find_one({"_id": id})
|
||
|
|
# print(post)
|
||
|
|
# if post is not None:
|
||
|
|
# return post
|
||
|
|
# else:
|
||
|
|
# return None
|