From 862837399072181638f59aaf95701f430a36b16f Mon Sep 17 00:00:00 2001
From: Felipe D'Abrantes <felidabrantes@gmail>
Date: Sat, 8 Apr 2023 01:11:15 +0100
Subject: [PATCH] Add parameters to endpoints

---
 .../app/controllers/DailyController.scala     | 20 +++++++++----------
 backend-services/feed-service/conf/routes     | 10 +++++-----
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/backend-services/feed-service/app/controllers/DailyController.scala b/backend-services/feed-service/app/controllers/DailyController.scala
index 8e5d1b2b..4d640bc8 100644
--- a/backend-services/feed-service/app/controllers/DailyController.scala
+++ b/backend-services/feed-service/app/controllers/DailyController.scala
@@ -35,11 +35,11 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
   /**
    * Create an Action to fetch the user's Dailies in the DB.
    */
-  def getUserDailies() = Action {
+  def getUserDailies(userId: String) = Action {
     println("DailyController:getUserDailies")
 
     try {
-        val result: Seq[Daily] = Daily.getUserDailiesAsync(new ObjectId("641128f7e80bcd1ba39d04af"))
+        val result: Seq[Daily] = Daily.getUserDailiesAsync(new ObjectId(userId))
         val jsonResult: JsValue = Daily.toJson(result)
         Ok(jsonResult)
     } catch {
@@ -51,11 +51,11 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
   /**
    * Create an Action to fetch the user's Feed.
    */
-  def getUserFeed() = Action {
+  def getUserFeed(userId: String) = Action {
     println("DailyController:getUserFeed")
 
     try {
-        val result: Seq[Daily] = Daily.getUserFeedAsync(new ObjectId("641128f7e80bcd1ba39d04ae"))
+        val result: Seq[Daily] = Daily.getUserFeedAsync(new ObjectId(userId))
         val jsonResult: JsValue = Daily.toJson(result)
         Ok(jsonResult)
     } catch {
@@ -67,12 +67,12 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
   /**
    * Create an Action to create a Daily.
    */
-  def create() = Action {
+  def create(userId: String, questionId: String, content: String) = Action {
     println("DailyController:create")
 
     try {
         // Dummy data
-        val result: Daily = Daily.createDailyAsync(new ObjectId("641128f7e80bcd1ba39d04ae"), new ObjectId("641128f7e80bcd1ba39d04ae"), "asddas")
+        val result: Daily = Daily.createDailyAsync(new ObjectId(userId), new ObjectId(questionId), content)
         val jsonResult: JsValue = Daily.toJson(result)
         Ok(jsonResult)
     } catch {
@@ -84,12 +84,12 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
   /**
    * Create an Action to like a Daily.
    */
-  def like() = Action {
+  def like(dailyId: String, likerId: String) = Action {
     println("DailyController:like")
 
     try {
         // Dummy data
-        Daily.likeAsync(new ObjectId("642314b4b9748f6794e9895b"), new ObjectId("641128f7e80bcd1ba39d04ae"))
+        Daily.likeAsync(new ObjectId(dailyId), new ObjectId(likerId))
         Ok("Updated")
     } catch {
         case _: TimeoutException => BadRequest("Request timed out")
@@ -102,12 +102,12 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
    /**
    * Create an Action to unlike a Daily.
    */
-  def unlike() = Action {
+  def unlike(dailyId: String, likerId: String) = Action {
     println("DailyController:unlike")
 
     try {
         // Dummy data
-        Daily.unlikeAsync(new ObjectId("642314b4b9748f6794e9895b"), new ObjectId("641128f7e80bcd1ba39d04ae"))
+        Daily.unlikeAsync(new ObjectId(dailyId), new ObjectId(likerId))
         Ok("Updated")
     } catch {
         case _: TimeoutException => BadRequest("Request timed out")
diff --git a/backend-services/feed-service/conf/routes b/backend-services/feed-service/conf/routes
index 90c87567..d826e757 100644
--- a/backend-services/feed-service/conf/routes
+++ b/backend-services/feed-service/conf/routes
@@ -11,12 +11,12 @@ GET     /assets/*file               controllers.Assets.versioned(path="/public",
 
 GET     /daily/getAll      controllers.DailyController.getAll()
 
-GET     /daily/users       controllers.DailyController.getUserDailies()
+GET     /daily/users       controllers.DailyController.getUserDailies(userId: String)
 
-GET     /feed              controllers.DailyController.getUserFeed()
+GET     /feed              controllers.DailyController.getUserFeed(userId: String)
 
-POST     /daily/create      controllers.DailyController.create()
+POST     /daily/create      controllers.DailyController.create(userId: String, questionId: String, content: String)
 
-PUT     /daily/like      controllers.DailyController.like()
+PUT     /daily/like      controllers.DailyController.like(dailyId: String, likerId: String)
 
-PUT     /daily/unlike      controllers.DailyController.unlike()
+PUT     /daily/unlike      controllers.DailyController.unlike(dailyId: String, likerId: String)
-- 
GitLab