create post endpoint

This commit is contained in:
Łukasz Jędyk 2022-06-09 22:02:00 +02:00
parent 6fa42c9a0a
commit c484359495
2 changed files with 3 additions and 1 deletions

View File

@ -127,10 +127,12 @@ def delete_twitter_campaign():
return "Invalid request!", 400
twitter_campaign = TwitterCampaign.query.filter_by(user_id=user_id, id=request_json['campaign_id']).first()
campaign_posts = TwitterPost.query.filter_by(campaign_id=request_json['campaign_id'])
if not twitter_campaign:
return "Capmaign not found!", 404
db.session.delete(campaign_posts)
db.session.delete(twitter_campaign)
db.session.commit()

View File

@ -19,7 +19,6 @@ class TwitterCampaign(db.Model):
user_id = db.Column(db.String(64), nullable=False)
campaign_name = db.Column(db.String(64), nullable=False)
twitter_account_id = db.Column(db.String(32), nullable=False)
user_input = db.Column(db.String(100), nullable=False)
posts = db.relationship('TwitterPost', backref='campaign', lazy=True)
class TwitterPost(db.Model):
@ -28,5 +27,6 @@ class TwitterPost(db.Model):
id = db.Column(db.String(36), primary_key=True)
campaign_id = db.Column(db.String(36), db.ForeignKey(TwitterCampaign.id), nullable=False)
user_id = db.Column(db.String(64), nullable=False)
user_input = db.Column(db.String(100), nullable=False)
post_content = db.Column(db.String(300), nullable=False)
twitter_post_id = db.Column(db.String(32), unique=True, nullable=False)