This commit is contained in:
2025-02-10 14:15:27 +03:00
parent c408934efd
commit 5a8daa3feb
14 changed files with 1552 additions and 3 deletions

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.baobab.generator
import freeflowuniverse.herolib.baobab.specification
import freeflowuniverse.herolib.schemas.openapi
import os
const example_dir = os.dir(@FILE)
const openapi_spec_path = os.join_path(example_dir, 'openapi.json')
// the actor specification obtained from the OpenRPC Specification
openapi_spec := openapi.new(path: openapi_spec_path)!
actor_spec := specification.from_openapi(openapi_spec)!
println(actor_spec)
actor_module := generator.generate_actor_module(
actor_spec,
interfaces: [.openapi, .http]
)!
actor_module.write(example_dir,
format: false
overwrite: true
compile: false
)!
// os.execvp('bash', ['${example_dir}/meeting_scheduler_actor/scripts/run.sh'])!

View File

@@ -0,0 +1,81 @@
module geomind_poc
pub struct Merchant {
pub:
id string
name string
description string
contact string
active bool
}
pub struct ProductComponentTemplate {
pub:
id string
name string
description string
// technical specifications
specs map[string]string
// price per unit
price f64
// currency code (e.g., 'USD', 'EUR')
currency string
}
pub struct ProductTemplate {
pub:
id string
name string
description string
// components that make up this product template
components []ProductComponentTemplate
// merchant who created this template
merchant_id string
// category of the product (e.g., 'electronics', 'clothing')
category string
// whether this template is available for use
active bool
}
pub struct Product {
pub:
id string
template_id string
// specific instance details that may differ from template
name string
description string
// actual price of this product instance
price f64
currency string
// merchant selling this product
merchant_id string
// current stock level
stock_quantity int
// whether this product is available for purchase
available bool
}
pub struct OrderItem {
pub:
product_id string
quantity int
price f64
currency string
}
pub struct Order {
pub:
id string
// customer identifier
customer_id string
// items in the order
items []OrderItem
// total order amount
total_amount f64
currency string
// order status (e.g., 'pending', 'confirmed', 'shipped', 'delivered')
status string
// timestamps
created_at string
updated_at string
}

View File

