Code Monkey home page Code Monkey logo

user-management-lagom's Introduction

user-management-lagom

Basic implementation of a user management service using :

  • Lagom 1.4.11
  • Scala 2.12.6
  • JBcrypt
  • Cassandra
  • Kafka

Get started

git clone https://github.com/botekchristophe/user-management-lagom.git
cd user-management-lagom
sbt runAll
curl -X POST http://localhost:9000/api/users \
  -d '{
	"username":"foo",
	"email": "[email protected]",
	"password": "barbarbar"
  }'

User service

API

  def descriptor: Descriptor = {
    import Service._
    named("user").withCalls(
      restCall(Method.GET,    "/api/users",              getUsers _),
      restCall(Method.POST,   "/api/users",              createUser _),
      restCall(Method.GET,    "/api/users/:id",          getUser _),
      restCall(Method.DELETE, "/api/users/:id",          deleteUser _),
      restCall(Method.PUT,    "/api/users/:id/verify",   verifyUser _),
      restCall(Method.PUT,    "/api/users/:id/unverify", unVerifyUser _),
      restCall(Method.POST,   "/api/users/auth",         getUserAuth _),
      restCall(Method.POST,   "/api/users/auth/grant",   userLogin _),
      restCall(Method.POST,   "/api/users/auth/revoke",  revokeToken _),
      restCall(Method.POST,   "/api/users/auth/refresh", refreshToken _)
    )
  }

Persistence entity

Image of User FSM

ReadSide - Cassandra

In order to demonstrate Cassandra Readside with Lagom, two tables are being updated by processing the event stream.

users table

id username status email
$UUID john VERIFIED $email
$UUID Maddie UNVERIFIED $email

sessions table

access_token refresh_token userid
$UUID $UUID $UUID
$UUID $UUID $UUID

Model evolution

An example of model evolution can be found in UserEntity

object UserSerializerRegistry extends JsonSerializerRegistry {
  override def serializers = ...

  private val emailAdded = new JsonMigration(2) {
    override def transform(fromVersion: Int, json: JsObject): JsObject = {
      if (fromVersion < 2) {
        json + ("email" -> JsString("[email protected]"))
      } else {
        json
      }
    }
  }

  override def migrations = Map[String, JsonMigration](
    classOf[CreateUser].getName -> emailAdded,
    classOf[UserCreated].getName -> emailAdded,
    classOf[UserAggregate].getName -> emailAdded
  )
}

Email service

API

trait EmailService extends Service {
  def getEmails: ServiceCall[NotUsed, List[EmailResponse]]

  def emailEvents: Topic[EmailKafkaEvent]

  def descriptor: Descriptor = {
    import Service._
    named("email").withCalls(
      restCall(Method.GET, "/api/emails", getEmails _)
    )
      .withAutoAcl(true)
      .withExceptionSerializer(new DefaultExceptionSerializer(Environment.simple(mode = Mode.Prod)))
      .withTopics(topic("EmailEvents", emailEvents))
  }
}

Persistence entity

Image of Email FSM

ReadSide - Cassandra

In order to retrieve the history of emails processed.

email table

id recipient topic content status date
uuid [email protected] Welcome Hello user DELIVERED timestamp

Further work - unit testing with Lagom test kit

user-management-lagom's People

Contributors

botekchristophe avatar grmontpetit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.