Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial order service setup #1

Merged
merged 87 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
e17079d
Initial order service setup
legendofa Feb 18, 2024
daf967f
Fixed general compilation errors and mutations
legendofa Feb 19, 2024
c431530
cargo fix
legendofa Feb 19, 2024
c28dd6f
cargo fmt
legendofa Feb 19, 2024
30cae81
Renaming and code comments
legendofa Feb 19, 2024
aa1db0d
Feature complete mutations
legendofa Feb 19, 2024
8a1d4f3
Working validation making use of events and generics
legendofa Feb 19, 2024
74db71b
Removed test artifacts
legendofa Feb 19, 2024
09f2bba
Reactivated authentication
legendofa Feb 19, 2024
c866f81
Removed unused lifetime
legendofa Feb 19, 2024
f0af340
Event URLs to dashes
legendofa Feb 19, 2024
39b3ef7
Adapted event logic, mutations, datatypes and OrderItem creation
legendofa Feb 20, 2024
8da4d28
Reworked core logic of order creation, resolving datatype needed with…
legendofa Feb 21, 2024
87b0f6a
Added TODO
legendofa Feb 21, 2024
8696b27
Added required dependencies for lib: reqwest, which are libssl and pk…
legendofa Feb 21, 2024
e077677
Check validity of order placement using 'PENDING_TIMEOUT'
legendofa Feb 22, 2024
bf851fc
Fixed validations according to adapted OrderItemInput
legendofa Feb 22, 2024
ba57caf
Authenticated order item query
legendofa Feb 22, 2024
f46f865
Calculate order item compensatable amount
legendofa Feb 22, 2024
f123ccf
Adjusted shopping cart query to also query counts, adjusted shipment …
legendofa Feb 26, 2024
bc3e400
Product variant availability query completed
legendofa Feb 26, 2024
d2390a3
Progress in shopping cart query
legendofa Feb 26, 2024
8376f1e
Order item creation: Map order item input to shopping cart ids
legendofa Feb 27, 2024
e6b367d
Order created event to Dapr sidecar
legendofa Feb 27, 2024
a74d183
Set URLs for endpoint invocation
legendofa Feb 27, 2024
a839050
Removed accidential imports
legendofa Feb 27, 2024
c6d2857
Removed deprecated docs
legendofa Feb 27, 2024
237ce76
DTOs for order created event
legendofa Feb 28, 2024
15309e4
Updated ShipmentDTO
legendofa Feb 28, 2024
2ff3dd4
Adapted datatypes and DTOs as requested by other services, user addre…
legendofa Mar 6, 2024
2570a20
Order compensation logic and events triggered on shipment failure
legendofa Mar 6, 2024
42c9ee4
Order compensation check and calculate amount to compensate
legendofa Mar 14, 2024
c3b3498
Batch of structural changes in queries, query structures, foreign typ…
legendofa Mar 16, 2024
c0781f9
Additional order amount and GraphQL client library types
legendofa Mar 16, 2024
5c43727
Completed discounts by coupons GraphQL query and reordering logic
legendofa Mar 16, 2024
379cabe
Requested review changes
legendofa Mar 16, 2024
cacf320
Adapted schema submodule name to prevent conflicts when generating th…
legendofa Mar 16, 2024
7174a58
Checkout with submodules for schema generation
legendofa Mar 16, 2024
284548f
Fixed placement of 'recursive'
legendofa Mar 16, 2024
e17a153
Renamed to 'compensatable_order_amount' for consistency reasons
legendofa Mar 16, 2024
1cd4865
Skipped internal GraphQL fields
legendofa Mar 16, 2024
582ef8e
Unpacking function for unreserved product item counts
legendofa Mar 17, 2024
7e98394
Rewrite order creation logic with HashMaps instead of index based lists
legendofa Mar 18, 2024
48a4a6f
Retrieve missing values for order item creation
legendofa Mar 18, 2024
cfc23a3
Implemented shipment query, unused for now as there i would like to d…
legendofa Mar 18, 2024
fd55578
Initial ideas for how a product variant visibility event should be pr…
legendofa Mar 18, 2024
9b8a823
Requested review changes
legendofa Mar 18, 2024
9641797
Shoppingcart service authentication header forwarding
legendofa Mar 19, 2024
4af6ae8
ctx.data_unchecked::<Database>() -> ctx.data::<Database>()? to propag…
legendofa Mar 19, 2024
4250c2d
Merge branch 'product-and-product-variant-visibility-events' into ord…
legendofa Mar 19, 2024
b8eab2d
Filters product variants based on visibility according to product var…
legendofa Mar 19, 2024
72aed1c
Adapt URLs of GraphQL services and deconstruct large function
legendofa Mar 19, 2024
a419c72
Small code simplification
legendofa Mar 19, 2024
221d5b7
Todo match branch to adapt to schema
legendofa Mar 19, 2024
3d6bd08
Parse from camelCase in deserialization
legendofa Mar 19, 2024
a19f8ac
Product variant event 'retailPrice' instead of 'price'
legendofa Mar 19, 2024
44b1f7d
Address event user id bugfix
legendofa Mar 19, 2024
69d9524
User validation bugfix
legendofa Mar 19, 2024
dd7627c
Representation object for entity queries
legendofa Mar 19, 2024
88db735
Adapted __typename for product variant query
legendofa Mar 19, 2024
d4dd754
Proper error handling for map item retrieval
legendofa Mar 20, 2024
9cbbf52
Documentation
legendofa Mar 20, 2024
6a5b691
Fixed typo + doc improvement
legendofa Mar 20, 2024
4a7e2f6
Tax rate version event insert bugfix
legendofa Mar 20, 2024
2af475b
Product variant event insertion bugfix
legendofa Mar 20, 2024
f61f94b
Product variant event insertion bugfix v2
legendofa Mar 20, 2024
5b52429
Correct BSON conversion
legendofa Mar 20, 2024
de66143
minor fixes
nk-coding Mar 21, 2024
f07013c
Removed unused deps and serialization rename to camelCase of OrderDTO
legendofa Mar 21, 2024
9079341
Merge branch 'order-setup' of github.com:MiSArch/order into order-setup
legendofa Mar 21, 2024
bb57ceb
Shipment and invoice address in OrderDTO and 'cargo fmt'
legendofa Mar 22, 2024
eac4dfd
UUIDs instead of objects
legendofa Mar 22, 2024
144aa2c
Send placed order in event
legendofa Mar 22, 2024
17242d1
DateTime serialization fixes
legendofa Mar 22, 2024
b6595c7
Enum renames to #[serde(rename_all = SCREAMING_SNAKE_CASE)]
legendofa Mar 22, 2024
c3dbecd
Now refuses multiple order placements and fixes Bson serialization fr…
legendofa Mar 22, 2024
a2f2290
Fix OrderItemDTO created at format
legendofa Mar 22, 2024
a5ad1dd
Requested review changes
legendofa Mar 24, 2024
9d0557e
configure schema transformation
nk-coding Mar 27, 2024
4f815e8
Requested review change
legendofa Mar 27, 2024
34a5b8e
Adapted path for inventory schema + schemas_repo update
legendofa Mar 27, 2024
c91fdac
Adapted extension typo
legendofa Mar 27, 2024
946404d
Schemas repo update
legendofa Mar 27, 2024
1c31409
Recursive checkout in publish image workflow
legendofa Mar 27, 2024
a7b4b0d
Requested review changes
legendofa Mar 28, 2024
284a5bc
Remove protoc dependency
legendofa Mar 28, 2024
aad2173
Tax rate version, required graphql skips
legendofa Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dapr/components/pubsub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: pubsub
spec:
type: pubsub.in-memory
version: v1
metadata: []
5 changes: 5 additions & 0 deletions .dapr/dapr-config-minimal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: daprConfig
namespace: default
43 changes: 43 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
{
"name": "Existing Docker Compose (Extend)",

// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
"dockerComposeFile": ["../compose.yaml", "docker-compose.yml"],

// The 'service' property is the name of the service for the container that VS Code should
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
"service": "order",

// The optional 'workspaceFolder' property is the path VS Code should open by default when
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"customizations": {
"vscode": {
"extensions": ["rust-lang.rust-analyzer"]
}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Uncomment the next line if you want start specific services in your Docker Compose config.
// "runServices": [],

// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "cat /etc/os-release",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
}
25 changes: 25 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3.8"
services:
# Update this to the name of the service you want to work with in your docker-compose.yml file
order:
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
# array). The sample below assumes your primary file is in the root of your project.
#
# build:
# context: .
# dockerfile: .devcontainer/Dockerfile

volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- ..:/workspaces:cached

# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
# cap_add:
# - SYS_PTRACE
# security_opt:
# - seccomp:unconfined

# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
54 changes: 54 additions & 0 deletions .github/workflows/publish-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Create and publish a Docker image on Release

on:
push:
branches:
- "main"
tags:
- "v*"
pull_request:
branches:
- "main"

concurrency: ${{ github.workflow }}-${{ github.ref }}

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:

build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Log in to the Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: base-dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
29 changes: 29 additions & 0 deletions .github/workflows/test-update-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test update GraphQL schema on pull request

on:
pull_request:

jobs:
schema:
name: Test update GraphQL schema on pull request
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Install latest stable
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- uses: actions/checkout@v4
with:
repository: "misarch/schemas"
path: "schemas"
- name: Save graphql schemas
run: |
cargo run -- --generate-schema
- uses: misarch/graphql-schema-transform@v1
with:
schema: schemas/order.graphql
target: schemas/order.graphql
31 changes: 31 additions & 0 deletions .github/workflows/update-infrastructure-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Update infrastructure-docker submodule
nk-coding marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
schema:
name: Update infrastructure-docker submodule
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: "misarch/infrastructure-docker"
submodules: true
- name: Update submodule
run: |
cd order
git checkout ${{ github.sha }}
- uses: peter-evans/create-pull-request@v5
with:
commit-message: Update order schema
branch: update/order
token: ${{ secrets.INFRASTRUCTURE_DOCKER_PUSH_SECRET }}
- name: Set to auto merge
run: gh pr merge update/order --auto --merge -R misarch/infrastructure-docker
env:
GH_TOKEN: ${{ secrets.INFRASTRUCTURE_DOCKER_PUSH_SECRET }}
39 changes: 39 additions & 0 deletions .github/workflows/update-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Update GraphQL schema

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
schema:
name: Update GraphQL schema
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Install latest stable
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- uses: actions/checkout@v4
with:
repository: "misarch/schemas"
path: "schemas"
- name: Save graphql schemas
run: |
cargo run -- --generate-schema
- uses: misarch/graphql-schema-transform@v1
with:
schema: schemas/order.graphql
target: schemas/order.graphql
- uses: peter-evans/create-pull-request@v5
with:
path: ./schemas
commit-message: Update order schema
branch: update/order
token: ${{ secrets.SCHEMAS_PUSH_SECRET }}
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "schemas"]
path = schemas_repo
url = [email protected]:MiSArch/schemas.git
26 changes: 26 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "misarch-order"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-graphql = { version = "6.0.11", features = ["bson", "chrono", "uuid", "log"] }
async-graphql-axum = "6.0.11"
tokio = { version = "1.8", features = ["macros", "rt-multi-thread"] }
axum = { version = "0.6.0", features = ["headers", "macros"] }
mongodb = "2.8.0"
serde = "1.0.193"
futures = "0.3.30"
bson = { version = "2.8.1", features = ["chrono"]}
clap = { version = "4.4.13", features = ["derive"] }
uuid = { version = "1.6.1", features = ["v4", "serde"] }
mongodb-cursor-pagination = "0.3.2"
json = "0.12.4"
log = "0.4.20"
simple_logger = "4.3.3"
serde_json = "1.0.113"
graphql_client = "0.13.0"
reqwest = { version = "0.11.24", features = ["json"] }
chrono = { version = "0.4.33", features = ["serde"] }
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Order service for MiSArch

