HTTP server using Gin-Gonic framework and implementing CRUD operations. It operates on User entity. The whole project is dockerized. It also contains implemetation of seek pagination with sorting and filtering
Attributes:
- name
- surname
- gender
- age
- address
- created_at
name and surname are the user's unique identifier. There can be only one user with given name and surname
GET /v1/users/:user_id- return User entity in JSON formatDELETE /v1/users/:user_id- delete User entityPUT /v1/users/:user_id- update User entity. Request in JSON formatPOST /v1/users- create User entity. Request in JSON formatGET /v1/users- search Users using sorting, filtering and seek pagination
Exmples
GET /v1/users- return up to 30 users sort byidascendingGET /v1/users?limit=100&sort=name:desc- return up to 100 users sort bynamedescendingGET /v1/users?gender=male&limit=100&sort=age:asc- return up to 100 users sort byageascending with gendermaleGET /v1/users?name=sonny&gender=male&limit=100&sort=age:desc- return up to 100 users sort byagedescending with gendermaleand name like%sonny%case insensitiveGET /v1/users?name=sonny&gender=male&limit=100&sort=age:desc&min_age=30- return up to 100 users sort byagedescending with gendermaleand name like%sonny%case insensitive withage>= 30GET /v1/users?name=sonny&gender=male&limit=100&sort=age:asc&max_age=30- return up to 100 users sort byageascending with gendermaleand name like%sonny%case insensitive withage<= 30GET /v1/users?name=sonny&gender=male&limit=100&sort=age:asc&min_age=30&max_age=45- return up to 100 users sort byageascending with gendermaleand name like%sonny%case insensitive withage>= 30 andage<= 45GET /v1/users?limit=100&sort=created_at:desc- return up to 100 users sort bycreated_atdescending
There is also Pagination object in response to know how to query next or previous page
To start unit tests please call command:
make go_test_unit
The unit tests do not have any dependencies
To start integration tests please call command:
make docker_build_image && make application_test
The command:
- builds application docker image
- starts postgres DB in docker container
- starts application itself in docker container
- executes goose migration to preapre DB schema
- inserts test data into postgres
- executes integration tests in docker container
To run service locally please call command:
application_run
Start you browser and enter url:
http://localhost:8080/v1/users
In case of errors there will be returned custom error object in JSON format with custom error code and message.
For example in case of validation error there is returned HTTP code 400 with detailed error code and message Examples:
- {"code":2140004,"message":"
limitcan not be negative"} - {"code":2040001,"message":"
namecan't be empty"} - {"code":2040001,"message":"
afterIDcan not be negative"}
- app - aplication code
- api - definition of response and request objects
- config - application configuration object
- controller - controller layer
- dao - repository layer
- db - db helpers
- httperrors - definition of custom http error object and predefined application errors
- middleware - gin-gonic middleware
- model - database models
- service -service layer
- build - docker and docker-compose files to build, run and test application
- test - integration tests