@@ -0,0 +1,996 @@
{
"openapi": "3.0.1",
"info": {
"title": "Commerce API",
"description": "API for e-commerce operations including merchants, products, and orders",
"version": "1.0.0"
},
"servers": [
{
"url": "http://localhost:8080",
"description": "Local development server"
}
],
"components": {
"schemas": {
"Merchant": {
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid",
"example": "123e4567-e89b-12d3-a456-426614174000"
},
"name": {
"type": "string",
"example": "Tech Gadgets Store"
},
"description": {
"type": "string",
"example": "Premium electronics and gadgets retailer"
},
"contact": {
"type": "string",
"example": "contact@techgadgets.com"
},
"active": {
"type": "boolean",
"example": true
}
},
"required": [
"id",
"name",
"contact",
"active"
]
},
"ProductComponentTemplate": {
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid",
"example": "123e4567-e89b-12d3-a456-426614174001"
},
"name": {
"type": "string",
"example": "4K Display Panel"
},
"description": {
"type": "string",
"example": "55-inch 4K UHD Display Panel"
},
"specs": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"example": {
"resolution": "3840x2160",
"refreshRate": "120Hz",
"panel_type": "OLED"
}
},
"price": {
"type": "number",
"format": "double",
"example": 599.99
},
"currency": {
"type": "string",
"pattern": "^[A-Z]{3}$",
"example": "USD"
}
},
"required": [
"id",
"name",
"price",
"currency"
]
},
"ProductTemplate": {
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid",
"example": "123e4567-e89b-12d3-a456-426614174002"
},
"name": {
"type": "string",
"example": "Smart TV 55-inch"
},
"description": {
"type": "string",
"example": "55-inch Smart TV with 4K Display"
},
"components": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ProductComponentTemplate"
},
"example": [
{
"id": "123e4567-e89b-12d3-a456-426614174001",
"name": "4K Display Panel",
"description": "55-inch 4K UHD Display Panel",
"specs": {
"resolution": "3840x2160",
"refreshRate": "120Hz"
},
"price": 599.99,
"currency": "USD"
}
]
},
"merchant_id": {
"type": "string",
"format": "uuid",
"example": "123e4567-e89b-12d3-a456-426614174000"
},
"category": {
"type": "string",
"example": "Electronics"
},
"active": {
"type": "boolean",
"example": true
}
},
"required": [
"id",
"name",
"components",
"merchant_id",
"active"
]
},
"Product": {
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid",
"example": "123e4567-e89b-12d3-a456-426614174003"
},
"template_id": {
"type": "string",
"format": "uuid",
"example": "123e4567-e89b-12d3-a456-426614174002"
},
"name": {
"type": "string",
"example": "Smart TV 55-inch"
},
"description": {
"type": "string",
"example": "55-inch Smart TV with 4K Display"
},
"price": {
"type": "number",
"format": "double",
"example": 899.99
},
"currency": {
"type": "string",
"pattern": "^[A-Z]{3}$",
"example": "USD"
},
"merchant_id": {
"type": "string",
"format": "uuid",
"example": "123e4567-e89b-12d3-a456-426614174000"
},
"stock_quantity": {
"type": "integer",
"minimum": 0,
"example": 50
},
"available": {
"type": "boolean",
"example": true
}
},
"required": [
"id",
"template_id",
"name",
"price",
"currency",
"merchant_id",
"stock_quantity",
"available"
]
},
"OrderItem": {
"type": "object",
"properties": {
"product_id": {
"type": "string",
"format": "uuid",
"example": "123e4567-e89b-12d3-a456-426614174003"
},
"quantity": {
"type": "integer",
"minimum": 1,
"example": 2
},
"price": {
"type": "number",
"format": "double",
"example": 899.99
},
"currency": {
"type": "string",
"pattern": "^[A-Z]{3}$",
"example": "USD"
}
},
"required": [
"product_id",
"quantity",
"price",
"currency"
]
},
"Order": {
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid",
"example": "123e4567-e89b-12d3-a456-426614174004"
},
"customer_id": {
"type": "string",
"format": "uuid",
"example": "123e4567-e89b-12d3-a456-426614174005"
},
"items": {
"type": "array",
"items": {
"$ref": "#/components/schemas/OrderItem"
},
"example": [
{
"product_id": "123e4567-e89b-12d3-a456-426614174003",
"quantity": 2,
"price": 899.99,
"currency": "USD"
}
]
},
"total_amount": {
"type": "number",
"format": "double",
"example": 1799.98
},
"currency": {
"type": "string",
"pattern": "^[A-Z]{3}$",
"example": "USD"
},
"status": {
"type": "string",
"enum": [
"pending",
"confirmed",
"shipped",
"delivered"
],
"example": "pending"
},
"created_at": {
"type": "string",
"format": "date-time",
"example": "2024-02-10T10:30:00Z"
},
"updated_at": {
"type": "string",
"format": "date-time",
"example": "2024-02-10T10:30:00Z"
}
},
"required": [
"id",
"customer_id",
"items",
"total_amount",
"currency",
"status",
"created_at",
"updated_at"
]
},
"Error": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 404
},
"message": {
"type": "string",
"example": "Resource not found"
}
},
"required": [
"code",
"message"
]
}
}
},
"paths": {
"/merchants": {
"post": {
"summary": "Create a new merchant",
"operationId": "createMerchant",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string",
"example": "Tech Gadgets Store"
},
"description": {
"type": "string",
"example": "Premium electronics and gadgets retailer"
},
"contact": {
"type": "string",
"example": "contact@techgadgets.com"
}
},
"required": [
"name",
"contact"
]
},
"examples": {
"newMerchant": {
"summary": "Create a new electronics store",
"value": {
"name": "Tech Gadgets Store",
"description": "Premium electronics and gadgets retailer",
"contact": "contact@techgadgets.com"
}
}
}
}
}
},
"responses": {
"201": {
"description": "Merchant created successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Merchant"
},
"example": {
"id": "123e4567-e89b-12d3-a456-426614174000",
"name": "Tech Gadgets Store",
"description": "Premium electronics and gadgets retailer",
"contact": "contact@techgadgets.com",
"active": true
}
}
}
},
"400": {
"description": "Invalid input",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
},
"example": {
"code": 400,
"message": "Invalid merchant data provided"
}
}
}
}
}
}
},
"/products/templates/components": {
"post": {
"summary": "Create a new product component template",
"operationId": "createProductComponentTemplate",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"specs": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"price": {
"type": "number"
},
"currency": {
"type": "string"
}
},
"required": [
"name",
"price",
"currency"
]
},
"examples": {
"displayPanel": {
"summary": "Create a display panel component",
"value": {
"name": "4K Display Panel",
"description": "55-inch 4K UHD Display Panel",
"specs": {
"resolution": "3840x2160",
"refreshRate": "120Hz",
"panel_type": "OLED"
},
"price": 599.99,
"currency": "USD"
}
}
}
}
}
},
"responses": {
"201": {
"description": "Component template created successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProductComponentTemplate"
},
"example": {
"id": "123e4567-e89b-12d3-a456-426614174001",
"name": "4K Display Panel",
"description": "55-inch 4K UHD Display Panel",
"specs": {
"resolution": "3840x2160",
"refreshRate": "120Hz",
"panel_type": "OLED"
},
"price": 599.99,
"currency": "USD"
}
}
}
},
"400": {
"description": "Invalid input",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
},
"example": {
"code": 400,
"message": "Invalid component template data"
}
}
}
}
}
}
},
"/products/templates": {
"post": {
"summary": "Create a new product template",
"operationId": "createProductTemplate",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"components": {
"type": "array",
"items": {
"type": "string",
"format": "uuid"
}
},
"merchant_id": {
"type": "string",
"format": "uuid"
},
"category": {
"type": "string"
}
},
"required": [
"name",
"components",
"merchant_id"
]
},
"examples": {
"smartTV": {
"summary": "Create a Smart TV template",
"value": {
"name": "Smart TV 55-inch",
"description": "55-inch Smart TV with 4K Display",
"components": [
"123e4567-e89b-12d3-a456-426614174001"
],
"merchant_id": "123e4567-e89b-12d3-a456-426614174000",
"category": "Electronics"
}
}
}
}
}
},
"responses": {
"201": {
"description": "Product template created successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProductTemplate"
},
"example": {
"id": "123e4567-e89b-12d3-a456-426614174002",
"name": "Smart TV 55-inch",
"description": "55-inch Smart TV with 4K Display",
"components": [
{
"id": "123e4567-e89b-12d3-a456-426614174001",
"name": "4K Display Panel",
"description": "55-inch 4K UHD Display Panel",
"specs": {
"resolution": "3840x2160",
"refreshRate": "120Hz"
},
"price": 599.99,
"currency": "USD"
}
],
"merchant_id": "123e4567-e89b-12d3-a456-426614174000",
"category": "Electronics",
"active": true
}
}
}
},
"404": {
"description": "Merchant not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
},
"example": {
"code": 404,
"message": "Merchant not found"
}
}
}
}
}
}
},
"/products": {
"post": {
"summary": "Create a new product from template",
"operationId": "createProduct",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"template_id": {
"type": "string",
"format": "uuid"
},
"merchant_id": {
"type": "string",
"format": "uuid"
},
"stock_quantity": {
"type": "integer",
"minimum": 0
}
},
"required": [
"template_id",
"merchant_id",
"stock_quantity"
]
},
"examples": {
"newProduct": {
"summary": "Create a new Smart TV product",
"value": {
"template_id": "123e4567-e89b-12d3-a456-426614174002",
"merchant_id": "123e4567-e89b-12d3-a456-426614174000",
"stock_quantity": 50
}
}
}
}
}
},
"responses": {
"201": {
"description": "Product created successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Product"
},
"example": {
"id": "123e4567-e89b-12d3-a456-426614174003",
"template_id": "123e4567-e89b-12d3-a456-426614174002",
"name": "Smart TV 55-inch",
"description": "55-inch Smart TV with 4K Display",
"price": 899.99,
"currency": "USD",
"merchant_id": "123e4567-e89b-12d3-a456-426614174000",
"stock_quantity": 50,
"available": true
}
}
}
},
"404": {
"description": "Template or merchant not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
},
"example": {
"code": 404,
"message": "Product template not found"
}
}
}
}
}
}
},
"/orders": {
"post": {
"summary": "Create a new order",
"operationId": "createOrder",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"customer_id": {
"type": "string",
"format": "uuid"
},
"items": {
"type": "array",
"items": {
"$ref": "#/components/schemas/OrderItem"
}
}
},
"required": [
"customer_id",
"items"
]
},
"examples": {
"newOrder": {
"summary": "Create an order for two Smart TVs",
"value": {
"customer_id": "123e4567-e89b-12d3-a456-426614174005",
"items": [
{
"product_id": "123e4567-e89b-12d3-a456-426614174003",
"quantity": 2,
"price": 899.99,
"currency": "USD"
}
]
}
}
}
}
}
},
"responses": {
"201": {
"description": "Order created successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Order"
},
"example": {
"id": "123e4567-e89b-12d3-a456-426614174004",
"customer_id": "123e4567-e89b-12d3-a456-426614174005",
"items": [
{
"product_id": "123e4567-e89b-12d3-a456-426614174003",
"quantity": 2,
"price": 899.99,
"currency": "USD"
}
],
"total_amount": 1799.98,
"currency": "USD",
"status": "pending",
"created_at": "2024-02-10T10:30:00Z",
"updated_at": "2024-02-10T10:30:00Z"
}
}
}
},
"400": {
"description": "Invalid input or insufficient stock",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
},
"example": {
"code": 400,
"message": "Insufficient stock for product"
}
}
}
}
}
}
},
"/orders/{orderId}/status": {
"put": {
"summary": "Update order status",
"operationId": "updateOrderStatus",
"parameters": [
{
"name": "orderId",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
},
"example": "123e4567-e89b-12d3-a456-426614174004"
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"pending",
"confirmed",
"shipped",
"delivered"
]
}
},
"required": [
"status"
]
},
"examples": {
"updateStatus": {
"summary": "Update order to shipped status",
"value": {
"status": "shipped"
}
}
}
}
}
},
"responses": {
"200": {
"description": "Order status updated successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Order"
},
"example": {
"id": "123e4567-e89b-12d3-a456-426614174004",
"customer_id": "123e4567-e89b-12d3-a456-426614174005",
"items": [
{
"product_id": "123e4567-e89b-12d3-a456-426614174003",
"quantity": 2,
"price": 899.99,
"currency": "USD"
}
],
"total_amount": 1799.98,
"currency": "USD",
"status": "shipped",
"created_at": "2024-02-10T10:30:00Z",
"updated_at": "2024-02-10T10:35:00Z"
}
}
}
},
"404": {
"description": "Order not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
},
"example": {
"code": 404,
"message": "Order not found"
}
}
}
}
}
}
},
"/merchants/{merchantId}/products": {
"get": {
"summary": "Get all products for a merchant",
"operationId": "getMerchantProducts",
"parameters": [
{
"name": "merchantId",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
},
"example": "123e4567-e89b-12d3-a456-426614174000"
}
],
"responses": {
"200": {
"description": "List of merchant's products",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Product"
}
},
"example": [
{
"id": "123e4567-e89b-12d3-a456-426614174003",
"template_id": "123e4567-e89b-12d3-a456-426614174002",
"name": "Smart TV 55-inch",
"description": "55-inch Smart TV with 4K Display",
"price": 899.99,
"currency": "USD",
"merchant_id": "123e4567-e89b-12d3-a456-426614174000",
"stock_quantity": 48,
"available": true
}
]
}
}
},
"404": {
"description": "Merchant not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
},
"example": {
"code": 404,
"message": "Merchant not found"
}
}
}
}
}
}
},
"/merchants/{merchantId}/orders": {
"get": {
"summary": "Get all orders for a merchant's products",
"operationId": "getMerchantOrders",
"parameters": [
{
"name": "merchantId",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
},
"example": "123e4567-e89b-12d3-a456-426614174000"
}
],
"responses": {
"200": {
"description": "List of orders containing merchant's products",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Order"
}
},
"example": [
{
"id": "123e4567-e89b-12d3-a456-426614174004",
"customer_id": "123e4567-e89b-12d3-a456-426614174005",
"items": [
{
"product_id": "123e4567-e89b-12d3-a456-426614174003",
"quantity": 2,
"price": 899.99,
"currency": "USD"
}
],
"total_amount": 1799.98,
"currency": "USD",
"status": "shipped",
"created_at": "2024-02-10T10:30:00Z",
"updated_at": "2024-02-10T10:35:00Z"
}
]
}
}
},
"404": {
"description": "Merchant not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
},
"example": {
"code": 404,
"message": "Merchant not found"
}
}
}
}
}
}
}
}
}

