예제 #1
0
def to_entity(comment: Comment, post: Post) -> CommentEntity:
    return CommentEntity(id=comment.id_,
                         post=post_data.to_entity(post),
                         author=profile_data.to_entity(comment.author),
                         comment=comment.comment,
                         last_visit=comment.last_visit,
                         comment_date=comment.comment_date,
                         deleted=comment.deleted
                         )
예제 #2
0
def to_entity(post: Post) -> PostEntity:
    return PostEntity(id=post.id_,
                      profile=profile_data.to_entity(post.profile),
                      url=post.url,
                      url_imgs=post.url_imgs,
                      post_date=post.post_date,
                      caption=post.caption,
                      last_visit=post.last_visit,
                      created_at=post.created_at,
                      deleted=post.deleted)
예제 #3
0
def create_or_update_following(follower: Profile, followed: Profile):
    follower_on_db: Profile = profile_data.get_or_create_profile(
        follower.username)
    followed_on_db: Profile = profile_data.get_or_create_profile(
        followed.username)

    follower_entity: ProfileEntity = profile_data.to_entity(follower_on_db)
    followed_entity: ProfileEntity = profile_data.to_entity(followed_on_db)

    following_on_db: FollowingEntity = \
        FollowingEntity.get_or_create(follower=follower_entity, followed=followed_entity)[0]

    now = int(datetime.now().timestamp())
    if following_on_db.created_at is None:
        following_on_db.created_at = now
    else:
        following_on_db.created_at = following_on_db.created_at

    following_on_db.last_visit = now

    following_on_db.save()
예제 #4
0
def create_or_update_like_on_post(post: Post, profile: Profile):
    like_on_post_entity_on_db: LikeOnPostEntity = \
        LikeOnPostEntity.get_or_create(post=post_data.to_entity(post), profile=profile_data.to_entity(profile))[0]

    now = int(datetime.now().timestamp())
    if like_on_post_entity_on_db.created_at is None:
        like_on_post_entity_on_db.created_at = now
    else:
        like_on_post_entity_on_db.created_at = like_on_post_entity_on_db.created_at

    like_on_post_entity_on_db.last_visit = now

    like_on_post_entity_on_db.save()
예제 #5
0
def create_or_update_comment(comment: Comment, post: Post):
    comment_on_db: CommentEntity = \
        CommentEntity.get_or_create(post=post_data.to_entity(post), author=profile_data.to_entity(comment.author),
                                    comment_date=comment.comment_date)[0]

    now = int(datetime.now().timestamp())
    if comment_on_db.created_at is None:
        comment.created_at = now
    else:
        comment.created_at = comment_on_db.created_at

    comment.last_visit = now

    comment.id_ = comment_on_db.id
    comment_entity: CommentEntity = to_entity(comment, post)

    comment_entity.save()

    for comment_liker in comment.likers:
        create_or_update_like_on_comment(comment, post, comment_liker)