mirror of
https://gitverse.ru/kpa39l/telepost.git
synced 2026-09-29 18:05:08 +00:00
Implement phase 3 and 4: Telegram and Twitter integration
This commit is contained in:
@@ -98,4 +98,85 @@ def delete_post(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Post not found"
|
||||
)
|
||||
return {"message": "Post deleted successfully"}
|
||||
return {"message": "Post deleted successfully"}
|
||||
|
||||
|
||||
@router.post("/{post_id}/publish_telegram")
|
||||
def publish_post_to_telegram(
|
||||
post_id: int,
|
||||
chat_id: str,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Опубликовать пост в Telegram
|
||||
"""
|
||||
post_service = PostService(db)
|
||||
|
||||
# Проверяем, что пост принадлежит пользователю
|
||||
post = post_service.get_post(post_id=post_id, owner_id=current_user.id)
|
||||
if not post:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Post not found"
|
||||
)
|
||||
|
||||
try:
|
||||
success = post_service.publish_post_to_telegram(post_id=post_id, chat_id=chat_id)
|
||||
if success:
|
||||
return {"message": "Post published to Telegram successfully", "success": True}
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to publish post to Telegram"
|
||||
)
|
||||
except ValueError as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=str(e)
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Error publishing post to Telegram: {str(e)}"
|
||||
)
|
||||
|
||||
|
||||
@router.post("/{post_id}/publish_twitter")
|
||||
def publish_post_to_twitter(
|
||||
post_id: int,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Опубликовать пост в Twitter
|
||||
"""
|
||||
post_service = PostService(db)
|
||||
|
||||
# Проверяем, что пост принадлежит пользователю
|
||||
post = post_service.get_post(post_id=post_id, owner_id=current_user.id)
|
||||
if not post:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Post not found"
|
||||
)
|
||||
|
||||
try:
|
||||
success = post_service.publish_post_to_twitter(post_id=post_id)
|
||||
if success:
|
||||
return {"message": "Post published to Twitter successfully", "success": True}
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to publish post to Twitter"
|
||||
)
|
||||
except ValueError as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=str(e)
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Error publishing post to Twitter: {str(e)}"
|
||||
)
|
||||
Reference in New Issue
Block a user