Coder Social home page Coder Social logo

saswata-dutta / pfps-shopping-cart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gvolpe/pfps-shopping-cart

0.0 1.0 0.0 491 KB

:shopping_cart: The Shopping Cart application developed in the book "Practical FP in Scala: A hands-on approach"

Home Page: https://leanpub.com/pfp-scala

License: Apache License 2.0

Scala 99.03% TSQL 0.97%

pfps-shopping-cart's Introduction

shopping-cart

CI Status MergifyStatus Scala Steward badge Cats friendly

Authentication Data

For didactic purposes this information is made available to the readers but in a real application THIS SHOULD NEVER BE MADE PUBLIC.

For Admin users, the following environment variables are needed:

  • SC_JWT_SECRET_KEY
  • SC_JWT_CLAIM
  • SC_ADMIN_USER_TOKEN

For access token (manipulation of the shopping cart):

  • SC_ACCESS_TOKEN_SECRET_KEY

For password encryption:

  • SC_PASSWORD_SALT

See the docker-compose.yml file for more details.

Generate your own auth data

In order to generate a valid JWT token, you need a secret key, which can be any String, and a JWT Claim, which can be any valid JSON. You can then generate a token, as shown below:

val claim = JwtClaim(
  """
    {"uuid": "6290c116-4153-11ea-b77f-2e728ce88125"}
  """
)

val secretKey = JwtSecretKey("any-secret")

val algo = JwtAlgorithm.HS256

val mkToken: IO[JwtToken] =
  jwtEncode[IO](claim, secretKey, algo)

In our case, our claim contains a UUID, which is used to identify the Admin Id. In practice, though, a JWT can be any valid JSON.

Take a look at the TokenGenerator program to learn more.

Tests

To run Unit Tests:

sbt test

To run Integration Tests we need to run both PostgreSQL and Redis:

docker-compose up
sbt it:test
docker-compose down

Build Docker image

sbt docker:publishLocal

Our image should now be built. We can check it by running the following command:

> docker images | grep shopping-cart
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
shopping-cart                 latest              646501a87362        2 seconds ago       138MB

To run our application using our Docker image, run the following command:

cd /app
docker-compose up

Payments Client

The configured test payment client is a fake API that always returns 200 with a Payment Id. Users are encouraged to make modifications, e.g. return 409 with another Payment Id (you can create one here) or any other HTTP status to see how our application handles the different cases.

This fake API can be modified at: https://beeceptor.com/console/payments

HTTP API Resources

If you use the Insomnia REST Client, you can import the shopping cart resources using the insomnia.json file.

LICENSE

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

pfps-shopping-cart's People

Contributors

gvolpe avatar scala-steward avatar mergify[bot] avatar kubukoz avatar jopecko avatar nkgm avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.