diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
deleted file mode 100644
index 194ab54..0000000
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ /dev/null
@@ -1,31 +0,0 @@
----
-name: Bug report 🐛
-about: Create a report to help us improve
-title: ''
-labels: ''
-assignees: ''
-
----
-
-**Describe the bug**
-A clear and concise description of what the bug is.
-
-**To Reproduce**
-Steps to reproduce the behavior:
-1. Go to '...'
-2. Click on '....'
-3. Scroll down to '....'
-4. See error
-
-**Expected behavior**
-A clear and concise description of what you expected to happen.
-
-**Screenshots**
-If applicable, add screenshots to help explain your problem.
-
-**Desktop (please complete the following information):**
- - OS: [e.g. Ubuntu 21.04]
- - Docker version: [e.g. Docker version 20.10.12]
-
-**Additional context**
-Add any other context about the problem here.
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
deleted file mode 100644
index 6c1ee26..0000000
--- a/.github/ISSUE_TEMPLATE/config.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-blank_issues_enabled: true
-contact_links:
- - name: Ask a question ❓
- url: https://github.com/Rviewer-Challenges/skeleton-java-spring-rest/discussions/new
- about: Ask a question or request support for using this skeleton
\ No newline at end of file
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
deleted file mode 100644
index be1cb51..0000000
--- a/.github/ISSUE_TEMPLATE/feature_request.md
+++ /dev/null
@@ -1,20 +0,0 @@
----
-name: Feature request ✨
-about: Suggest an idea for this project
-title: ''
-labels: ''
-assignees: ''
-
----
-
-**Is your feature request related to a problem? Please describe.**
-A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
-
-**Describe the solution you'd like**
-A clear and concise description of what you want to happen.
-
-**Describe alternatives you've considered**
-A clear and concise description of any alternative solutions or features you've considered.
-
-**Additional context**
-Add any other context or screenshots about the feature request here.
diff --git a/.github/rviewer_logo--dark.png b/.github/rviewer_logo--dark.png
deleted file mode 100644
index 94f24c0..0000000
Binary files a/.github/rviewer_logo--dark.png and /dev/null differ
diff --git a/.github/workflows/sonarqube-scanner.yaml b/.github/workflows/sonarqube-scanner.yaml
deleted file mode 100644
index 627517b..0000000
--- a/.github/workflows/sonarqube-scanner.yaml
+++ /dev/null
@@ -1,70 +0,0 @@
-on:
- workflow_dispatch:
- push:
- branches:
- - main
- - devel
- pull_request:
- types:
- - opened
- - reopened
- - synchronize
- branches:
- - main
- - devel
-
-jobs:
- secrets-gate:
- runs-on: ubuntu-latest
- outputs:
- ok: ${{ steps.check-secrets.outputs.ok }}
- steps:
- - name: check for secrets needed to run SonarQube
- id: check-secrets
- run: |
- if [ ! -z "${{ secrets.SONAR_TOKEN }}" ] && [ ! -z "${{ secrets.SONAR_HOST_URL }}" ]; then
- echo "::set-output name=ok::true"
- fi
-
- sonarqube:
- needs:
- - secrets-gate
- if: ${{ needs.secrets-gate.outputs.ok == 'true' }}
- runs-on: ubuntu-latest
- services:
- postgres-skeleton-db:
- image: postgres
- env:
- POSTGRES_DB: postgres_rv_database
- POSTGRES_USER: rv_user
- POSTGRES_PASSWORD: rv_password
- options: >-
- --health-cmd pg_isready
- --health-interval 10s
- --health-timeout 5s
- --health-retries 5
- ports:
- - 5432:5432
- steps:
- - uses: actions/checkout@v2
-
- - uses: actions/setup-java@v3
- with:
- distribution: temurin
- java-version: 17
-
- - uses: gradle/gradle-build-action@v2
- with:
- gradle-version: 7.4.2
-
- - name: Gradle execute tests
- run: gradle clean build
-
- - name: SonarQube Scan
- uses: sonarsource/sonarqube-scan-action@master
- with:
- args: >
- -Dsonar.projectKey=${{ github.event.repository.name }}
- env:
- SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
diff --git a/INSTRUCTIONS.md b/INSTRUCTIONS.md
deleted file mode 100644
index ee7fce6..0000000
--- a/INSTRUCTIONS.md
+++ /dev/null
@@ -1,77 +0,0 @@
-
-
-## Rviewer skeleton: Java, Spring & PostgreSQL
-
-[](https://twitter.com/Rviewer_/)
-
-[](https://discord.gg/VVN4ur8FaQ)
-
-
-
-This repository is a Java skeleton with Spring & PostgreSQL designed for quickly getting started developing an API.
-Check the [Getting Started](#getting-started) for full details.
-
-## Technologies
-
-* [Java 18](https://openjdk.java.net/projects/jdk/18/)
-* [Gradle 7](https://docs.gradle.org/7.0/release-notes.html)
-* [Spring boot](https://spring.io/projects/spring-boot)
-* [Lombok](https://projectlombok.org/)
-* [Junit](https://junit.org/junit5/)
-* [JaCoCo](https://docs.gradle.org/current/userguide/jacoco_plugin.html)
-* [Docker](https://www.docker.com/)
-* [Make](https://www.gnu.org/software/make/manual/make.html)
-
-## Getting Started
-
-Within the [Makefile](Makefile) you can handle the entire flow to get everything up & running:
-
-1. Install `make` on your computer, if you do not already have it.
-2. Start the application: `make up`
-3. Run the application tests: `make test`
-
-As you could see on the [Makefile](Makefile) script and the [Docker-Compose File](docker-compose.yml), the whole API
-is containerized with Docker and the API is using the internal DNS to connect with the PostgreSQL instance.
-
-Go to `http://127.0.0.1:8080/ping` to see that everything is up & running!
-
-## Overview
-
-This skeleton is based on
-a [Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) approach, so you
-could find the first basic layers:
-
-> You could find here two amazing articles ([here](https://www.educative.io/blog/clean-architecture-tutorial)
-> and [here](https://www.freecodecamp.org/news/modern-clean-architecture/)) explaining the Clean Architecture with Java!
-> (credits to [@bertilMuth](https://twitter.com/BertilMuth) and [@ryanthelin](https://dev.to/ryanthelin)).
-
-### Infrastructure
-
-Here you will find the different files to interact with the outside. In this folder you there are two different folders:
-
-* `controllers`: Here you will have the classes that handle the REST endpoints and the Request/Response
-* `persistence`: Here it is the persistence layer, which interact with the PostgreSQL database, decoupling the rest of
- the application
-
-You can use this as a starting point to continue with this architecture, or adapt it to your preferences.
-
-### Domain
-
-Any of your domain Entities, or Services, that models your business logic. These classes should be completely isolated
-of any external dependency or framework, but interact with them. This layer should follow the Dependency Inversion
-principle.
-
-## Support
-
-If you are having problems or need anything else, please let us know by
-[raising a new issue](https://github.com/Rviewer-Challenges/skeleton-java-spring-rest/issues/new/choose).
-
-## License
-
-This project is licensed with the [MIT license](LICENSE).
-
----
-
-
- Made with ❤️ by Rviewer -
diff --git a/LICENSE b/LICENSE index 02697ef..77c87e7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Rviewer +Copyright (c) 2022 droideparanoico Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/Makefile b/Makefile index cc3ecb1..788da7f 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,9 @@ down: docker-compose down up: - docker-compose run -d -p "8080:8080" java-skeleton-api gradle clean build bootRun -x test + docker-compose run -d -p "8080:8080" java-cartchain-api gradle clean build bootRun -x test test: - docker-compose run --rm --no-deps -p "8080:8080" java-skeleton-api gradle test + docker-compose run --rm --no-deps -p "8080:8080" java-cartchain-api gradle test coverage: test diff --git a/README.md b/README.md new file mode 100644 index 0000000..b71d227 --- /dev/null +++ b/README.md @@ -0,0 +1,76 @@ +# CartChain + +Proof of concept for an e-commerce API implementing blockchain technology by using a simple private chain (no mining) + +## How it works? + +The aim of this API is to manage a shopping cart of an ecommerce website. So, through it, the client will be +able to request and create, update or delete any item in the current cart. + +Every action of the API will generate a new _Block_ on the _Blockchain_ in order to create a history and persist the +information, so we can retrieve it later, but also keeps a history of which items have the user added to the cart. + +### Workflow + +The workflow of this API is as follows: + +* Create + +1. Create request is received +2. Check if the `id` for a Cart is not already used + 1. If it has been used we return error + 2. If it has not been used, we create the cart with the given item and generates a new Block to add to the + Blockchain +3. Add the new _Block_ to the _Blockchain_ with the current information of this Cart + +* Update + +1. Update request is received +2. Check if the `id` for a Cart exists + 1. If not exists return error + 2. If exist retrieve it +3. Update the items in the cart and generate a new Block with the information +4. Add the new _Block_ to the _Blockchain_ + +* Delete + +1. Delete request is received +2. Check if the `id` for a Cart exists + 1. If not exists return error + 2. If exist retrieve it +3. Remove cart information and create a new _Block_ +4. Add the new _Block_ to the _Blockchain_ + +## Technical Considerations + +### Stack +* [Java 17](https://openjdk.java.net/projects/jdk/17/) +* [Gradle 7](https://docs.gradle.org/7.0/release-notes.html) +* [Spring boot](https://spring.io/projects/spring-boot) +* [Lombok](https://projectlombok.org/) +* [Junit](https://junit.org/junit5/) +* [JaCoCo](https://docs.gradle.org/current/userguide/jacoco_plugin.html) +* [Docker](https://www.docker.com/) +* [Make](https://www.gnu.org/software/make/manual/make.html) + +### Architecture + +This app is implemented using hexagonal architecture (ports & adapters) and DDD approach. + +The architecture helps to have a decoupled code and being easy to modify or extend it. Following diagram hints how this is achieved: + + + +More info at [Hexagonal Architecture](https://alistair.cockburn.us/hexagonal-architecture/) +### Getting Started + +Within the [Makefile](Makefile) you can handle the entire flow to get everything up & running: + +1. Install `make` on your computer, if you do not already have it. +2. Start the application: `make up` +3. Run the application tests: `make test` + +Go to [localhost:8080/swagger-ui/index.html](http://localhost:8080/swagger-ui/index.html) to see the API description. + +As you can see on the [Makefile](Makefile) script and the [docker-Compose File](docker-compose.yml), the whole API +is containerized with docker and the API is using the internal DNS to connect with the PostgreSQL instance. diff --git a/api.spec.yaml b/api.spec.yaml deleted file mode 100644 index 7cb2ece..0000000 --- a/api.spec.yaml +++ /dev/null @@ -1,175 +0,0 @@ -openapi: 3.0.0 -info: - title: Shopping Cart API - description: | - Shopping Cart API is a REST API responsible for manage the shopping car for an e-commerce with a Blockchain storage - system, where the users could create, update and delete their cart. - version: 1.0.0 -paths: - /carts/{id}: - get: - summary: | - This endpoint returns a cart for the given id. - parameters: - - name: id - description: The id of the cart. - required: true - in: path - schema: - type: string - format: uuid - responses: - '200': - description: created - content: - application/json: - schema: - $ref: '#/components/schemas/CreateCartRes' - '404': - description: Cart not found - content: - application/json: - schema: - type: object - properties: - error: - type: string - example: Cart not found for the given ID - post: - summary: | - This endpoint creates a cart for the given id. - parameters: - - name: id - description: The id of the cart. - required: true - in: path - schema: - type: string - format: uuid - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/CreateCartReq' - responses: - '201': - description: created - '409': - description: Already exists - content: - application/json: - schema: - type: object - properties: - error: - type: string - example: Invalid identifier. - '400': - description: Invalid body provided - content: - application/json: - schema: - type: object - properties: - error: - type: string - example: Invalid body provided, check the payload. - patch: - summary: | - This endpoint updates totally or partially a cart for the given id. - parameters: - - name: id - description: The id of the cart. - required: true - in: path - schema: - type: string - format: uuid - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/UpdateCartReq' - responses: - '200': - description: created - '404': - description: Not found - content: - application/json: - schema: - type: object - properties: - error: - type: string - example: Cart not found for the given id - '400': - description: Invalid body provided - content: - application/json: - schema: - type: object - properties: - error: - type: string - example: Invalid body provided, check the payload. - delete: - summary: | - This endpoint deletes a cart for the given id. - parameters: - - name: id - description: The id of the cart. - required: true - in: path - schema: - type: string - format: uuid - responses: - '200': - description: deleted - '404': - description: Cart not found - content: - application/json: - schema: - type: object - properties: - error: - type: string - example: Cart not found for the given ID -components: - schemas: - CartItem: - type: object - properties: - id: - type: string - format: uuid - name: - type: string - quantity: - type: number - price: - type: number - CartItems: - type: array - items: - $ref: '#/components/schemas/CartItem' - CreateCartReq: - type: object - properties: - items: - $ref: '#/components/schemas/CartItems' - UpdateCartReq: - properties: - items: - $ref: '#/components/schemas/CartItems' - CreateCartRes: - type: object - properties: - id: - type: string - format: uuid - items: - $ref: '#/components/schemas/CartItems' - diff --git a/build.gradle b/build.gradle index a4d4fe2..adbfbee 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'jacoco' } -group = 'com.rviewer.skeletons' +group = 'com.cartchain' version = '1.0.0' sourceCompatibility = '17' @@ -25,9 +25,10 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'org.springdoc:springdoc-openapi-ui:1.6.11' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' - testImplementation 'com.h2database:h2:2.1.212' + testImplementation 'com.h2database:h2:2.1.214' runtimeOnly 'org.postgresql:postgresql' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' diff --git a/docker-compose.yml b/docker-compose.yml index 74c98bf..203721a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,37 +1,40 @@ version: '3.9' services: - java-skeleton-api: - container_name: java-skeleton-api - image: gradle:latest # this is due to some Mac M1 issues with Docker :_ - depends_on: - - postgres-skeleton-db - volumes: - - "${PWD}:/home/gradle/project" - - "rv-gradle-cache:/home/gradle/.gradle" - working_dir: "/home/gradle/project" - ports: - - "8080:8080" - networks: - internal-net: + java-cartchain-api: + container_name: java-cartchain-api + image: gradle:latest # this is due to some Mac M1 issues with Docker :_ + depends_on: + - postgres-cartchain-db + volumes: + - "${PWD}:/home/gradle/project" + - "gradle-cache:/home/gradle/.gradle" + working_dir: "/home/gradle/project" + ports: + - "8080:8080" + networks: + internal-net: - postgres-skeleton-db: - container_name: postgres-skeleton-db - image: postgres:13.4-alpine - restart: on-failure - volumes: - - rv-volume:/var/lib/postgresql/data - ports: - - "5432:5432" - env_file: - - postgres.dev.env - networks: - internal-net: + postgres-cartchain-db: + container_name: postgres-cartchain-db + image: postgres:13.4-alpine + restart: on-failure + volumes: + - volume:/var/lib/postgresql/data + ports: + - "5432:5432" + environment: + - POSTGRES_NAME=postgres-cartchain-db + - POSTGRES_DB=postgres_database + - POSTGRES_USER=user + - POSTGRES_PASSWORD=password + networks: + internal-net: volumes: - rv-volume: - rv-gradle-cache: + volume: + gradle-cache: networks: - internal-net: - name: rv-skeleton-net + internal-net: + name: cartchain-net diff --git a/gradlew b/gradlew deleted file mode 100755 index 1b6c787..0000000 --- a/gradlew +++ /dev/null @@ -1,234 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://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. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" -APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index ac1b06f..0000000 --- a/gradlew.bat +++ /dev/null @@ -1,89 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/hexagonal.png b/hexagonal.png new file mode 100644 index 0000000..0c21144 Binary files /dev/null and b/hexagonal.png differ diff --git a/postgres.dev.env b/postgres.dev.env deleted file mode 100644 index 8581d0c..0000000 --- a/postgres.dev.env +++ /dev/null @@ -1,4 +0,0 @@ -POSTGRES_NAME=postgres-skeleton-db -POSTGRES_DB=postgres_rv_database -POSTGRES_USER=rv_user -POSTGRES_PASSWORD=rv_password diff --git a/readme.md b/readme.md deleted file mode 100644 index 8f8814e..0000000 --- a/readme.md +++ /dev/null @@ -1,115 +0,0 @@ -# Cartfidential - -Within the current landscape of digital commerce, there is no such progress and there are still the same problems of -scalability and performance with high traffic than some years ago. For this reason, we have decided to implement a new -type of ecommerce based on the [Blockchain](https://builtin.com/blockchain) technology, creating a decentralized network -to execute and store, in a decentralized way, the different processes of an ecommerce. - -That's why you will be in charge of creating a very important part of it, the shopping cart. - -## How it works? - -The aim of this API is to manage a shopping cart of our ecommerce website. So, through it, the Frontend Team will be -able to request and create, update or delete any item in the current cart. - -Every action of the API will generate a new _Block_ on the _Blockchain_ in order to create a history and persist the -information, so we can retrieve it later, but also keeps a history of which items have the user added to the cart. - -You could find the API description on the OpenAPI description file. - -### Workflow - -The workflow of this API is as follows: - -* Create - -1. Create request is received -2. Check if the `id` for a Cart is not already used - 1. If it has been used we return error - 2. If it has not been used, we create the cart with the given item and generates a new Block to add to the - Blockchain -3. Add the new _Block_ to the _Blockchain_ with the current information of this Cart - -* Update - -1. Update request is received -2. Check if the `id` for a Cart exists - 1. If not exists return error - 2. If exist retrieve it -3. Update the items in the cart and generate a new Block with the information -4. Add the new _Block_ to the _Blockchain_ - -* Delete - -1. Delete request is received -2. Check if the `id` for a Cart exists - 1. If not exists return error - 2. If exist retrieve it -3. Remove cart information and create a new _Block_ -4. Add the new _Block_ to the _Blockchain_ - -## Technical Considerations - -Keep in mind the following: - -1. Related with the Blockchain: - 1. The blockchain have a first block called 'genesis block', these block doesn't contain a reference of the previous - block, usually is hardcoded on the software - 2. Every Block has multiple properties: - 1. timestamp: the timestamp for the moment when the block was created - 2. lastHash: hash of the previous block on the _blockchain_ - 3. data: information we want to store in the block (in our case the votes) - 4. nonce: a unique number - 5. hash: a SHA256 string for the block, calculated concatenating the timestamp, lastHash, data and nonce. - 3. The implementation of the Blockchain must follow these contract: - ``` - Blockchain - /** Adds new block to blockchain */ - addBlock(block: Block): Block - /** The new blockchain that is a candidate for replacing the current blockchain */ - replace(blockchain: Blockchain): boolean - /** - * Validates the chain by checking if: - * - Genesis Block hash match given blockchain genesis block hash - * - every element's last hash value matches previous block's hash - * - data hasn't been tampered (which will produce a different hash value) - */ - isValid(blockchain: Blockchain): boolean - - Block - /** Generate the first block for the chain */ - static getGenesisBlock(): Block - /** Generate the hash for the given block */ - static generateHashFromBlock(block: Block): string - ``` - -## Technical requirements - -* Create a **clean**, **maintainable** and **well-designed** code. We expect to see a good and clear architecture that - allows to add or modify the solution without so much troubles. -* **Test** your code until you are comfortable with it. We don't expect a 100% of Code Coverage but some tests that - helps to have a more stable and confident base code. - -To understand how you take decisions during the implementation, **please write a COMMENTS.md** file explaining some of -the most important parts of the application. You would also be able to defend your code through -[Rviewer](https://rviewer.io), once you submit your solution. - ---- - -## How to submit your solution - -* Push your code to the `devel` branch - we encourage you to commit regularly to show your thinking process was. -* **Create a new Pull Request** to `main` branch & **merge it**. - -Once merged you **won't be able to change or add** anything to your solution, so double-check that everything is as -you expected! - -Remember that **there is no countdown**, so take your time and implement a solution that you are proud! - ---- - -
- If you have any feedback or problem, let us know! 🤘
-
- Made with ❤️ by Rviewer
-