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