Poems added to db
This commit is contained in:
parent
e5da503ee5
commit
5012642f7a
43
back/main.py
43
back/main.py
@ -20,9 +20,9 @@ import os
|
|||||||
|
|
||||||
from .utils import *
|
from .utils import *
|
||||||
from .db import Base, engine, SessionLocal, database
|
from .db import Base, engine, SessionLocal, database
|
||||||
from .models import Announcement, Trashbox, UserDatabase
|
from .models import Announcement, Trashbox, UserDatabase, Poems
|
||||||
|
|
||||||
from . import schema
|
from . import schemas
|
||||||
|
|
||||||
Base.metadata.create_all(bind=engine)
|
Base.metadata.create_all(bind=engine)
|
||||||
|
|
||||||
@ -35,6 +35,33 @@ if not os.path.exists("./uploads"):
|
|||||||
os.mkdir("C:/Users/38812/porridger/uploads")
|
os.mkdir("C:/Users/38812/porridger/uploads")
|
||||||
app.mount("/uploads", StaticFiles(directory = "./uploads"))
|
app.mount("/uploads", StaticFiles(directory = "./uploads"))
|
||||||
|
|
||||||
|
# # Загружаем стихи
|
||||||
|
# def add_poems_to_db(db: Session):
|
||||||
|
# f1 = open('text121.txt', encoding='utf-8', mode='r')#открыть фаил для чтения на русском
|
||||||
|
# for a in range(1, 102):
|
||||||
|
# f1.seek(0)#перейти к началу
|
||||||
|
# i=0
|
||||||
|
# str1=""
|
||||||
|
# stixi = ""
|
||||||
|
# while str1 != f"стих {a}\n":
|
||||||
|
# str1=f1.readline()
|
||||||
|
# name=f1.readline()
|
||||||
|
# # Цикл для склеивания стихотворения
|
||||||
|
# while str1 != f"стих {a+1}\n":
|
||||||
|
# str1=f1.readline()
|
||||||
|
# if(str1 != f"стих {a+1}\n"):
|
||||||
|
# stixi+=str1#удаление /n и заключение в список
|
||||||
|
# poem = Poems(poem_name=name, poem_text=stixi)
|
||||||
|
# # В конце каждой итерации добавляем в базу данных
|
||||||
|
# db.add(poem)
|
||||||
|
# db.commit()
|
||||||
|
# db.refresh(poem)
|
||||||
|
# # close the file
|
||||||
|
# f1.close()
|
||||||
|
|
||||||
|
## Записываем стихи в базу данных, если их еще нет (запускать только если ).
|
||||||
|
# add_poems_to_db(database)
|
||||||
|
|
||||||
|
|
||||||
# Функция, создающая сессию БД при каждом запросе к нашему API.
|
# Функция, создающая сессию БД при каждом запросе к нашему API.
|
||||||
# Срабатывает до запуска остальных функций.
|
# Срабатывает до запуска остальных функций.
|
||||||
@ -137,14 +164,12 @@ def delete_from_db(data = Body()):#функция удаления объект
|
|||||||
|
|
||||||
# Забронировать объявление
|
# Забронировать объявление
|
||||||
@app.post("/api/book")
|
@app.post("/api/book")
|
||||||
def change_book_status(data: schema.Book):
|
def change_book_status(data: schemas.Book):
|
||||||
try:
|
try:
|
||||||
# Получаем id пользователя, который бронирует объявление
|
|
||||||
temp_user_id = 1
|
|
||||||
# Находим объявление по данному id
|
# Находим объявление по данному id
|
||||||
announcement_to_change = database.query(Announcement).filter(Announcement.id == data.id).first()
|
announcement_to_change = database.query(Announcement).filter(Announcement.id == data.id).first()
|
||||||
# Изменяем поле booked_status на полученный id
|
# Изменяем поле booked_status на полученный id
|
||||||
announcement_to_change.booked_status = temp_user_id
|
announcement_to_change.booked_status += 1
|
||||||
return {"Success": True}
|
return {"Success": True}
|
||||||
except:
|
except:
|
||||||
return {"Success": False}
|
return {"Success": False}
|
||||||
@ -182,16 +207,16 @@ async def login_for_access_token(
|
|||||||
return {"access_token":access_token}
|
return {"access_token":access_token}
|
||||||
|
|
||||||
|
|
||||||
# @app.get("/api/users/me/", response_model=schema.User)
|
# @app.get("/api/users/me/", response_model=schemas.User)
|
||||||
# async def read_users_me( #!!!!!!!!!!!
|
# async def read_users_me( #!!!!!!!!!!!
|
||||||
# current_user: Annotated[schema.User, Depends(get_current_active_user)]
|
# current_user: Annotated[schemas.User, Depends(get_current_active_user)]
|
||||||
# ):
|
# ):
|
||||||
# return {"data": current_user}
|
# return {"data": current_user}
|
||||||
|
|
||||||
|
|
||||||
# @app.get("/api/users/me/items/")
|
# @app.get("/api/users/me/items/")
|
||||||
# async def read_own_items(
|
# async def read_own_items(
|
||||||
# current_user: Annotated[schema.User, Depends(get_current_active_user)]
|
# current_user: Annotated[schemas.User, Depends(get_current_active_user)]
|
||||||
# ):
|
# ):
|
||||||
# return [{"Current user name": current_user.name, "Current user surname": current_user.surname}]
|
# return [{"Current user name": current_user.name, "Current user surname": current_user.surname}]
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ class Poems(Base):#класс поэзии
|
|||||||
__tablename__ = "poems"
|
__tablename__ = "poems"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True, index=True) #айди
|
id = Column(Integer, primary_key=True, index=True) #айди
|
||||||
|
poem_name = Column(String) # название стихотворения
|
||||||
poem_text = Column(String) # текст стихотворения
|
poem_text = Column(String) # текст стихотворения
|
||||||
|
|
||||||
# from typing import AsyncGenerator
|
# from typing import AsyncGenerator
|
||||||
|
@ -1,20 +1,3 @@
|
|||||||
# import uuid
|
|
||||||
|
|
||||||
# from fastapi_users import schemas
|
|
||||||
|
|
||||||
|
|
||||||
# class UserRead(schema.BaseUser[uuid.UUID]):
|
|
||||||
# pass
|
|
||||||
|
|
||||||
|
|
||||||
# class UserCreate(schema.BaseUserCreate):
|
|
||||||
# pass
|
|
||||||
|
|
||||||
|
|
||||||
# class UserUpdate(schema.BaseUserUpdate):
|
|
||||||
# pass
|
|
||||||
|
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import Annotated, Union
|
from typing import Annotated, Union
|
||||||
|
|
||||||
@ -44,4 +27,6 @@ class User(BaseModel):
|
|||||||
|
|
||||||
class UserInDB(User):
|
class UserInDB(User):
|
||||||
password: str
|
password: str
|
||||||
hashed_password: str
|
hashed_password: str
|
||||||
|
|
||||||
|
|
@ -11,7 +11,7 @@ from sqlalchemy import select
|
|||||||
|
|
||||||
# from .db import Session, database
|
# from .db import Session, database
|
||||||
from .models import UserDatabase
|
from .models import UserDatabase
|
||||||
from .schema import Token, TokenData, UserInDB, User
|
from .schemas import Token, TokenData, UserInDB, User
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
"""new colomn (poem_name) added to poems table
|
||||||
|
|
||||||
|
Revision ID: 1cf412fb7547
|
||||||
|
Revises: daffcb4729af
|
||||||
|
Create Date: 2023-07-27 21:29:57.568487
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '1cf412fb7547'
|
||||||
|
down_revision = 'daffcb4729af'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
pass
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
pass
|
||||||
|
# ### end Alembic commands ###
|
@ -0,0 +1,28 @@
|
|||||||
|
"""new colomn (poem_name) added to poems table
|
||||||
|
|
||||||
|
Revision ID: 57c3df575fa5
|
||||||
|
Revises: 1cf412fb7547
|
||||||
|
Create Date: 2023-07-27 21:40:06.979472
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '57c3df575fa5'
|
||||||
|
down_revision = '1cf412fb7547'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('poems', sa.Column('poem_name', sa.String(), nullable=True))
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column('poems', 'poem_name')
|
||||||
|
# ### end Alembic commands ###
|
2706
text121.txt
Normal file
2706
text121.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user