View File

@@ -0,0 +1,148 @@
module geomind_poc
import freeflowuniverse.crystallib.core.playbook { PlayBook }
// play_commerce processes heroscript actions for the commerce system
pub fn play_commerce(mut plbook playbook.PlayBook) ! {
commerce_actions := plbook.find(filter: 'commerce.')!
mut c := Commerce{}
for action in commerce_actions {
match action.name {
'merchant' {
mut p := action.params
merchant := c.create_merchant(
name: p.get('name')!,
description: p.get_default('description', '')!,
contact: p.get('contact')!
)!
println('Created merchant: ${merchant.name}')
}
'component' {
mut p := action.params
component := c.create_product_component_template(
name: p.get('name')!,
description: p.get_default('description', '')!,
specs: p.get_map(),
price: p.get_float('price')!,
currency: p.get('currency')!
)!
println('Created component: ${component.name}')
}
'template' {
mut p := action.params
// Get component IDs as a list
component_ids := p.get_list('components')!
// Convert component IDs to actual components
mut components := []ProductComponentTemplate{}
for id in component_ids {
// In a real implementation, you would fetch the component from storage
// For this example, we create a dummy component
component := ProductComponentTemplate{
id: id
name: 'Component'
description: ''
specs: map[string]string{}
price: 0
currency: 'USD'
}
components << component
}
template := c.create_product_template(
name: p.get('name')!,
description: p.get_default('description', '')!,
components: components,
merchant_id: p.get('merchant_id')!,
category: p.get_default('category', 'General')!
)!
println('Created template: ${template.name}')
}
'product' {
mut p := action.params
product := c.create_product(
template_id: p.get('template_id')!,
merchant_id: p.get('merchant_id')!,
stock_quantity: p.get_int('stock_quantity')!
)!
println('Created product: ${product.name} with stock: ${product.stock_quantity}')
}
'order' {
mut p := action.params
// Get order items as a list of maps
items_data := p.get_list('items')!
mut items := []OrderItem{}
for item_data in items_data {
// Parse item data (format: "product_id:quantity:price:currency")
parts := item_data.split(':')
if parts.len != 4 {
return error('Invalid order item format: ${item_data}')
}
item := OrderItem{
product_id: parts[0]
quantity: parts[1].int()
price: parts[2].f64()
currency: parts[3]
}
items << item
}
order := c.create_order(
customer_id: p.get('customer_id')!,
items: items
)!
println('Created order: ${order.id} with ${order.items.len} items')
}
'update_order' {
mut p := action.params
order := c.update_order_status(
order_id: p.get('order_id')!,
new_status: p.get('status')!
)!
println('Updated order ${order.id} status to: ${order.status}')
}
else {
return error('Unknown commerce action: ${action.name}')
}
}
}
}
// Example heroscript usage:
/*
!!commerce.merchant
name: "Tech Gadgets Store"
description: "Premium electronics and gadgets retailer"
contact: "contact@techgadgets.com"
!!commerce.component
name: "4K Display Panel"
description: "55-inch 4K UHD Display Panel"
specs:
resolution: "3840x2160"
refreshRate: "120Hz"
panel_type: "OLED"
price: 599.99
currency: "USD"
!!commerce.template
name: "Smart TV 55-inch"
description: "55-inch Smart TV with 4K Display"
components: "123e4567-e89b-12d3-a456-426614174001"
merchant_id: "123e4567-e89b-12d3-a456-426614174000"
category: "Electronics"
!!commerce.product
template_id: "123e4567-e89b-12d3-a456-426614174002"
merchant_id: "123e4567-e89b-12d3-a456-426614174000"
stock_quantity: 50
!!commerce.order
customer_id: "123e4567-e89b-12d3-a456-426614174005"
items:
- "123e4567-e89b-12d3-a456-426614174003:2:899.99:USD"
!!commerce.update_order
order_id: "123e4567-e89b-12d3-a456-426614174004"
status: "shipped"
*/

