Skip to content

Instantly share code, notes, and snippets.

@agnaldo4j
Created October 25, 2015 16:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agnaldo4j/aae4f2cb85eaaf057211 to your computer and use it in GitHub Desktop.
Save agnaldo4j/aae4f2cb85eaaf057211 to your computer and use it in GitHub Desktop.
Separação tecnologia da implementação da regra do negócio. Com isso mudar de tecnologia de persistência e framework web fica bem mais fácil
post("/") {
contentType = "application/json"
authenticated { jsonObject =>
val entityManager = entityManagerFactory.createEntityManager()
val userRepository = new UserRepository(entityManager)
val userPersistenceAdapter = new NewUserPersistenceAdapterJPA(userRepository)
val usecase = new NewUserUsecase(userPersistenceAdapter)
val savedUser = usecase.save( User( jsonObject ) )
writeOkResponse( ProtocolResponse.prepare(savedUser.state) )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment