The callenge is chat system that has multiple Application identified by token, each Application has many chats identified by a number ( number should start from 1) , each Chat has many messages identified by a number ( number should start from 1)
- the endpoints should be RESTful
- Use MySQL as datastore
- use ElasticSearch for searching through messages of a specific chat
- use Docker to contatinerize the application
- use Sidekiq to create
chats
andmessages
- Personally I used
rufus-scheduler
to create a cron job to update chats_count and messages_count every 30 minutes
- First run
docker-compose build
- Then run
docker-compose up
- Extract classes (Application, Chat, Message)
- Define Relations between classes
- Add (RoR, MySQL, ElasticSearch , Redis , SidekiqWorker , RufusScheduler) images
- Test Docker
-Create Application
Model
-Create Chat
Model
-Create Message
Model
- Initialize
REDIS
inconfig/initalizers
-CreateRedisService
Service inlib
folder
- Add
partial_search
method to search in message bodies for a specific chat
- Create
GenerateApplicationTokenHelper
to create application's token usingsecurerandom
gem
- create
applications
endopoints - create
chats
endopoints - create
messages
endopoints
- create new application
curl -X POST http://localhost:3000/api/v1/applications/ -d '{"name": "application1"}' -H "Content-Type: application/json"
- list applications
curl -X GET http://localhost:3000/api/v1/applications/
- create chat for application1
curl -X POST http://localhost:3000/api/v1/applications/Z6Ytw68GoCeceFRDdZL8zj97/chats
- list chats for application1
curl -X GET http://localhost:3000/api/v1/applications/Z6Ytw68GoCeceFRDdZL8zj97/chats
- create message for chat 1
curl -X POST http://localhost:3000/api/v1/applications/Z6Ytw68GoCeceFRDdZL8zj97/chats/1/messages/ -d '{"body": "hello"}' -H "Content-Type: application/json"
- list all messages for chat 1
curl -X GET http://localhost:3000/api/v1/applications/Z6Ytw68GoCeceFRDdZL8zj97/chats/1/messages/
- partial search in specific chat messages
curl -X GET "http://localhost:3000/api/v1/applications/Z6Ytw68GoCeceFRDdZL8zj97/chats/6/messages/search?query=hel"
- unit testing
- performance testing
- api testing