Objective is to implement a really simple CRUD for a contact database, using Play Framework and MongoDb with ReactiveMongo. A template controller (controllers.ContactController
) is provided. You should implement the function stubs so that the application is able to create, update, read, list and delete contacts. Don't hesitate to ask for an advice if you're seem to be stuck with some problem. The aim is not only to assess your codings skills, but also your problem solving and collaboration skills. And if you don't get everything done in a reasonable amount of time, return what you've made anyways, so we can estimate your effort.
You will need Java JDK 8 installed. Start the sbt-console by running the activator-script found in the project root. From the console run the project with command run
and head to address http://localhost:9000 with your browser.
Help and documentation can be found at:
- Scala
- Play
- MongoDb
Good IDE's for Scala programming are IntelliJ IDEA and Eclipse's Scala-IDE.
The database consists of contact records. A contact has the following form:
{
_id: String, autogenerated,
firstName: String, required,
lastName: String, required,
email: String, required,
phone: String, optional,
city: String, optional
}
Data model should be validated on the input, so that no invalid data ends up in the database. Invalid input should return HTTP status BAD REQUEST
. You can use the "Coast-to-coast"-json approach or create domain objects for validation.
./activator run
Template for Contacts controller is provided. Implement the function stubs so that the
application provides the following REST-services. Also a helper function (collection()
)
to get a reference to the contacts collection in MongoDb is provided. Remember, all the
operations on MongoDb are asynchronous. As an example, the get()
-function is already
implemented. Remember that MongoDb uses ObjectId
-instances as id's by default, so
you should generate the id as string yourself before you insert the object to the database.
curl -H "Content-Type: application/json" -X POST -d '{"firstName":"John","lastName":"Doe","email":"john.doe@example.org}' http://localhost:9000/contacts
curl http://localhost:9000/contacts
Use a contact id from the list of contacts fetched with the list service
curl -H "Content-Type: application/json" -X PUT -d '{"firstName":"John","lastName":"Doe","email":"doe.john@example.org}' http://localhost:9000/contacts/<contactId>
Use a contact id from the list of contacts fetched with the list service
curl http://localhost:9000/contacts/<contactId>
Use a contact id from the list of contacts fetched with the list service
curl -X DELETE http://localhost:9000/contacts/<contactId>
The input doesn't contain all the required fields, so it should return a status BAD REQUEST
.
curl -H "Content-Type: application/json" -X POST -d '[{"firstName": "pepe"}]' http://localhost:9000/contacts