feat: Add publish and mark-published endpoints with validation
- Add /api/posts/{id}/publish endpoint for API-based publishing
- Add /api/posts/{id}/mark-published endpoint for manual workflow
- Add content length validation before publishing
- Update modal with "Ya lo publiqué" and "Publicar (API)" buttons
- Fix retry_count handling for None values
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -220,6 +220,62 @@ async def reject_post(post_id: int, db: Session = Depends(get_db)):
|
||||
return {"message": "Post rechazado", "post_id": post_id}
|
||||
|
||||
|
||||
@router.post("/{post_id}/publish")
|
||||
async def publish_post_now(post_id: int, db: Session = Depends(get_db)):
|
||||
"""Publicar un post inmediatamente."""
|
||||
from worker.tasks.publish_post import publish_to_platform
|
||||
|
||||
post = db.query(Post).filter(Post.id == post_id).first()
|
||||
if not post:
|
||||
raise HTTPException(status_code=404, detail="Post no encontrado")
|
||||
|
||||
if post.status not in ["draft", "pending_approval", "scheduled", "failed"]:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"No se puede publicar un post con status '{post.status}'"
|
||||
)
|
||||
|
||||
# Cambiar estado a publishing
|
||||
post.status = "publishing"
|
||||
db.commit()
|
||||
|
||||
# Encolar tarea de publicación para cada plataforma
|
||||
for platform in post.platforms:
|
||||
publish_to_platform.delay(post.id, platform)
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"message": "Post enviado a publicación",
|
||||
"post_id": post_id,
|
||||
"platforms": post.platforms
|
||||
}
|
||||
|
||||
|
||||
@router.post("/{post_id}/mark-published")
|
||||
async def mark_post_as_published(post_id: int, db: Session = Depends(get_db)):
|
||||
"""Marcar un post como publicado manualmente (sin usar API)."""
|
||||
post = db.query(Post).filter(Post.id == post_id).first()
|
||||
if not post:
|
||||
raise HTTPException(status_code=404, detail="Post no encontrado")
|
||||
|
||||
if post.status not in ["draft", "pending_approval", "scheduled", "failed"]:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"No se puede marcar un post con status '{post.status}'"
|
||||
)
|
||||
|
||||
post.status = "published"
|
||||
post.published_at = datetime.utcnow()
|
||||
post.error_message = None
|
||||
db.commit()
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"message": "Post marcado como publicado",
|
||||
"post_id": post_id
|
||||
}
|
||||
|
||||
|
||||
@router.post("/{post_id}/regenerate")
|
||||
async def regenerate_post(post_id: int, db: Session = Depends(get_db)):
|
||||
"""Regenerar contenido de un post con IA."""
|
||||
|
||||
Reference in New Issue
Block a user