All Projects → gvolpe → Pfps Shopping Cart

gvolpe / Pfps Shopping Cart

Licence: apache-2.0
🛒 The Shopping Cart application developed in the book "Practical FP in Scala: A hands-on approach"

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to Pfps Shopping Cart

Monix
Asynchronous, Reactive Programming for Scala and Scala.js.
Stars: ✭ 1,819 (+594.27%)
Mutual labels:  cats, functional-programming, fp
Sup
Composable, purely functional healthchecks in Scala.
Stars: ✭ 138 (-47.33%)
Mutual labels:  cats, functional-programming, fp
Stm4cats
STM monad for cats-effect
Stars: ✭ 35 (-86.64%)
Mutual labels:  cats, functional-programming, fp
Test State
Scala Test-State.
Stars: ✭ 119 (-54.58%)
Mutual labels:  cats, functional-programming, fp
Cats Stm
An STM implementation for Cats Effect
Stars: ✭ 106 (-59.54%)
Mutual labels:  cats, functional-programming
Canoe
Functional Telegram Bot API for Scala
Stars: ✭ 137 (-47.71%)
Mutual labels:  cats, functional-programming
Meow Mtl
Next Level MTL for Scala
Stars: ✭ 149 (-43.13%)
Mutual labels:  cats, functional-programming
Hammock
Purely functional HTTP client
Stars: ✭ 174 (-33.59%)
Mutual labels:  cats, fp
Nine Cards V2
An Open Source Android Launcher built with Scala on Android
Stars: ✭ 181 (-30.92%)
Mutual labels:  cats, functional-programming
tutorials
🎥 Source code of the examples shown in the video tutorials
Stars: ✭ 18 (-93.13%)
Mutual labels:  cats, fp
Cats Mtl
cats transformer type classes.
Stars: ✭ 238 (-9.16%)
Mutual labels:  cats, functional-programming
pfps-examples
🏮 Standalone examples shown in the book "Practical FP in Scala: A hands-on approach"
Stars: ✭ 167 (-36.26%)
Mutual labels:  cats, fp
Monocle
Optics library for Scala
Stars: ✭ 1,357 (+417.94%)
Mutual labels:  cats, functional-programming
Skunk
A data access library for Scala + Postgres.
Stars: ✭ 1,107 (+322.52%)
Mutual labels:  cats, functional-programming
fs2-ssh
A wrapper around Apache SSHD targeting cats-effect and fs2
Stars: ✭ 36 (-86.26%)
Mutual labels:  cats, fp
Es Cqrs Shopping Cart
A resilient and scalable shopping cart system designed using Event Sourcing (ES) and Command Query Responsibility Segregation (CQRS)
Stars: ✭ 19 (-92.75%)
Mutual labels:  cats, functional-programming
Pratica
🥃 Functional Algebraic Data Types
Stars: ✭ 246 (-6.11%)
Mutual labels:  functional-programming, fp
Cats Infographic
typeclass diagram for cats
Stars: ✭ 403 (+53.82%)
Mutual labels:  cats, fp
Scala Exercises
The easy way to learn Scala.
Stars: ✭ 2,431 (+827.86%)
Mutual labels:  cats, functional-programming
scala-functional-programming-tutorial
Functional Programming in Scala Tutorial
Stars: ✭ 23 (-91.22%)
Mutual labels:  cats, fp

shopping-cart

CI Status MergifyStatus Scala Steward badge Cats friendly

⚠️ IMPORTANT NOTICE If you come here from Practical FP in Scala, go to the master branch. You're now on the second-edition branch, which is the new default, as I'm currently working on the 2nd edition of the book. ⚠️

Components Overview

Here's an overview of the different components that make this application.

components

  • Both Services and Authentication are algebras. The latter are mainly dependencies for some of the services.
  • Programs shows Checkout, the business logic that combines most of the services.
  • Effects show our custom interfaces required implicitly.
  • The lines connecting services to Redis and PostgreSQL show which ones access which storage.
  • The HTTP layer shows the client and the different routes.
  • At the very end, we have both the modules and the entry point to the application.

Authentication Data

For didactic purposes, this 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].