Store the “known” status of a post in the database.
[Sone.git] / src / main / java / net / pterodactylus / sone / database / PostDatabase.java
index 1f9a2a8..8fa4000 100644 (file)
 
 package net.pterodactylus.sone.database;
 
-import net.pterodactylus.util.config.Configuration;
-import net.pterodactylus.util.config.ConfigurationException;
+import java.util.Collection;
+import java.util.Set;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.Sone;
+
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
 
 /**
- * Combines a {@link PostProvider}, a {@link PostBuilderFactory}, and a
- * {@link PostStore} into a complete post database.
+ * Database for handling {@link Post}s.
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public interface PostDatabase extends PostProvider, PostBuilderFactory, PostStore {
+public interface PostDatabase {
+
+       Function<String, Optional<Post>> getPost();
+
+       /**
+        * Returns the post with the given ID.
+        *
+        * @param postId
+        *            The ID of the post to return
+        * @return The post with the given ID, or {@code null}
+        */
+       Optional<Post> getPost(String postId);
+
+       /**
+        * Returns all posts from the given Sone.
+        *
+        * @param soneId
+        *            The ID of the Sone
+        * @return All posts from the given Sone
+        */
+       Collection<Post> getPosts(String soneId);
 
-       /*
-        * these methods have to be here until the database knows how to save its
-        * own stuff. all the configuration-specific stuff will have to leave!
+       /**
+        * Returns all posts that have the given Sone as recipient.
+        *
+        * @see Post#getRecipient()
+        * @param recipientId
+        *            The ID of the recipient of the posts
+        * @return All posts that have the given Sone as recipient
+        */
+       Collection<Post> getDirectedPosts(String recipientId);
+
+       /**
+        * Adds the given post to the store.
+        *
+        * @param post
+        *            The post to store
         */
+       void storePost(Post post);
 
        /**
-        * Loads the knows posts.
+        * Removes the given post.
         *
-        * @param configuration
-        *            The configuration to load the known posts from
-        * @param prefix
-        *            The prefix for the configuration keys
+        * @param post
+        *            The post to remove
         */
-       public void loadKnownPosts(Configuration configuration, String prefix);
+       void removePost(Post post);
 
        /**
-        * Saves the knows posts.
+        * Stores the given posts as all posts of a single {@link Sone}. This method
+        * will removed all other posts from the Sone!
         *
-        * @param configuration
-        *            The configuration to save the known posts to
-        * @param prefix
-        *            The prefix for the configuration keys
-        * @throws ConfigurationException
-        *             if a value can not be stored in the configuration
+        * @param sone
+        *            The Sone to store the posts for
+        * @param posts
+        *            The posts to store
+        * @throws IllegalArgumentException
+        *             if posts do not all belong to the same Sone
         */
-       public void saveKnownPosts(Configuration configuration, String prefix) throws ConfigurationException;
+       void storePosts(Sone sone, Collection<Post> posts) throws IllegalArgumentException;
+
+       /**
+        * Removes all posts of the given {@link Sone}
+        *
+        * @param sone
+        *            The Sone to remove all posts for
+        */
+       void removePosts(Sone sone);
+
+       void setPostKnown(Post post);
+       boolean isPostKnown(Post post);
+       void likePost(Post post, Sone localSone);
+       void unlikePost(Post post, Sone localSone);
+       boolean isLiked(Post post, Sone sone);
+       Set<Sone> getLikes(Post post);
 
 }