From 38fc519d0acb206617196fe0d92ecdcb2fb3888a Mon Sep 17 00:00:00 2001 From: Felipe D'Abrantes <felidabrantes@gmail> Date: Wed, 29 Mar 2023 19:37:15 +0100 Subject: [PATCH] Remove unused code --- .../app/controllers/DailyController.scala | 38 +++++++++---------- .../app/controllers/HomeController.scala | 3 +- .../app/controllers/MongoTestController.scala | 12 +++--- .../feed-service/app/models/Daily.scala | 4 +- .../app/models/MongoDBClient.scala | 5 +-- .../feed-service/app/models/User.scala | 2 +- .../app/repositories/DailyRepository.scala | 3 +- 7 files changed, 29 insertions(+), 38 deletions(-) diff --git a/backend-services/feed-service/app/controllers/DailyController.scala b/backend-services/feed-service/app/controllers/DailyController.scala index a63319a7..3cb1c736 100644 --- a/backend-services/feed-service/app/controllers/DailyController.scala +++ b/backend-services/feed-service/app/controllers/DailyController.scala @@ -1,13 +1,11 @@ package controllers import javax.inject._ -import play.api._ import play.api.mvc._ -import models.{Daily, User} +import models.{Daily} import scala.concurrent.TimeoutException -import scala.concurrent.duration._ import org.bson.types.ObjectId /** @@ -19,7 +17,7 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) /** * Create an Action to fetch all the Dailies in the DB. */ - def getAll() = Action { implicit request: Request[AnyContent] => + def getAll() = Action { println("DailyController:getAll") try { @@ -27,15 +25,15 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) val jsonResult = Daily.toJson(result) Ok(jsonResult) } catch { - case ex: TimeoutException => BadRequest("Request timed out") - case ex: Throwable => BadRequest("Exception raised") + case _: TimeoutException => BadRequest("Request timed out") + case _: Throwable => BadRequest("Exception raised") } } /** * 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") try { @@ -43,15 +41,15 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) val jsonResult = Daily.toJson(result) Ok(jsonResult) } catch { - case ex: TimeoutException => BadRequest("Request timed out") - case ex: Throwable => BadRequest("Exception raised") + case _: TimeoutException => BadRequest("Request timed out") + case _: Throwable => BadRequest("Exception raised") } } /** * Create an Action to fetch the user's Feed. */ - def getUserFeed() = Action { implicit request: Request[AnyContent] => + def getUserFeed() = Action { println("DailyController:getUserFeed") try { @@ -59,35 +57,35 @@ class DailyController @Inject()(val controllerComponents: ControllerComponents) val jsonResult = Daily.toJson(result) Ok(jsonResult) } catch { - case ex: TimeoutException => BadRequest("Request timed out") - case ex: Throwable => BadRequest("Exception raised") + case _: TimeoutException => BadRequest("Request timed out") + case _: Throwable => BadRequest("Exception raised") } } - def create() = Action { implicit request: Request[AnyContent] => + def create() = Action { println("DailyController:create") try { // 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) Ok(jsonResult) } catch { - case ex: TimeoutException => BadRequest("Request timed out") - case ex: Throwable => BadRequest("Exception raised") + case _: TimeoutException => BadRequest("Request timed out") + case _: Throwable => BadRequest("Exception raised") } } - def like() = Action { implicit request: Request[AnyContent] => + def like() = Action { println("DailyController:like") try { // Dummy data - val result = Daily.likeAsync(new ObjectId("642314b4b9748f6794e9895b"), new ObjectId("641128f7e80bcd1ba39d04ae")) + Daily.likeAsync(new ObjectId("642314b4b9748f6794e9895b"), new ObjectId("641128f7e80bcd1ba39d04ae")) Ok("Updated") } catch { - case ex: TimeoutException => BadRequest("Request timed out") - case ex: Throwable => BadRequest("Exception raised") + case _: TimeoutException => BadRequest("Request timed out") + case _: Throwable => BadRequest("Exception raised") } } } diff --git a/backend-services/feed-service/app/controllers/HomeController.scala b/backend-services/feed-service/app/controllers/HomeController.scala index 60a6e853..690b3253 100644 --- a/backend-services/feed-service/app/controllers/HomeController.scala +++ b/backend-services/feed-service/app/controllers/HomeController.scala @@ -1,7 +1,6 @@ package controllers import javax.inject._ -import play.api._ import play.api.mvc._ /** @@ -18,7 +17,7 @@ class HomeController @Inject()(val controllerComponents: ControllerComponents) e * will be called when the application receives a `GET` request with * a path of `/`. */ - def index() = Action { implicit request: Request[AnyContent] => + def index() = Action { Ok("OK") } } diff --git a/backend-services/feed-service/app/controllers/MongoTestController.scala b/backend-services/feed-service/app/controllers/MongoTestController.scala index c086129a..8e827042 100644 --- a/backend-services/feed-service/app/controllers/MongoTestController.scala +++ b/backend-services/feed-service/app/controllers/MongoTestController.scala @@ -1,7 +1,6 @@ package controllers import javax.inject._ -import play.api._ import play.api.mvc._ import models.MongoDBClient @@ -19,13 +18,13 @@ class MongoTestController @Inject()(val controllerComponents: ControllerComponen /** * Create an Action to test the Mongo Client. */ - def index() = Action { implicit request: Request[AnyContent] => + def index() = Action { println("MongoController") - var database_name = "{DATABASE_NAME}" - var collection_name = "{COLLECTION_NAME}" + val database_name = "{DATABASE_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 val result: Future[Seq[Document]] = for { @@ -42,8 +41,7 @@ class MongoTestController @Inject()(val controllerComponents: ControllerComponen val jsonResult: Seq[String] = resultCompleted.map(doc => doc.toJson()) Ok(jsonResult.toString()) } catch { - case e: TimeoutException => - BadRequest("Request timed out") + case _: TimeoutException => BadRequest("Request timed out") } } } diff --git a/backend-services/feed-service/app/models/Daily.scala b/backend-services/feed-service/app/models/Daily.scala index 38c239f3..7617f0d3 100644 --- a/backend-services/feed-service/app/models/Daily.scala +++ b/backend-services/feed-service/app/models/Daily.scala @@ -11,8 +11,7 @@ import java.util.Date import java.time.Instant import java.text.SimpleDateFormat -import play.api.libs.json.Json -import play.api.libs.json.{Json, JsValue, JsString, JsNumber, JsObject, JsArray} +import play.api.libs.json.{Json, JsValue, JsString, JsObject, JsArray} case class Daily( @@ -29,7 +28,6 @@ object Daily { val dailyRepo = new DailyRepository() def createDailyAsync( - id: Option[ObjectId], userId: ObjectId, questionId: ObjectId, content: String, diff --git a/backend-services/feed-service/app/models/MongoDBClient.scala b/backend-services/feed-service/app/models/MongoDBClient.scala index ed6339e9..dd2c719b 100644 --- a/backend-services/feed-service/app/models/MongoDBClient.scala +++ b/backend-services/feed-service/app/models/MongoDBClient.scala @@ -2,14 +2,13 @@ package models 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.bson.conversions.Bson import org.bson.types.ObjectId import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future -import scala.util.{Success, Failure, Try} /** @@ -21,7 +20,7 @@ class MongoDBClient { private val mongoUri = ConfigHelper.getString("mongodb.uri") // 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. diff --git a/backend-services/feed-service/app/models/User.scala b/backend-services/feed-service/app/models/User.scala index dea7c2c2..945285ce 100644 --- a/backend-services/feed-service/app/models/User.scala +++ b/backend-services/feed-service/app/models/User.scala @@ -2,12 +2,12 @@ package models import org.bson.types.ObjectId import scala.concurrent.Future -import scala.concurrent.ExecutionContext.Implicits.global object User { def getUserFriends(userId: ObjectId): Future[Seq[ObjectId]] = { // TODO: Fetch user friends from Friend Service + println("Fetching friends for", userId.toString()) val friends: Seq[ObjectId] = Seq(new ObjectId("641128f7e80bcd1ba39d04af")) Future.successful(friends) } diff --git a/backend-services/feed-service/app/repositories/DailyRepository.scala b/backend-services/feed-service/app/repositories/DailyRepository.scala index cca9fe13..69f118db 100644 --- a/backend-services/feed-service/app/repositories/DailyRepository.scala +++ b/backend-services/feed-service/app/repositories/DailyRepository.scala @@ -116,8 +116,7 @@ class DailyRepository extends MongoDBClient { val updates: Seq[Bson] = Seq(update) val dailyId = daily.id.getOrElse(throw new RuntimeException) - val result = updateOne(dailiesCollection, dailyId, updates) - Future.successful(result) + updateOne(dailiesCollection, dailyId, updates) } } -- GitLab