A simple REST API to emulate the creation and manipulation of decks of cards.
This project is structured based on the MVC architectural pattern. All files that are part of the project can be found under the 'src' folder, both the business logic as well as unit tests and a test for the endpoints can be found under this dir.
The models folder contains the following files: suits.go, card.go, cards.go and deck.go. All of these files come with a data structure representing the model itself, as well as helper functions and member functions.
The routes folder contain the routing to our endpoint '/decks', this folder presents a single file, decks.go that is responsible to relate a controller method to its respective endpoint with the goal of registering this route on the server, echo.
Global helpers are kept on the helpers folder on the base of our project. The helpers found on this project are used as facilitators for the creation of errors that are handled by the server API.
The controllers folder handles all of the validations specific to a particular route, being them: parsing query parameters or address parameters, and inserting/retrieving content from the database to a formatted response
Mocks a database using a slice, the slice is a singleton and implements methods such as: insert, find, wipe and peek
Assuming go is already installed on your environment, invoke make vendor
$ make vendor
Unit tests and integration tests can be executed by invoking make tests
$ make tests
To compile the server invoke make build
$ make build
To compile and run the server invoke make run
$ make run
For the Create Deck Route, the cards passed as a query parameter are not sorted, in other words, they keep the order of the cards as sent through the request. e.g.: for /decks?cards=AS,KD,XC the cards will be maintained as is, AS, KD, XC.
For the entire project, 10 of any suit is written as 'X'. e.g.: XS, 10 of spades
The project does not use a relational/non relational database, instead I have decided to use a slice to store my decks. I am aware this is not ACID compliant and assume this will not be a problem for this project.