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

Remove unused code

parent c726f08e
No related branches found
No related tags found
1 merge request!14Add endpoints to manage Dailies
package controllers package controllers
import javax.inject._ import javax.inject._
import play.api._
import play.api.mvc._ import play.api.mvc._
import models.{Daily, User} import models.{Daily}
import scala.concurrent.TimeoutException import scala.concurrent.TimeoutException
import scala.concurrent.duration._
import org.bson.types.ObjectId import org.bson.types.ObjectId
/** /**
...@@ -19,7 +17,7 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) ...@@ -19,7 +17,7 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
/** /**
* Create an Action to fetch all the Dailies in the DB. * Create an Action to fetch all the Dailies in the DB.
*/ */
def getAll() = Action { implicit request: Request[AnyContent] => def getAll() = Action {
println("DailyController:getAll") println("DailyController:getAll")
try { try {
...@@ -27,15 +25,15 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) ...@@ -27,15 +25,15 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
val jsonResult = Daily.toJson(result) val jsonResult = Daily.toJson(result)
Ok(jsonResult) Ok(jsonResult)
} catch { } catch {
case ex: TimeoutException => BadRequest("Request timed out") case _: TimeoutException => BadRequest("Request timed out")
case ex: Throwable => BadRequest("Exception raised") case _: Throwable => BadRequest("Exception raised")
} }
} }
/** /**
* 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 { implicit request: Request[AnyContent] => def getUserDailies() = Action {
println("DailyController:getUserDailies") println("DailyController:getUserDailies")
try { try {
...@@ -43,15 +41,15 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) ...@@ -43,15 +41,15 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
val jsonResult = Daily.toJson(result) val jsonResult = Daily.toJson(result)
Ok(jsonResult) Ok(jsonResult)
} catch { } catch {
case ex: TimeoutException => BadRequest("Request timed out") case _: TimeoutException => BadRequest("Request timed out")
case ex: Throwable => BadRequest("Exception raised") case _: Throwable => BadRequest("Exception raised")
} }
} }
/** /**
* Create an Action to fetch the user's Feed. * Create an Action to fetch the user's Feed.
*/ */
def getUserFeed() = Action { implicit request: Request[AnyContent] => def getUserFeed() = Action {
println("DailyController:getUserFeed") println("DailyController:getUserFeed")
try { try {
...@@ -59,35 +57,35 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) ...@@ -59,35 +57,35 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents)
val jsonResult = Daily.toJson(result) val jsonResult = Daily.toJson(result)
Ok(jsonResult) Ok(jsonResult)
} catch { } catch {
case ex: TimeoutException => BadRequest("Request timed out") case _: TimeoutException => BadRequest("Request timed out")
case ex: Throwable => BadRequest("Exception raised") case _: Throwable => BadRequest("Exception raised")
} }
} }
def create() = Action { implicit request: Request[AnyContent] => def create() = Action {
println("DailyController:create") println("DailyController:create")
try { try {
// Dummy data // Dummy data
val result = Daily.createDailyAsync(None, new ObjectId("641128f7e80bcd1ba39d04ae"), new ObjectId("641128f7e80bcd1ba39d04ae"), "asddas") val result = Daily.createDailyAsync(new ObjectId("641128f7e80bcd1ba39d04ae"), new ObjectId("641128f7e80bcd1ba39d04ae"), "asddas")
val jsonResult = Daily.toJson(result) val jsonResult = Daily.toJson(result)
Ok(jsonResult) Ok(jsonResult)
} catch { } catch {
case ex: TimeoutException => BadRequest("Request timed out") case _: TimeoutException => BadRequest("Request timed out")
case ex: Throwable => BadRequest("Exception raised") case _: Throwable => BadRequest("Exception raised")
} }
} }
def like() = Action { implicit request: Request[AnyContent] => def like() = Action {
println("DailyController:like") println("DailyController:like")
try { try {
// Dummy data // Dummy data
val result = Daily.likeAsync(new ObjectId("642314b4b9748f6794e9895b"), new ObjectId("641128f7e80bcd1ba39d04ae")) Daily.likeAsync(new ObjectId("642314b4b9748f6794e9895b"), new ObjectId("641128f7e80bcd1ba39d04ae"))
Ok("Updated") Ok("Updated")
} catch { } catch {
case ex: TimeoutException => BadRequest("Request timed out") case _: TimeoutException => BadRequest("Request timed out")
case ex: Throwable => BadRequest("Exception raised") case _: Throwable => BadRequest("Exception raised")
} }
} }
} }
package controllers package controllers
import javax.inject._ import javax.inject._
import play.api._
import play.api.mvc._ import play.api.mvc._
/** /**
...@@ -18,7 +17,7 @@ class HomeController @Inject()(val controllerComponents: ControllerComponents) e ...@@ -18,7 +17,7 @@ class HomeController @Inject()(val controllerComponents: ControllerComponents) e
* will be called when the application receives a `GET` request with * will be called when the application receives a `GET` request with
* a path of `/`. * a path of `/`.
*/ */
def index() = Action { implicit request: Request[AnyContent] => def index() = Action {
Ok("OK") Ok("OK")
} }
} }
package controllers package controllers
import javax.inject._ import javax.inject._
import play.api._
import play.api.mvc._ import play.api.mvc._
import models.MongoDBClient import models.MongoDBClient
...@@ -19,13 +18,13 @@ class MongoTestController @Inject()(val controllerComponents: ControllerComponen ...@@ -19,13 +18,13 @@ class MongoTestController @Inject()(val controllerComponents: ControllerComponen
/** /**
* Create an Action to test the Mongo Client. * Create an Action to test the Mongo Client.
*/ */
def index() = Action { implicit request: Request[AnyContent] => def index() = Action {
println("MongoController") println("MongoController")
var database_name = "{DATABASE_NAME}" val database_name = "{DATABASE_NAME}"
var collection_name = "{COLLECTION_NAME}" val collection_name = "{COLLECTION_NAME}"
var mongo = new MongoDBClient() val mongo = new MongoDBClient()
// Sequentially waits for Future objects to complete before calling next method // Sequentially waits for Future objects to complete before calling next method
val result: Future[Seq[Document]] = for { val result: Future[Seq[Document]] = for {
...@@ -42,8 +41,7 @@ class MongoTestController @Inject()(val controllerComponents: ControllerComponen ...@@ -42,8 +41,7 @@ class MongoTestController @Inject()(val controllerComponents: ControllerComponen
val jsonResult: Seq[String] = resultCompleted.map(doc => doc.toJson()) val jsonResult: Seq[String] = resultCompleted.map(doc => doc.toJson())
Ok(jsonResult.toString()) Ok(jsonResult.toString())
} catch { } catch {
case e: TimeoutException => case _: TimeoutException => BadRequest("Request timed out")
BadRequest("Request timed out")
} }
} }
} }
...@@ -11,8 +11,7 @@ import java.util.Date ...@@ -11,8 +11,7 @@ import java.util.Date
import java.time.Instant import java.time.Instant
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import play.api.libs.json.Json import play.api.libs.json.{Json, JsValue, JsString, JsObject, JsArray}
import play.api.libs.json.{Json, JsValue, JsString, JsNumber, JsObject, JsArray}
case class Daily( case class Daily(
...@@ -29,7 +28,6 @@ object Daily { ...@@ -29,7 +28,6 @@ object Daily {
val dailyRepo = new DailyRepository() val dailyRepo = new DailyRepository()
def createDailyAsync( def createDailyAsync(
id: Option[ObjectId],
userId: ObjectId, userId: ObjectId,
questionId: ObjectId, questionId: ObjectId,
content: String, content: String,
......
...@@ -2,14 +2,13 @@ package models ...@@ -2,14 +2,13 @@ package models
import utils.ConfigHelper import utils.ConfigHelper
import org.mongodb.scala.{MongoClient, MongoDatabase, MongoCollection, Document, FindObservable, Observer, Observable} import org.mongodb.scala.{MongoClient, MongoDatabase, MongoCollection, Document}
import org.mongodb.scala.model.{Filters, Projections, Sorts} import org.mongodb.scala.model.{Filters, Projections, Sorts}
import org.bson.conversions.Bson import org.bson.conversions.Bson
import org.bson.types.ObjectId import org.bson.types.ObjectId
import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future import scala.concurrent.Future
import scala.util.{Success, Failure, Try}
/** /**
...@@ -21,7 +20,7 @@ class MongoDBClient { ...@@ -21,7 +20,7 @@ class MongoDBClient {
private val mongoUri = ConfigHelper.getString("mongodb.uri") private val mongoUri = ConfigHelper.getString("mongodb.uri")
// Connects to a MongoDB Client when class is constructed // Connects to a MongoDB Client when class is constructed
private var client: MongoClient = this.connect() private val client: MongoClient = this.connect()
/** /**
* Connects to a MongoDB database using the default MongoDB connection string. * Connects to a MongoDB database using the default MongoDB connection string.
......
...@@ -2,12 +2,12 @@ package models ...@@ -2,12 +2,12 @@ package models
import org.bson.types.ObjectId import org.bson.types.ObjectId
import scala.concurrent.Future import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
object User { object User {
def getUserFriends(userId: ObjectId): Future[Seq[ObjectId]] = { def getUserFriends(userId: ObjectId): Future[Seq[ObjectId]] = {
// TODO: Fetch user friends from Friend Service // TODO: Fetch user friends from Friend Service
println("Fetching friends for", userId.toString())
val friends: Seq[ObjectId] = Seq(new ObjectId("641128f7e80bcd1ba39d04af")) val friends: Seq[ObjectId] = Seq(new ObjectId("641128f7e80bcd1ba39d04af"))
Future.successful(friends) Future.successful(friends)
} }
......
...@@ -116,8 +116,7 @@ class DailyRepository extends MongoDBClient { ...@@ -116,8 +116,7 @@ class DailyRepository extends MongoDBClient {
val updates: Seq[Bson] = Seq(update) val updates: Seq[Bson] = Seq(update)
val dailyId = daily.id.getOrElse(throw new RuntimeException) val dailyId = daily.id.getOrElse(throw new RuntimeException)
val result = updateOne(dailiesCollection, dailyId, updates) updateOne(dailiesCollection, dailyId, updates)
Future.successful(result)
} }
} }
......
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