Skip to content

BA-Group/play-assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Play & ReactiveMongo, assignment

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:

Good IDE's for Scala programming are IntelliJ IDEA and Eclipse's Scala-IDE.

Data model

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.

Run it

./activator run

Contacts

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.

Add some contacts

curl -H "Content-Type: application/json" -X POST -d '{"firstName":"John","lastName":"Doe","email":"john.doe@example.org}' http://localhost:9000/contacts

List contacts

curl  http://localhost:9000/contacts

Update existing contact

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>

Get a specific contact

Use a contact id from the list of contacts fetched with the list service

curl  http://localhost:9000/contacts/<contactId>

Delete a specific contact

Use a contact id from the list of contacts fetched with the list service

curl -X DELETE http://localhost:9000/contacts/<contactId>

Test invalid formats

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages