Skip to content

timrs2998/myretail

Repository files navigation

myretail

License: GPL v3 Build Status

myretail is an implementation of a products API that aggregates price details by ID. It is a Spring Boot microservice backed by a Cassandra database and the RedSky API.

Build and Run

Assuming you installed git, you can clone and enter the project directory:

$ git clone [email protected]:timrs2998/myretail.git
$ cd myretail/

Start Cassandra

The app will fail to run and build without Cassandra. To start Cassandra, run:

# Mac
$ brew install cassandra
$ brew services start cassandra

# docker
$ docker run -p 9042:9042 -t library/cassandra:3.11.0

# docker-compose
$ docker-compose up db

# arch (from AUR)
$ yay -S cassandra
$ systemctl start cassandra

Run the app

Assuming you installed JDK 8 you can build and run the project:

# Build and run jar
$ ./gradlew build
$ java -jar myretail-service/build/libs/myretail-service*.jar

# Or run via bootRun task
$ ./gradlew myretail-service:bootRun

Run with docker

As an alternative to building from source with the JDK, you can use Docker. All builds are tagged and pushed to Docker Hub.

To pull down and run the latest docker image:

$ docker run -p 8080:8080 timrs2998/myretail

Run with docker-compose

Start service:

$ docker-compose build
$ docker-compose up db
# wait for Cassandra to start listening
$ docker-compose up app

Run with Docker Swarm

Similar to Kubernetes, the myretail app can be deployed on Docker Swarm:

# Start swarm mode and deploy stack
$ docker swarm init --advertise-adr 127.0.0.1
$ docker stack deploy --compose-file docker-compose.yml myretail-swarm-demo

# Wait for deployment to finish
$ watch -n 0.5 docker ps
$ watch -n 0.5 docker-compose ps

# Verify service is running
$ curl 127.0.0.1:8080/actuator/health

# Cleanup
$ docker stack rm myretail-swarm-demo
$ docker swarm leave --force

Usage

Once running, the Cassandra database will not have any price information. Any GET request would return either a 404 (if missing in RedSky) or a response without a price.

You can perform PUT requests to add or update price information for any existing product:

ie: PUT http://127.0.0.1:8080/products/13860428 with body:

$ curl 'http://127.0.0.1:8080/products/13860428' \
  -X PUT \
  -H 'Content-Type: application/json' \
  -d '{'\
'  "id": 13860428,'\
'  "name": "The Big Lebowski (Blu-ray)",'\
'  "current_price": {'\
'    "value": 123.42,'\
'    "currency_code": "USD"'\
'  }'\
'}'

or you can perform a GET request to aggregate information from Cassandra and RedSky:

Hosted Instance

Instead of running myretail locally, you can see a live demo. The service is hosted on Google App Engine, has a domain name through Google Domains, and has a certificate through Let's Encrypt.

Visit https://www.myretail.pw/ for the live demo.

Sample queries:

Documentation

API documentation is written using asciidoctor. The integration tests generate documentation snippets and ensure they are always up-to-date.

Some endpoints of interest include:

Testing

There are several unit and integration tests written with Spock in Groovy. Use ./gradlew test to run them locally.

Whenever a change is made to the GitHub project, Travis runs all the tests, builds the code, publishes a docker image, publishes artifacts to bintray, and deploys the latest code to Google Container Engine.

See also

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published