View File

@@ -0,0 +1,190 @@
module geomind_poc
import crypto.rand
// Commerce represents the main e-commerce server handling all operations
pub struct Commerce {
mut:
merchants map[string]Merchant
templates map[string]ProductTemplate
products map[string]Product
orders map[string]Order
}
// generate_id creates a unique identifier
fn generate_id() string {
return rand.uuid_v4()
}
// create_merchant adds a new merchant to the system
pub fn (mut c Commerce) create_merchant(name string, description string, contact string) !Merchant {
merchant_id := generate_id()
merchant := Merchant{
id: merchant_id
name: name
description: description
contact: contact
active: true
}
c.merchants[merchant_id] = merchant
return merchant
}
// create_product_component_template creates a new component template
pub fn (mut c Commerce) create_product_component_template(name string, description string, specs map[string]string, price f64, currency string) !ProductComponentTemplate {
component := ProductComponentTemplate{
id: generate_id()
name: name
description: description
specs: specs
price: price
currency: currency
}
return component
}
// create_product_template creates a new product template
pub fn (mut c Commerce) create_product_template(name string, description string, components []ProductComponentTemplate, merchant_id string, category string) !ProductTemplate {
if merchant_id !in c.merchants {
return error('Merchant not found')
}
template := ProductTemplate{
id: generate_id()
name: name
description: description
components: components
merchant_id: merchant_id
category: category
active: true
}
c.templates[template.id] = template
return template
}
// create_product creates a new product instance from a template
pub fn (mut c Commerce) create_product(template_id string, merchant_id string, stock_quantity int) !Product {
if template_id !in c.templates {
return error('Template not found')
}
if merchant_id !in c.merchants {
return error('Merchant not found')
}
template := c.templates[template_id]
mut total_price := 0.0
for component in template.components {
total_price += component.price
}
product := Product{
id: generate_id()
template_id: template_id
name: template.name
description: template.description
price: total_price
currency: template.components[0].currency // assuming all components use same currency
merchant_id: merchant_id
stock_quantity: stock_quantity
available: true
}
c.products[product.id] = product
return product
}
// create_order creates a new order
pub fn (mut c Commerce) create_order(customer_id string, items []OrderItem) !Order {
mut total_amount := 0.0
mut currency := ''
for item in items {
if item.product_id !in c.products {
return error('Product not found: ${item.product_id}')
}
product := c.products[item.product_id]
if !product.available || product.stock_quantity < item.quantity {
return error('Product ${product.name} is not available in requested quantity')
}
total_amount += item.price * item.quantity
if currency == '' {
currency = item.currency
} else if currency != item.currency {
return error('Mixed currencies are not supported')
}
}
order := Order{
id: generate_id()
customer_id: customer_id
items: items
total_amount: total_amount
currency: currency
status: 'pending'
created_at: time.now().str()
updated_at: time.now().str()
}
c.orders[order.id] = order
// Update stock quantities
for item in items {
mut product := c.products[item.product_id]
product.stock_quantity -= item.quantity
if product.stock_quantity == 0 {
product.available = false
}
c.products[item.product_id] = product
}
return order
}
// update_order_status updates the status of an order
pub fn (mut c Commerce) update_order_status(order_id string, new_status string) !Order {
if order_id !in c.orders {
return error('Order not found')
}
mut order := c.orders[order_id]
order.status = new_status
order.updated_at = time.now().str()
c.orders[order_id] = order
return order
}
// get_merchant_products returns all products for a given merchant
pub fn (c Commerce) get_merchant_products(merchant_id string) ![]Product {
if merchant_id !in c.merchants {
return error('Merchant not found')
}
mut products := []Product{}
for product in c.products.values() {
if product.merchant_id == merchant_id {
products << product
}
}
return products
}
// get_merchant_orders returns all orders for products sold by a merchant
pub fn (c Commerce) get_merchant_orders(merchant_id string) ![]Order {
if merchant_id !in c.merchants {
return error('Merchant not found')
}
mut orders := []Order{}
for order in c.orders.values() {
mut includes_merchant := false
for item in order.items {
product := c.products[item.product_id]
if product.merchant_id == merchant_id {
includes_merchant = true
break
}
}
if includes_merchant {
orders << order
}
}
return orders
}

