Client-server system representing an ASCII art drawing canvas (programming assignment).
Client-server system representing an ASCII art drawing canvas. It implements:
DETS
based canvas persistence mechanism (no DB needed!)Phenix LiveView
based client (read only)git clone https://github.com/Kociamber/sketch.git
(or unzip the package if you got it from Joanna ;])cd sketch
) and perform required setup with mix setup
mix run
or iex -S mix phx.server
(with interactive console)To access LiveView based client visit localhost:4000
from your browser.
After the setup your local storage is empty - you can quickly create (an assignment test fixture based) canvas you can run the seedfile with mix seed
.
To “clear” your storage run mix clear_storage
or simply delete sketch_storage
file from the project’s root directory.
Browser’s routes:
/ - shows all locally stored canvases
/:id - shows a specific canvas
JSON endpoint requests routes:
post
/canvas
: creates, persists and returns empty canvas, no body params requiredget
/canvas
: returns a list of currently stored canvasesget
/canvas/:id
: returns canvas by id, no body params requiredput
/canvas/:id
: performs flood or rectangle draw operation, returns “updated” canvas (requred body params below)delete
/canvas/:id
- removes canvas and returns deleted structure, no body params requiredBody params required for put
(canvas drawing operation) - drawing rectangle:
{"operation":"rectangle","x":7, "y":10,"width":40,"height":15,"fill_char":"#", "outline_char":"+"}
fill_char
and outline_char
- only one of them must be present)fill_char
and outline_char
can be only strings of length 1Flood operation required params:
{"operation":"flood","x":3, "y":3,"fill_char":"7"}
fill_char
can be only a strings of length 1The server is performing request parameters validation and in case of missing or incorrect values json error message is being returned.
Get a list of all stored canvases:
curl -H "Content-Type: application/json" -X GET http://localhost:4000/api/canvas/
Create new canvas:
curl -H "Content-Type: application/json" -X POST http://localhost:4000/api/canvas/
Get canvas by id:
curl -H "Content-Type: application/json" -X GET http://localhost:4000/api/canvas/:canvas_id
Perform rectangle drawing operation:
curl -H "Content-Type: application/json" -X PUT -d '{"operation":"rectangle","x":1, "y":2,"width":5,"height":5,"fill_char":"#"}' http://localhost:4000/api/canvas/:canvas_id
Perform fill-flood operation:
curl -H "Content-Type: application/json" -X PUT -d '{"operation":"flood","x":3, "y":2,"fill_char":"^"}' http://localhost:4000/api/canvas/:canvas_id
Remove canvas from the storage:
curl -H "Content-Type: application/json" -X DELETE http://localhost:4000/api/canvas/:canvas_id
All operations are returning a canvas of following structure:
{"canvas":{"content":{"0":{"0":"-","1":"-","2":"-","3":"-","4"},...,"id":"ee25fbec-2767-11eb-8a6f-784f436f155b"}}}