Skip to content

Latest commit

 

History

History
51 lines (32 loc) · 3.19 KB

QuickstartDevGuide.md

File metadata and controls

51 lines (32 loc) · 3.19 KB

Quickstart Developers Guide

Last Updated: 18.06.2020

How to add a new data:

Prerequsites:

  • Docker installed
  • Firebase service account json file added to ./conf/firebase.json
  • Sbt and Java 11 installed

Description:

  1. Create a new file named V2__NameForThisFile.sql or edit V1__Tables.sql in ./conf/db/migration/* and add PostgreSQL Statements for the new data structure.

  2. Create new Class with Companion Object for the new Model in /app/models/api and extend from ApiBaseModel and implement needed Methods like toJson for the newly created model as shown in the example models.

  3. Start a new Database, migrate with flyway and start slick codegen (See Readme for commands). In intelliJ mark the ./scala-x.xx/src_managed as generated source root through right clicking and mark as source root. mark-as-source

  4. Create a new DAO in ./app/db/* extending from BaseSlickDAO. See the example DAOs for usage.

  5. Bind the newly created DAO to the Trait for Dependency Injection in Module. A new Class Called ***DAOCloseHook has to be created and also bound to close the Database connection on application stop or restart (important for hot reload).

     bind(classOf[MyNewDAO]).to(classOf[SlickMyNewSlickDAO])
     bind(classOf[MyNewDAOCloseHook]).asEagerSingleton()
    
  6. Create a new Repository ./app/de.innfactory.bootstrapplay2.repositories/* for data aggregation and handling.

  7. A new Controller has to be created in ./app/controllers/*.

  8. Bind the route to the Controller Method in routes (/conf/routes).
    The first entry is the HTTP Method (GET, POST, PATCH, DELETE, ...).
    The second entry is the method path excluding the domain. In Path Parameter can be added like shown in the example below with :parameterName and then bound to the Method with the same name and data type. The third entry calls the controller method with controllerpackage.ControllerName.MethodName(id: DataType). Additional Query Parameter can be added by adding more parameters to the Method (Option[Datatype] or Datatype) for optional or required query parameters.

      GET       /v1/test/:id          controllers.TestController.test(id: String)
    
  9. To create Tests add a new ControllerTest to ./test/controllers/*. Test Data can be added to the Database by editing the V999__DATA.sql in ./test/resources/migration/*. Flyway will then automatically migrate the data into the database before each Controller Test. So each controller starts with a freshly cleaned an migrated Database.

  10. Run test with the runForScript. Make sure no Docker database container is running with the port bound to 5432!

      ./.deployment/runFor.sh
    
  11. The test coverage can be found in ./target/scala-x.xx/scoverage-report/. Just open the index.html file in the browser of your choice.