How to structure and monitor user posts on blog style app using Firebase











up vote
0
down vote

favorite












I am building an app that allows users to make public posts, you can make a post and view all new posts on the home page. I am struggling to find the best way to efficiently structure the database data and monitor all new posts that are made, as currently if a user is logged in, they can post anything without restriction. I need an effective way to screen posts for content that is uploaded to Firebase, or even a solution that when a new post is made it is sent for approval, rather than being sent on the database straight away. How should I manage this?



Here is the way that posts are uploaded to the database, I use duplicates of this structure also under authors and categories, which I am not sure if it is a good way to do it or not, should I be finding a way to have 1 instance of a post on the database, and instead use some kind of IDs to find it in different situations such as by author or by category?



     "posts": {
-childGeneratedKey: {
author: "author",
body: "body",
category: "category",
post_date: "1541784510.682485",
post_id: "childAddedID",
title: "post_title",
votes:"0",
}
-childGeneratedKey: {...
}


Here is how I handle posting in-app:



 func createPost(title: String, body: String) {

let timeInterval = NSDate().timeIntervalSince1970
let timeDouble = Double(timeInterval)

ref = Database.database().reference()
let posts = self.ref.child("posts")
let post_id = posts.childByAutoId().key!
let category = self.category
let post_date = timeDouble

if postTitle != "" {

let newPost: Dictionary<String, Any> = [
"title": title,
"body": body,
"votes": 0,
"author": username,
"post_id": post_id,
"category": category,
"post_date": post_date

]

if privatePost == false {
createNewPost(post: newPost, post_id: post_id, category: category)
} else if privatePost == true {
createnewPrivatePost(post: newPost, post_id: post_id, category: category)
}

}
}

func createNewPost(post: Dictionary<String, Any>, post_id: String, category: String) {

let user_id = Auth.auth().currentUser?.uid
let posts = self.ref.child("posts")
let authors = self.ref.child("authors")
let categories = self.ref.child("categories")
let users = self.ref.child("users")

posts.child(post_id).setValue(post)
authors.child(user_id!).child("posts").child(post_id).setValue(post)
categories.child(category).child("posts").child(post_id).setValue(post)
users.child(user_id!).child("posts").child(post_id).setValue(post)


}


I am finding it hard to find the best structure to handle this type of data and an efficient way to screen it to ensure that the content is acceptable (no abusive content etc) Please point me to the best way to handle a blog post type situation like this and how I can best monitor the posts that are set to the database, Thank you.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am building an app that allows users to make public posts, you can make a post and view all new posts on the home page. I am struggling to find the best way to efficiently structure the database data and monitor all new posts that are made, as currently if a user is logged in, they can post anything without restriction. I need an effective way to screen posts for content that is uploaded to Firebase, or even a solution that when a new post is made it is sent for approval, rather than being sent on the database straight away. How should I manage this?



    Here is the way that posts are uploaded to the database, I use duplicates of this structure also under authors and categories, which I am not sure if it is a good way to do it or not, should I be finding a way to have 1 instance of a post on the database, and instead use some kind of IDs to find it in different situations such as by author or by category?



         "posts": {
    -childGeneratedKey: {
    author: "author",
    body: "body",
    category: "category",
    post_date: "1541784510.682485",
    post_id: "childAddedID",
    title: "post_title",
    votes:"0",
    }
    -childGeneratedKey: {...
    }


    Here is how I handle posting in-app:



     func createPost(title: String, body: String) {

    let timeInterval = NSDate().timeIntervalSince1970
    let timeDouble = Double(timeInterval)

    ref = Database.database().reference()
    let posts = self.ref.child("posts")
    let post_id = posts.childByAutoId().key!
    let category = self.category
    let post_date = timeDouble

    if postTitle != "" {

    let newPost: Dictionary<String, Any> = [
    "title": title,
    "body": body,
    "votes": 0,
    "author": username,
    "post_id": post_id,
    "category": category,
    "post_date": post_date

    ]

    if privatePost == false {
    createNewPost(post: newPost, post_id: post_id, category: category)
    } else if privatePost == true {
    createnewPrivatePost(post: newPost, post_id: post_id, category: category)
    }

    }
    }

    func createNewPost(post: Dictionary<String, Any>, post_id: String, category: String) {

    let user_id = Auth.auth().currentUser?.uid
    let posts = self.ref.child("posts")
    let authors = self.ref.child("authors")
    let categories = self.ref.child("categories")
    let users = self.ref.child("users")

    posts.child(post_id).setValue(post)
    authors.child(user_id!).child("posts").child(post_id).setValue(post)
    categories.child(category).child("posts").child(post_id).setValue(post)
    users.child(user_id!).child("posts").child(post_id).setValue(post)


    }


    I am finding it hard to find the best structure to handle this type of data and an efficient way to screen it to ensure that the content is acceptable (no abusive content etc) Please point me to the best way to handle a blog post type situation like this and how I can best monitor the posts that are set to the database, Thank you.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am building an app that allows users to make public posts, you can make a post and view all new posts on the home page. I am struggling to find the best way to efficiently structure the database data and monitor all new posts that are made, as currently if a user is logged in, they can post anything without restriction. I need an effective way to screen posts for content that is uploaded to Firebase, or even a solution that when a new post is made it is sent for approval, rather than being sent on the database straight away. How should I manage this?



      Here is the way that posts are uploaded to the database, I use duplicates of this structure also under authors and categories, which I am not sure if it is a good way to do it or not, should I be finding a way to have 1 instance of a post on the database, and instead use some kind of IDs to find it in different situations such as by author or by category?



           "posts": {
      -childGeneratedKey: {
      author: "author",
      body: "body",
      category: "category",
      post_date: "1541784510.682485",
      post_id: "childAddedID",
      title: "post_title",
      votes:"0",
      }
      -childGeneratedKey: {...
      }


      Here is how I handle posting in-app:



       func createPost(title: String, body: String) {

      let timeInterval = NSDate().timeIntervalSince1970
      let timeDouble = Double(timeInterval)

      ref = Database.database().reference()
      let posts = self.ref.child("posts")
      let post_id = posts.childByAutoId().key!
      let category = self.category
      let post_date = timeDouble

      if postTitle != "" {

      let newPost: Dictionary<String, Any> = [
      "title": title,
      "body": body,
      "votes": 0,
      "author": username,
      "post_id": post_id,
      "category": category,
      "post_date": post_date

      ]

      if privatePost == false {
      createNewPost(post: newPost, post_id: post_id, category: category)
      } else if privatePost == true {
      createnewPrivatePost(post: newPost, post_id: post_id, category: category)
      }

      }
      }

      func createNewPost(post: Dictionary<String, Any>, post_id: String, category: String) {

      let user_id = Auth.auth().currentUser?.uid
      let posts = self.ref.child("posts")
      let authors = self.ref.child("authors")
      let categories = self.ref.child("categories")
      let users = self.ref.child("users")

      posts.child(post_id).setValue(post)
      authors.child(user_id!).child("posts").child(post_id).setValue(post)
      categories.child(category).child("posts").child(post_id).setValue(post)
      users.child(user_id!).child("posts").child(post_id).setValue(post)


      }


      I am finding it hard to find the best structure to handle this type of data and an efficient way to screen it to ensure that the content is acceptable (no abusive content etc) Please point me to the best way to handle a blog post type situation like this and how I can best monitor the posts that are set to the database, Thank you.










      share|improve this question















      I am building an app that allows users to make public posts, you can make a post and view all new posts on the home page. I am struggling to find the best way to efficiently structure the database data and monitor all new posts that are made, as currently if a user is logged in, they can post anything without restriction. I need an effective way to screen posts for content that is uploaded to Firebase, or even a solution that when a new post is made it is sent for approval, rather than being sent on the database straight away. How should I manage this?



      Here is the way that posts are uploaded to the database, I use duplicates of this structure also under authors and categories, which I am not sure if it is a good way to do it or not, should I be finding a way to have 1 instance of a post on the database, and instead use some kind of IDs to find it in different situations such as by author or by category?



           "posts": {
      -childGeneratedKey: {
      author: "author",
      body: "body",
      category: "category",
      post_date: "1541784510.682485",
      post_id: "childAddedID",
      title: "post_title",
      votes:"0",
      }
      -childGeneratedKey: {...
      }


      Here is how I handle posting in-app:



       func createPost(title: String, body: String) {

      let timeInterval = NSDate().timeIntervalSince1970
      let timeDouble = Double(timeInterval)

      ref = Database.database().reference()
      let posts = self.ref.child("posts")
      let post_id = posts.childByAutoId().key!
      let category = self.category
      let post_date = timeDouble

      if postTitle != "" {

      let newPost: Dictionary<String, Any> = [
      "title": title,
      "body": body,
      "votes": 0,
      "author": username,
      "post_id": post_id,
      "category": category,
      "post_date": post_date

      ]

      if privatePost == false {
      createNewPost(post: newPost, post_id: post_id, category: category)
      } else if privatePost == true {
      createnewPrivatePost(post: newPost, post_id: post_id, category: category)
      }

      }
      }

      func createNewPost(post: Dictionary<String, Any>, post_id: String, category: String) {

      let user_id = Auth.auth().currentUser?.uid
      let posts = self.ref.child("posts")
      let authors = self.ref.child("authors")
      let categories = self.ref.child("categories")
      let users = self.ref.child("users")

      posts.child(post_id).setValue(post)
      authors.child(user_id!).child("posts").child(post_id).setValue(post)
      categories.child(category).child("posts").child(post_id).setValue(post)
      users.child(user_id!).child("posts").child(post_id).setValue(post)


      }


      I am finding it hard to find the best structure to handle this type of data and an efficient way to screen it to ensure that the content is acceptable (no abusive content etc) Please point me to the best way to handle a blog post type situation like this and how I can best monitor the posts that are set to the database, Thank you.







      ios swift firebase firebase-realtime-database






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 11:15









      PradyumanDixit

      2,4512818




      2,4512818










      asked Nov 10 at 0:53









      Peter Ruppert

      79111




      79111





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235073%2fhow-to-structure-and-monitor-user-posts-on-blog-style-app-using-firebase%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235073%2fhow-to-structure-and-monitor-user-posts-on-blog-style-app-using-firebase%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Schultheiß

          Verwaltungsgliederung Dänemarks

          Liste der Kulturdenkmale in Wilsdruff