pub fn create_and_get_user(new_post: NewPost, conn: &PgConnection) -> BackendResult<ChildlessPostData> {
        let thread_uuid = ThreadUuid(new_post.thread_uuid);
        let thread: Thread = Thread::get_thread(thread_uuid, conn)?;
        if thread.locked || thread.archived {
            return Err(Error::ThreadImmutable);
        }

        // Do not allow the post to be created if the thread already has an "original post"
        if let None = new_post.parent_uuid {
            let thread_uuid: ThreadUuid = ThreadUuid(thread.uuid);
            // Expect this to return
            if let Err(_) = Post::get_root_post(thread_uuid, conn) {
                info!("New post created for new thread.");
            } else {
                return Err(Error::BadRequest); // TODO need better error
            }
        };

        let post: Post = Post::create_post(new_post, conn)?;
        let author_uuid = UserUuid(post.author_uuid);
        let user: User = User::get_user(author_uuid, conn)?;
        let user_uuid = UserUuid(post.author_uuid);
        let votes: VoteCounts = Post::get_vote_counts(&post, user_uuid, conn)?;
        let post_data = ChildlessPostData { post, user, votes };
        Ok(post_data)
    }
/// Creates a post, and also gets the associated author for the post.
Creates a post, and also gets the associated author for the post.
Creates a post and also gets the associated author for the post .
pub fn create_and_get_user(new_post: NewPost, conn: &PgConnection) -> BackendResult<ChildlessPostData> {
        let thread_uuid = ThreadUuid(new_post.thread_uuid);
        let thread: Thread = Thread::get_thread(thread_uuid, conn)?;
        if thread.locked || thread.archived {
            return Err(Error::ThreadImmutable);
        }
        // Do not allow the post to be created if the thread already has an "original post"
        if let None = new_post.parent_uuid {
            let thread_uuid: ThreadUuid = ThreadUuid(thread.uuid);
            // Expect this to return
            if let Err(_) = Post::get_root_post(thread_uuid, conn) {
                info!("New post created for new thread.");
            } else {
                return Err(Error::BadRequest); // TODO need better error
            }
        };
        let post: Post = Post::create_post(new_post, conn)?;
        let author_uuid = UserUuid(post.author_uuid);
        let user: User = User::get_user(author_uuid, conn)?;
        let user_uuid = UserUuid(post.author_uuid);
        let votes: VoteCounts = Post::get_vote_counts(&post, user_uuid, conn)?;
        let post_data = ChildlessPostData { post, user, votes };
        Ok(post_data)
    }
pub fn create_and_get_user ( new_post : NewPost , conn : & PgConnection ) -> BackendResult < ChildlessPostData > { let thread_uuid = ThreadUuid ( new_post . thread_uuid ) ; let thread : Thread = Thread :: get_thread ( thread_uuid , conn ) ? ; if thread . locked || thread . archived { return Err ( Error :: ThreadImmutable ) ; } // Do not allow the post to be created if the thread already has an "original post" if let None = new_post . parent_uuid { let thread_uuid : ThreadUuid = ThreadUuid ( thread . uuid ) ; // Expect this to return if let Err ( _ ) = Post :: get_root_post ( thread_uuid , conn ) { info ! ( " " ) ; } else { return Err ( Error :: BadRequest ) ; // TODO need better error } } ; let post : Post = Post :: create_post ( new_post , conn ) ? ; let author_uuid = UserUuid ( post . author_uuid ) ; let user : User = User :: get_user ( author_uuid , conn ) ? ; let user_uuid = UserUuid ( post . author_uuid ) ; let votes : VoteCounts = Post :: get_vote_counts ( & post , user_uuid , conn ) ? ; let post_data = ChildlessPostData { post , user , votes } ; Ok ( post_data ) }
Creates a post, and also gets the associated author for the post.
Creates a post and also gets the associated author for the post .
new_post
NewPost
conn
&PgConnection
new_post
NewPost
conn
&PgConnection