This REST API allows for flexible management of users in waiting queues. It was built on top of Play Scala and MongoDB, and illustrates how this custom Priority Queue implementation can be used in Scala projects.
- Install MongoDB.
- Download Typesafe Activator
- Extract the zip and run the
activator
script from a non-interactive shell - Your browser should open to the Activator UI: http://localhost:8888
Using the Activator UI you can compile the code, run tests, and run the app. You can see the running application at: http://localhost:9000/
You can also use the command line:
$ activator ~run
$ activator ~test
For more information you can visit: https://www.playframework.com/documentation/2.5.x/PlayConsole
GET /user/get
Gets user details
POST /user/delete
Deletes user from DB
POST /user/add
Adds new user to DB
POST /user/update
Updates user
GET /queue/all
Gets queue details
POST /queue/add
Adds new queue to DB
POST /queue/delete
Deletes queue from DB
POST /queue/cleanup
Removes deleted users from queue
GET /queue/getFirst
Gets first user in queue
GET /queue/getAll
Gets all users in queue
POST /queue/popFirst
Pops first user from queue
POST /queue/enqueue
Adds user to queue
POST /queue/dequeue
Removes user from queue
POST /queue/bump
Moves user to the top of the queue
The ReactiveMongo plugin for Play was used as the Scala driver for MongoDB.
The ScalaTest + Play integration library was used for testing the Play application with Scalatest.
Scalastyle was used because it's always good to follow some guidelines.
In this application, pattern matching was usually chosen over map.getOrElse or fold for readability purposes. As a personal preference I often use the first two interchangeably but fold does seem to produce less readable code in most cases. Also see: https://www.reddit.com/r/scala/comments/449td4/fold_or_pattern_matching_with_an_option/
MIT License