View File

@@ -0,0 +1,57 @@
- profile management
- my name
- my pub key
- kyc
- ...
- product has components
- admin items
- supported_currencies
- countries
- continents
- farming
- farms
- default farm exists, users don't have to chose
- name
- description
- owner (pubkey)
- nodes
- reward (nr of INCA per month and time e.g. 24 months)
- reward_promised
- reward_given
- location
- coordinates
- continent
- country
- description
- farmid
- capacity (disks, mem, ...)
- gridversion (eg. 3.16)
- nodestats
- ...
- uptime
- bandwidth
- referral system
- coupons for discounts (one product can have multiple coupons and discounts)
- data gets imported with heroscript for what we sell
- minimal wallet function (BTC, CHF, MGLD, TFT, INCA)
- transactions, so they can see what they spend money on
- transfer/exchange
- basic communication (messages in/out)
- to allow us to communicate with user
- news
- basic news feed with topics, which we can set
- vdc
- name
- description (optional)
- spendinglimit
- currency per month, week or day e.g. 0.1 BTC/month
- each spending limit has name
- admins, list of pubkeys who have access to this and can add capacity to it, or delete, ...
- deployment
- deploymentid
- vdcid
- heroscript
- status
- links (name, link, description, category)

View File

@@ -0,0 +1,47 @@
#!/usr/bin/env -S v
import freeflowuniverse.crystallib.core.playbook
import geomind_poc
fn main() {
test_script := "
!!commerce.merchant
name: 'Tech Gadgets Store'
description: 'Premium electronics and gadgets retailer'
contact: 'contact@techgadgets.com'
!!commerce.component
name: '4K Display Panel'
description: '55-inch 4K UHD Display Panel'
specs:
resolution: '3840x2160'
refreshRate: '120Hz'
panel_type: 'OLED'
price: 599.99
currency: 'USD'
!!commerce.template
name: 'Smart TV 55-inch'
description: '55-inch Smart TV with 4K Display'
components: '123e4567-e89b-12d3-a456-426614174001'
merchant_id: '123e4567-e89b-12d3-a456-426614174000'
category: 'Electronics'
!!commerce.product
template_id: '123e4567-e89b-12d3-a456-426614174002'
merchant_id: '123e4567-e89b-12d3-a456-426614174000'
stock_quantity: 50
!!commerce.order
customer_id: '123e4567-e89b-12d3-a456-426614174005'
items:
- '123e4567-e89b-12d3-a456-426614174003:2:899.99:USD'
!!commerce.update_order
order_id: '123e4567-e89b-12d3-a456-426614174004'
status: 'shipped'
"
mut plbook := playbook.new(text: test_script)!
geomind_poc.play_commerce(mut plbook)!
}

View File

@@ -17,9 +17,9 @@ echo "* /queues/${actor_name} -> Action Interface"
echo ""
echo "${actor_title} Actor HTTP Server running on http://localhost:8080"
echo "* /playground/openapi -> OpenAPI Playground"
echo "* /openapi -> OpenAPI Interface"
echo "* /docs -> Documentation"
echo "* http://localhost:8080/playground/openapi -> OpenAPI Playground"
echo "* http://localhost:8080/openapi -> OpenAPI Interface"
# echo "* http://localhost:8080/docs -> Documentation"
echo ""
# Function to clean up when script is killed