### Quickstart (DevContainer)

1. Open VSCode Development Container
2. `cargo run` starts the GraphQL service + GraphiQL on port `8080`

### Quickstart (Docker Compose)

1. `docker compose -f docker-compose-dev.yaml up --build` in the repository root directory. **IMPORTANT:** MongoDB credentials should be configured for production.

### What it can do

- CRUD orders
- Validates all UUIDs input as strings
- Error prop to GraphQL
29 changes: 29 additions & 0 deletions base-dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Source: https://github.com/LukeMathWalker/cargo-chef

FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /misarch-order

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /misarch-order/recipe.json recipe.json

RUN apt update && apt install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*

# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .

RUN cargo build --release --bin misarch-order

# We do not need the Rust toolchain to run the binary!
FROM debian:bookworm-slim AS runtime

RUN apt update && apt install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*

WORKDIR /misarch-order
COPY --from=builder /misarch-order/target/release/misarch-order /usr/local/bin
ENTRYPOINT ["/usr/local/bin/misarch-order"]
36 changes: 36 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
services:
order:
extends:
file: docker-compose-base.yaml
service: order
build:
context: .
dockerfile: devcontainer-dockerfile
ports:
- 8080:8080
order-db:
extends:
file: docker-compose-base.yaml
service: order-db
order-mongoexpress:
image: mongo-express
ports:
- 8081:8081
depends_on:
- order-db
environment:
ME_CONFIG_MONGODB_URL: mongodb://order-db:27017
order-dapr:
extends:
file: docker-compose-base.yaml
service: order-dapr
volumes:
- "./.dapr/dapr-config-minimal.yaml:/config.yaml"
- "./.dapr/components:/components"
placement:
image: "daprio/dapr"
command: ["./placement", "-port", "50006"]
ports:
- 50006:50006
volumes:
order-db-data:
8 changes: 8 additions & 0 deletions dev-dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM rust:1.75-slim-bookworm

RUN apt update && apt install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/misarch-order

COPY . .
CMD ["cargo", "run"]
5 changes: 5 additions & 0 deletions devcontainer-dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM rust:1.75-slim-bookworm

RUN apt update && apt install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/misarch-order
Loading
Loading