Skip to content

Instantly share code, notes, and snippets.

@benshaw
Last active July 5, 2018 17:40
Show Gist options
  • Save benshaw/0856ee70218caf05a55473905e54eac4 to your computer and use it in GitHub Desktop.
Save benshaw/0856ee70218caf05a55473905e54eac4 to your computer and use it in GitHub Desktop.
Refactor V2
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