Skip to content

hyperkliv/samling

Folders and files

NameName
Last commit message
Last commit date
Jan 8, 2025
Oct 29, 2024
May 23, 2023
Jan 10, 2025
Jan 13, 2025
Jan 8, 2025
Jan 4, 2023
Jan 4, 2023
Jan 5, 2025
Jan 4, 2023
Jan 8, 2025
Jan 13, 2025
Jan 7, 2025
Jan 8, 2025
Jan 4, 2023
Jan 4, 2023
Jan 16, 2023
Jan 7, 2025
Jan 10, 2025
Jan 4, 2023
Jan 5, 2025
Jan 17, 2023
Jan 8, 2025
Jan 7, 2025
Oct 30, 2024

Repository files navigation

Deploying

Running in a Kubernetes cluster

TODO: Write

For developers

Set up development environment

1. Create user config

This config will be picked up automatically

echo "DB_USER=$(whoami)
DB_NAME=samling
SECRET=abc123
LOG_LEVEL=info
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
CLOUDFLARE_ACCOUNT_ID=abc
CLOUDFLARE_TOKEN=123
SAMLING_PRETTY_RESPONSES=true" > .env

2. Create database and migrate

createdb samling
cargo run migrate

3. Create user

Export the user ID as an environment variable, we'll use it later. USER_ID should be 1 as in this example, if the database is clean. We'll also store SUPERUSER_ID for CLI access.

cargo run users create --name 'My Name' --email [email protected] --password MyPassword
export USER_ID=1
echo SUPERUSER_ID=$USER_ID >> .env

4. Create organization

cargo run organizations create 'Company Name'
export ORGANIZATION_ID=1

5. Associate all roles to superuser

NOTE: ORGANIZATION_ID might be something different than 1.

cargo run users associate-roles --all $USER_ID $ORGANIZATION_ID

6. Start the API server

cargo run serve

7. (Optional) Store API token for conveniently making API calls

NOTE: The stored API token will have to be updated every 7 days for the api command to work.

echo SAMLING_TOKEN=$(cargo run generate-user-token $USER_ID) >> .env

Pro tip! You can use cargo-watch to have the server restart every time the code changes.

cargo watch -- cargo run serve

8. Start the frontend

This is easy! Just do:

cd ui
npm install
npm start

Creating data via API

Currently the only way to create categories, prices, styles etc is via the API.

For example, to create a category called T-Shirts:

echo '{"name": {"en": "T-shirts"}}' | samling api -d - PUT 1/categories/external_id:BC-TShirts

A style:

echo '{"number": "A12345", "name": {"en": "Cool t-shirt"}}' | samling api -d - PUT 1/styles/external_id:BC-A12345

A color, associated with the above style:

echo '{"number": "HBlue", "name": {"en": "Hazy Blue"}, "style": {"external_id": "BC-A12345"}}' | samling api -d - PUT 1/colors/external_id:BC-A12345-HBlue

A size, associated with the above color:

echo '{"number": "XS", "name": {"en": "Extra small"}, "position": 1, "color": {"external_id": "BC-A12345-HBlue"}}' | samling api -d - PUT 1/sizes/external_id:BC-A12345-HBlue-XS

Notice how we're doing PUT requests here, with an External ID specified in the URL. This would be the typical way of syncing data from your ERP system.