You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@esme.apache.org by rh...@apache.org on 2011/06/06 11:04:31 UTC

svn commit: r1132555 - /esme/branches/api2-1.3/server/src/main/scala/org/apache/esme/api/API2.scala

Author: rhirsch
Date: Mon Jun  6 09:04:30 2011
New Revision: 1132555

URL: http://svn.apache.org/viewvc?rev=1132555&view=rev
Log:
[ESME-228]

Modified:
    esme/branches/api2-1.3/server/src/main/scala/org/apache/esme/api/API2.scala

Modified: esme/branches/api2-1.3/server/src/main/scala/org/apache/esme/api/API2.scala
URL: http://svn.apache.org/viewvc/esme/branches/api2-1.3/server/src/main/scala/org/apache/esme/api/API2.scala?rev=1132555&r1=1132554&r2=1132555&view=diff
==============================================================================
--- esme/branches/api2-1.3/server/src/main/scala/org/apache/esme/api/API2.scala (original)
+++ esme/branches/api2-1.3/server/src/main/scala/org/apache/esme/api/API2.scala Mon Jun  6 09:04:30 2011
@@ -104,6 +104,11 @@ object API2 extends ApiHelper with XmlHe
 
     case Req("api2" :: "tags" :: tag :: "messages" :: Nil, _, GetRequest)
             => () => allTagMsgs(tag)
+           
+    case Req("api2" :: "tags" :: tag :: "followees" ::  Nil, _, PostRequest)  => ()
+            => followTag(Box(List(tag)))
+    case Req("api2" :: "tags" :: tag :: "followees" ::  Nil, _, DeleteRequest) => ()
+            => unfollowTag(Box(List(tag)))  
 
     case Req("api2" :: "user" :: "followees" :: Nil, _, GetRequest) => allFollowees
     case Req("api2" :: "user" :: "followees" :: Nil, _, PostRequest) => addFollowee
@@ -137,6 +142,11 @@ object API2 extends ApiHelper with XmlHe
 
     case Req("api2" :: "conversations" :: conversationId :: Nil, _, GetRequest) => ()
             => getConversation(Box(List(conversationId)))
+    
+    case Req("api2" :: "conversations" :: conversationId :: "followees" ::  Nil, _, PostRequest)  => ()
+            => followConversation(Box(List(conversationId)))
+    case Req("api2" :: "conversations" :: conversationId :: "followees" ::  Nil, _, DeleteRequest) => ()
+            => unfollowConversation(Box(List(conversationId)))       
   }
 
   def allSessions(): LiftResponse = {
@@ -721,6 +731,102 @@ object API2 extends ApiHelper with XmlHe
 
     r
   }
+  
+   def followTag(tagId: Box[String]): LiftResponse = {
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      for (user <- User.currentUser)         
+      yield {
+         val tag = Tag.findAll(By(Tag.name, tagId)).headOption
+         
+         if (!tag.followers.contains(user)) { 
+            tag.followers += user
+            tag.save       
+        } 
+        if(tag.isEmpty)
+          (404,Map(),Empty)
+        else
+          (200,Map(),Empty)
+      }
+
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
+
+    r
+  }
+  
+  def unfollowTag(tagId: Box[String]): LiftResponse = {
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      for (user <- User.currentUser)         
+      yield {
+         val tag = Tag.findAll(By(Tag.name, tagId)).headOption
+         
+         if (!tag.followers.contains(user)) { 
+            tag.followers -= user
+            tag.save       
+        } 
+        if(tag.isEmpty)
+          (404,Map(),Empty)
+        else
+          (200,Map(),Empty)
+      }
+
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
+
+    r
+  }
+  
+  
+  
+  def followConversation(conversationId: Box[String]): LiftResponse = {
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      for (user <- User.currentUser;
+           id <- conversationId.map(toLong))
+      yield {
+      
+        val messages = Message.findMessages(List(id)) 
+        
+        val m = messages.values.toList.head
+         if (!m.followers.contains(user)) { 
+            m.followers += user
+            m.save       
+        } 
+        if(messages.isEmpty)
+          (404,Map(),Empty)
+        else
+          (200,Map(),Empty)
+      }
+
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
+
+    r
+  }
+  
+    def unfollowConversation(conversationId: Box[String]): LiftResponse = {
+    val ret: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      for (user <- User.currentUser;
+           id <- conversationId.map(toLong))
+      yield {
+      
+        val messages = Message.findMessages(List(id)) 
+        
+         val m = messages.values.toList.head
+         if (!m.followers.contains(user)) { 
+            m.followers -= user
+            m.save       
+        } 
+        if(messages.isEmpty)
+          (404,Map(),Empty)
+        else
+          (200,Map(),Empty)
+      }
+
+    val r: Box[Tuple3[Int,Map[String,String],Box[Elem]]] =
+      if(ret.isDefined) ret else Full((403,Map(),Empty))
+
+    r
+  }
 
   def unAuthorized(): LiftResponse = {
     Full((403,Map.empty[String, String],Empty))