Spaces:
Paused
Paused
auth details updated
Browse files- app/auth.py +7 -1
- app/dashboard.py +29 -11
- app/main.py +2 -0
- app/models.py +4 -0
app/auth.py
CHANGED
|
@@ -27,6 +27,10 @@ pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
| 27 |
class SignUp(BaseModel):
|
| 28 |
email: EmailStr
|
| 29 |
password: str
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
class Login(BaseModel):
|
|
@@ -44,7 +48,9 @@ async def signup(data: SignUp, db: AsyncSession = Depends(get_db)):
|
|
| 44 |
raise HTTPException(status_code=400, detail="Email already exists")
|
| 45 |
|
| 46 |
hashed_password = pwd_context.hash(data.password)
|
| 47 |
-
new_user = User(email=data.email, hashed_password=hashed_password
|
|
|
|
|
|
|
| 48 |
|
| 49 |
try:
|
| 50 |
db.add(new_user)
|
|
|
|
| 27 |
class SignUp(BaseModel):
|
| 28 |
email: EmailStr
|
| 29 |
password: str
|
| 30 |
+
mobile: str | None = None
|
| 31 |
+
name: str | None = None
|
| 32 |
+
dob: str | None = None
|
| 33 |
+
preparing_for: str | None = None
|
| 34 |
|
| 35 |
|
| 36 |
class Login(BaseModel):
|
|
|
|
| 48 |
raise HTTPException(status_code=400, detail="Email already exists")
|
| 49 |
|
| 50 |
hashed_password = pwd_context.hash(data.password)
|
| 51 |
+
new_user = User(email=data.email, hashed_password=hashed_password,
|
| 52 |
+
mobile=data.mobile, name=data.name, dob=data.dob,
|
| 53 |
+
preparing_for=data.preparing_for)
|
| 54 |
|
| 55 |
try:
|
| 56 |
db.add(new_user)
|
app/dashboard.py
CHANGED
|
@@ -4,7 +4,7 @@ from sqlalchemy.future import select
|
|
| 4 |
from sqlalchemy.orm import sessionmaker
|
| 5 |
from sqlalchemy import desc
|
| 6 |
from app.database import engine
|
| 7 |
-
from app.models import VideoUpload
|
| 8 |
|
| 9 |
router = APIRouter()
|
| 10 |
|
|
@@ -24,17 +24,35 @@ async def get_user_dashboard(user_id: int):
|
|
| 24 |
result = await session.execute(query)
|
| 25 |
uploads = result.scalars().all()
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# Convert SQLAlchemy objects to dicts for response
|
| 28 |
-
return
|
| 29 |
-
{
|
| 30 |
-
"id":
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
"
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
except Exception as e:
|
| 39 |
raise HTTPException(
|
| 40 |
status_code=500, detail=f"Error fetching dashboard data: {str(e)}"
|
|
|
|
| 4 |
from sqlalchemy.orm import sessionmaker
|
| 5 |
from sqlalchemy import desc
|
| 6 |
from app.database import engine
|
| 7 |
+
from app.models import VideoUpload, User
|
| 8 |
|
| 9 |
router = APIRouter()
|
| 10 |
|
|
|
|
| 24 |
result = await session.execute(query)
|
| 25 |
uploads = result.scalars().all()
|
| 26 |
|
| 27 |
+
# Get user details
|
| 28 |
+
user_query = select(User).where(User.id == user_id)
|
| 29 |
+
user_result = await session.execute(user_query)
|
| 30 |
+
user = user_result.scalars().first()
|
| 31 |
+
|
| 32 |
+
if not user:
|
| 33 |
+
raise HTTPException(status_code=404, detail="User not found")
|
| 34 |
+
|
| 35 |
# Convert SQLAlchemy objects to dicts for response
|
| 36 |
+
return {
|
| 37 |
+
"user": {
|
| 38 |
+
"id": user.id,
|
| 39 |
+
"email": user.email,
|
| 40 |
+
"mobile": user.mobile,
|
| 41 |
+
"name": user.name,
|
| 42 |
+
"dob": user.dob,
|
| 43 |
+
"preparing_for": user.preparing_for,
|
| 44 |
+
},
|
| 45 |
+
"uploads": [
|
| 46 |
+
{
|
| 47 |
+
"id": upload.id,
|
| 48 |
+
"video_url": upload.video_url,
|
| 49 |
+
"pdf_url": upload.pdf_url,
|
| 50 |
+
"status": upload.status,
|
| 51 |
+
"created_at": upload.created_at,
|
| 52 |
+
}
|
| 53 |
+
for upload in uploads
|
| 54 |
+
],
|
| 55 |
+
}
|
| 56 |
except Exception as e:
|
| 57 |
raise HTTPException(
|
| 58 |
status_code=500, detail=f"Error fetching dashboard data: {str(e)}"
|
app/main.py
CHANGED
|
@@ -7,6 +7,7 @@ from dotenv import load_dotenv
|
|
| 7 |
# Load environment variables
|
| 8 |
load_dotenv()
|
| 9 |
|
|
|
|
| 10 |
from app.auth import router as auth_router
|
| 11 |
from app.upload import router as upload_router
|
| 12 |
from app.dashboard import router as dashboard_router
|
|
@@ -61,6 +62,7 @@ async def startup_event():
|
|
| 61 |
logger.info("✅ FastAPI app started")
|
| 62 |
logger.info(f"Environment: {os.getenv('ENVIRONMENT', 'development')}")
|
| 63 |
logger.info(f"Database URL configured: {'DATABASE_URL' in os.environ}")
|
|
|
|
| 64 |
|
| 65 |
@app.on_event("shutdown")
|
| 66 |
async def shutdown_event():
|
|
|
|
| 7 |
# Load environment variables
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
+
from app.database import init_db # Import init_db
|
| 11 |
from app.auth import router as auth_router
|
| 12 |
from app.upload import router as upload_router
|
| 13 |
from app.dashboard import router as dashboard_router
|
|
|
|
| 62 |
logger.info("✅ FastAPI app started")
|
| 63 |
logger.info(f"Environment: {os.getenv('ENVIRONMENT', 'development')}")
|
| 64 |
logger.info(f"Database URL configured: {'DATABASE_URL' in os.environ}")
|
| 65 |
+
await init_db()
|
| 66 |
|
| 67 |
@app.on_event("shutdown")
|
| 68 |
async def shutdown_event():
|
app/models.py
CHANGED
|
@@ -8,6 +8,10 @@ class User(Base):
|
|
| 8 |
id = Column(Integer, primary_key=True, index=True)
|
| 9 |
email = Column(String, unique=True, index=True)
|
| 10 |
hashed_password = Column(String)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
class VideoUpload(Base):
|
|
|
|
| 8 |
id = Column(Integer, primary_key=True, index=True)
|
| 9 |
email = Column(String, unique=True, index=True)
|
| 10 |
hashed_password = Column(String)
|
| 11 |
+
mobile = Column(String, nullable=True)
|
| 12 |
+
name = Column(String, nullable=True)
|
| 13 |
+
dob = Column(String, nullable=True)
|
| 14 |
+
preparing_for = Column(String, nullable=True)
|
| 15 |
|
| 16 |
|
| 17 |
class VideoUpload(Base):
|