Skip to content
Snippets Groups Projects
Commit 86283739 authored by Felipe D'Abrantes's avatar Felipe D'Abrantes
Browse files

Add parameters to endpoints

parent 8f83f56c
No related branches found
No related tags found
1 merge request!14Add endpoints to manage Dailies
...@@ -35,11 +35,11 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) ...@@ -35,11 +35,11 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
/** /**
* Create an Action to fetch the user's Dailies in the DB. * Create an Action to fetch the user's Dailies in the DB.
*/ */
def getUserDailies() = Action { def getUserDailies(userId: String) = Action {
println("DailyController:getUserDailies") println("DailyController:getUserDailies")
try { 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) val jsonResult: JsValue = Daily.toJson(result)
Ok(jsonResult) Ok(jsonResult)
} catch { } catch {
...@@ -51,11 +51,11 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) ...@@ -51,11 +51,11 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
/** /**
* Create an Action to fetch the user's Feed. * Create an Action to fetch the user's Feed.
*/ */
def getUserFeed() = Action { def getUserFeed(userId: String) = Action {
println("DailyController:getUserFeed") println("DailyController:getUserFeed")
try { 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) val jsonResult: JsValue = Daily.toJson(result)
Ok(jsonResult) Ok(jsonResult)
} catch { } catch {
...@@ -67,12 +67,12 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) ...@@ -67,12 +67,12 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
/** /**
* Create an Action to create a Daily. * Create an Action to create a Daily.
*/ */
def create() = Action { def create(userId: String, questionId: String, content: String) = Action {
println("DailyController:create") println("DailyController:create")
try { try {
// Dummy data // 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) val jsonResult: JsValue = Daily.toJson(result)
Ok(jsonResult) Ok(jsonResult)
} catch { } catch {
...@@ -84,12 +84,12 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) ...@@ -84,12 +84,12 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
/** /**
* Create an Action to like a Daily. * Create an Action to like a Daily.
*/ */
def like() = Action { def like(dailyId: String, likerId: String) = Action {
println("DailyController:like") println("DailyController:like")
try { try {
// Dummy data // Dummy data
Daily.likeAsync(new ObjectId("642314b4b9748f6794e9895b"), new ObjectId("641128f7e80bcd1ba39d04ae")) Daily.likeAsync(new ObjectId(dailyId), new ObjectId(likerId))
Ok("Updated") Ok("Updated")
} catch { } catch {
case _: TimeoutException => BadRequest("Request timed out") case _: TimeoutException => BadRequest("Request timed out")
...@@ -102,12 +102,12 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) ...@@ -102,12 +102,12 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
/** /**
* Create an Action to unlike a Daily. * Create an Action to unlike a Daily.
*/ */
def unlike() = Action { def unlike(dailyId: String, likerId: String) = Action {
println("DailyController:unlike") println("DailyController:unlike")
try { try {
// Dummy data // Dummy data
Daily.unlikeAsync(new ObjectId("642314b4b9748f6794e9895b"), new ObjectId("641128f7e80bcd1ba39d04ae")) Daily.unlikeAsync(new ObjectId(dailyId), new ObjectId(likerId))
Ok("Updated") Ok("Updated")
} catch { } catch {
case _: TimeoutException => BadRequest("Request timed out") case _: TimeoutException => BadRequest("Request timed out")
......
...@@ -11,12 +11,12 @@ GET /assets/*file controllers.Assets.versioned(path="/public", ...@@ -11,12 +11,12 @@ GET /assets/*file controllers.Assets.versioned(path="/public",
GET /daily/getAll controllers.DailyController.getAll() 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment