in this project I applied the lessons learned from @codelyTv, this project is a simple API with authorization using JWT
sbt flyWayMigrate
β run database migrationsSCALA_ENV=test sbt flyWayMigrate
β run database migrations for testssbt run
β run http4s serversbt test
β test suite
envs:
API_POSTGRES_DATABASE=XXX
API_POSTGRES_USER=XXX
API_POSTGRES_PASS=XXX
API_JWT_SECRET=XXXXXXX
# tests suite envs
API_POSTGRES_TEST_DATABASE=XXX
API_POSTGRES_TEST_USER=XXX
API_POSTGRES_TEST_PASS=XXX
POST /authenticate:
authenticationpayload: (name: String)
GET /tasks:
Returns all tasks.POST /tasks:
creates a taskpayload: (title: String, done: Boolean)
GET /tasks/:id:
returns a taskPUT /tasks/:id
updates a taskpayload: (title: String, done: Boolean)
DELETE /tasks/:id
deletes a task
- http4s - A minimal, idiomatic Scala interface for HTTP
- doobie - Functional JDBC layer for Scala.
- jOOQ - jOOQ is the best way to write SQL in Java
- jwt-scala - JWT support for Scala
src
βββ main
β βββ resources
β β βββ db
β β βββ migration # β Migration files
β β βββ V1__create_tasks_table.sql
β βββ scala
β βββ bounded_contexts # β DDD Bounded contexts
β β βββ authentication
β β β βββ application # β DDD application services (public access)
β β β β βββ AuthenticateUser.scala
β β β β βββ DecodeToken.scala
β β β βββ domain
β β β βββ AuthenticationService.scala
β β βββ share # β DDD share kernel
β β β βββ domain
β β β β βββ UserEntity.scala
β β β βββ infrastructure
β β β βββ DoobieConnection.scala # β DATABASE CONNECTION
β β βββ tasks
β β βββ application # β DDD application services (public access)
β β β βββ CreateTaskApplicationService.scala
β β β βββ DeleteTaskApplicationService.scala
β β β βββ FilterTaskApplicationService.scala
β β β βββ FindTaskApplicationService.scala
β β β βββ UpdateTaskApplicationService.scala
β β βββ domain
β β β βββ TaskEntity.scala
β β β βββ TaskRepositoryContract.scala
β β βββ infrestucture
β β βββ TaskRepository.scala
β βββ conf
β β βββ Settings.scala # β APP CONFIGURATION
β βββ server # β http4s server
β βββ Server.scala
β βββ services
β βββ Services.scala
β βββ authentication
β β βββ AuthenticateService.scala
β β βββ TokenSerializer.scala
β βββ helpers
β β βββ Message.scala
β βββ middleware
β β βββ AuthMiddleware.scala # β api authorization
β βββ tasks
β βββ CreateTaskService.scala
β βββ DeleteTaskService.scala
β βββ GetTaskService.scala
β βββ ListTaskService.scala
β βββ UpdateTaskService.scala