Last active
July 5, 2018 17:40
-
-
Save benshaw/0856ee70218caf05a55473905e54eac4 to your computer and use it in GitHub Desktop.
Refactor V2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Routes -> GET /v1/reports/:reportId v1.ProductController.List(reportId:Long) | |
class ProductsController() extends Controller | |
def list(@ApiParam(value = "Id of the Report", required = true) id: Report.Id) | |
= Action.async { | |
MapResponse(DAO.run(reports.filter(id == id))) | |
} | |
} | |
class Controller @Inject()(protected implicit val dbConfigProvider: DatabaseConfigProvider, | |
cc: ControllerComponents) extends AbstractController(cc) with play.api.i18n.I18nSupport { | |
class DAO(protected val dbConfigProvider: DatabaseConfigProvider)(implicit executionContext: ExecutionContext) | |
extends HasDatabaseConfigProvider[MyPostgresProfile] { | |
implicit val Reports = TableQuery[ReportsTable] | |
def run[R](action: DbAction[R]): Future[R] = db.run(action.query()) | |
} | |
val dao = new DAO(dbConfigProvider) | |
val logger: Logger = Logger(this.getClass) | |
implicit val ec: ExecutionContext = defaultExecutionContext | |
def MapResponse(response: Reponse) = Action.async { | |
response.map(f => Ok(Json.toJson(f))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment