Skip to content

akarpz/template-service

Repository files navigation

template-service

This is a RESTFUL web service used to track users and their rewards points. It was designed to be easy to understand and modular enough to use as a starting point for new projects.

It has several useful endpoints:

Creating a User

The endpoint /api/v1/users allows for the creation of new users.

It requires a first name, last name, and email address, included as the request body.

Example call to create a user: curl -X POST "http://localhost:8080/api/v1/users" -H "accept: */*" -H "Content-Type: application/json" -d "{ \"emailAddress\": \"[email protected]\", \"firstName\": \"Wombat\", \"lastName\": \"Gumbo\"}"

Creating a Transfer

A transfer is a change to the amount of points a user has. One can be generated by calling /api/v1/transfers with a userId, action (ADD or REMOVE), and amount.

Example call to create a transfer: curl -X POST "http://localhost:8080/api/v1/transfers" -H "accept: */*" -H "Content-Type: application/json" -d "{ \"action\": \"ADD\", \"amount\": 4, \"userId\": 2}"

NOTE: Transactions can only be created for users that exist, and REMOVE transactions cannot be created for users that will leave them with negative points.

Listing Transfers for a User

Transfers for a User's ID can be retrieved at the /api/v1/transfers/list/{userId}

Example call: curl -X GET "http://localhost:8080/api/v1/transfers/1" -H "accept: */*"

Local Development

template-service utilizes docker-compose to bring up the service container and the database container in parallel. Because of the docker network, it is necessary for the spring.datasource.url property in src/main/resource/application.properties to reference the docker bridge IP on the docker host.

Simply run: docker-compose up in the root of the project (you must have docker installed)

It is also possible to run the service locally outside of a container with gradle:

* Change the datasource URL to localhost, ex: spring.datasource.url=jdbc:postgresql://localhost:6432/service
* Run the database container by running the build-and-start.sh script in /database
* Run the service with './gradlew bootRun' in the root project directory

Testing

This project includes unit and functional tests that will be automatically run as part of a gradle build (./gradlew build in the root directory)

Swagger Docs

Swagger documentation of the available endpoints and domain models is automatically generated with spring fox.

It is available at localhost:8080

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published