Added PostgreSQL RDS database. Added channels protected endpoints. Added scripts and docker config to run application locally in dev mode.
Some checks failed
AWS Deploy on Push / build (push) Failing after 41s

This commit is contained in:
2025-05-21 14:02:01 -05:00
parent b947ac67f0
commit 489281f3eb
18 changed files with 409 additions and 125 deletions

View File

@@ -1,10 +1,15 @@
from fastapi.security import OAuth2PasswordBearer
import uvicorn
from fastapi import FastAPI, Depends
from fastapi import FastAPI, Depends, HTTPException, status
from fastapi.responses import RedirectResponse
from sqlalchemy.orm import Session
from typing import List
from app.auth.cognito import initiate_auth
from app.auth.dependencies import get_current_user, require_roles
from app.models.auth import CognitoUser, SigninRequest, TokenResponse
from app.models import ChannelDB, ChannelCreate, ChannelResponse
from app.utils.database import get_db
from fastapi import FastAPI, Depends, Security
from fastapi.security import OAuth2PasswordBearer
@@ -89,4 +94,83 @@ def protected_admin_endpoint(user: CognitoUser = Depends(get_current_user)):
Protected endpoint that requires the 'admin' role.
If the user has 'admin' role, returns success message.
"""
return {"message": f"Hello {user.username}, you have admin privileges!"}
return {"message": f"Hello {user.username}, you have admin privileges!"}
# Channel CRUD Endpoints
@app.post("/channels", response_model=ChannelResponse, status_code=status.HTTP_201_CREATED)
@require_roles("admin")
def create_channel(
channel: ChannelCreate,
db: Session = Depends(get_db),
user: CognitoUser = Depends(get_current_user)
):
"""Create a new channel"""
db_channel = ChannelDB(**channel.model_dump())
db.add(db_channel)
db.commit()
db.refresh(db_channel)
return db_channel
@app.get("/channels/{tvg_id}", response_model=ChannelResponse)
def get_channel(
tvg_id: str,
db: Session = Depends(get_db)
):
"""Get a channel by tvg_id"""
channel = db.query(ChannelDB).filter(ChannelDB.tvg_id == tvg_id).first()
if not channel:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Channel not found"
)
return channel
@app.put("/channels/{tvg_id}", response_model=ChannelResponse)
@require_roles("admin")
def update_channel(
tvg_id: str,
channel: ChannelCreate,
db: Session = Depends(get_db),
user: CognitoUser = Depends(get_current_user)
):
"""Update a channel"""
db_channel = db.query(ChannelDB).filter(ChannelDB.tvg_id == tvg_id).first()
if not db_channel:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Channel not found"
)
for key, value in channel.model_dump().items():
setattr(db_channel, key, value)
db.commit()
db.refresh(db_channel)
return db_channel
@app.delete("/channels/{tvg_id}", status_code=status.HTTP_204_NO_CONTENT)
@require_roles("admin")
def delete_channel(
tvg_id: str,
db: Session = Depends(get_db),
user: CognitoUser = Depends(get_current_user)
):
"""Delete a channel"""
channel = db.query(ChannelDB).filter(ChannelDB.tvg_id == tvg_id).first()
if not channel:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Channel not found"
)
db.delete(channel)
db.commit()
return None
@app.get("/channels", response_model=List[ChannelResponse])
def list_channels(
skip: int = 0,
limit: int = 100,
db: Session = Depends(get_db)
):
"""List all channels with pagination"""
return db.query(ChannelDB).offset(skip).limit(limit).all()