Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
75934a3
Add migrations for various database schema updates
gustaavik Jun 29, 2025
de6530e
feat: Update product_prices table indexing and constraints for data i…
gustaavik Jun 29, 2025
730c406
feat: Add orders and order_items tables to enhance order management f…
gustaavik Jun 29, 2025
a8213aa
feat: Add API contracts for categories, checkouts, currencies, discou…
gustaavik Jun 29, 2025
e75a3d4
Refactor entity models to use GORM's Model struct for automatic times…
gustaavik Jun 29, 2025
225e58d
feat: Refactor product and variant pricing structure to simplify pric…
gustaavik Jun 29, 2025
0e523b6
feat: add test-db command for database connection testing
gustaavik Jun 29, 2025
80cc3a7
refactor: remove explicit price deletion in product and variant delet…
gustaavik Jun 29, 2025
1a10db8
Refactor shipping and user handlers to use contracts for request and …
gustaavik Jun 30, 2025
7db8a65
feat: Implement GORM repositories for various entities
gustaavik Jun 30, 2025
6d2c066
feat: Implement GORM-based repositories for shipping methods, rates, …
gustaavik Jun 30, 2025
0eb6f86
Refactor database migrations: Remove legacy currency, order, and cart…
gustaavik Jun 30, 2025
3ca675d
feat: Introduce JSONB type for flexible JSON handling and update paym…
gustaavik Jun 30, 2025
f5a0005
feat: Implement MobilePay and Stripe webhook handlers for payment pro…
gustaavik Jun 30, 2025
2015000
refactor: Replace UpdateOrderPaymentStatus with UpdatePaymentStatus i…
gustaavik Jun 30, 2025
6b7b5ef
feat: Enhance MobilePay and Stripe webhook handlers to record payment…
gustaavik Jun 30, 2025
96dce64
feat(mock): Implement mock logger and repository services for testing
gustaavik Jun 30, 2025
b91d479
Add unit tests for payment provider, transaction, product, and user e…
gustaavik Jun 30, 2025
59f6ec0
feat(tests): Add DTO conversion tests for Checkout, Discount, Order, …
gustaavik Jun 30, 2025
4bb2269
feat: enhance seeding functionality for users, categories, products, …
gustaavik Jun 30, 2025
49dfab0
feat: enhance PostgreSQL setup and logging configuration; update type…
gustaavik Jun 30, 2025
1c3efc0
feat: Add DTOs for categories, checkouts, orders, products, discounts…
gustaavik Jun 30, 2025
4002acb
Refactor DTO imports and restructure directory
gustaavik Jun 30, 2025
9f7c314
feat: Add currency seeding functionality and update product image han…
gustaavik Jun 30, 2025
ae8b605
feat: Refactor image handling to use common.StringSlice for consisten…
gustaavik Jun 30, 2025
74c5587
fix: Update shipping field reference in checkout abandonment queries
gustaavik Jun 30, 2025
7a95f01
feat: Enhance checkout functionality with JSON storage for shipping o…
gustaavik Jun 30, 2025
b5f957d
Refactor checkout and order handling to use JSON for addresses and di…
gustaavik Jun 30, 2025
07225e4
feat: Introduce StringMap type for handling JSON maps in database and…
gustaavik Jun 30, 2025
7ec2530
undo
gustaavik Jun 30, 2025
f034791
chore: Remove unused API binary file
gustaavik Jun 30, 2025
86fbd86
feat: Enhance Checkout DTO conversion to handle empty addresses and c…
gustaavik Jun 30, 2025
4820309
refactor: Update JSON column names in Checkout and Order entities for…
gustaavik Jul 1, 2025
31986f8
chore: Update dependencies in go.mod and go.sum for improved compatib…
gustaavik Jul 1, 2025
e9ac3b5
feat: Implement GetOrderByExternalID method and update MobilePay webh…
gustaavik Jul 1, 2025
7f736f9
fix: transaction type status not updating correctly
gustaavik Jul 1, 2025
1a3cb11
fix: Handle nil CustomerDetails in Order DTO conversions
gustaavik Jul 1, 2025
9f16ef6
feat: Update order number format to include guest order prefix and re…
gustaavik Jul 1, 2025
8015d17
feat: Enhance email templates and test handler with shipping, billing…
gustaavik Jul 1, 2025
2d55dd7
feat: Refactor product retrieval to remove currency filtering and enh…
gustaavik Jul 1, 2025
4e52100
Merge pull request #40 from Zenfulcode/migration-cleanup-payment-prov…
gustaavik Jul 1, 2025
0de6a66
feat: Update DTOs and API contracts for improved data handling and st…
gustaavik Jul 1, 2025
25a66e9
feat: Refactor order handling to use pointer for UserID, improving gu…
gustaavik Jul 1, 2025
7fde860
feat: Update session ID indexing and enhance checkout deletion logic …
gustaavik Jul 1, 2025
f854af8
feat: Enhance payment transaction handling with unique constraints an…
gustaavik Jul 1, 2025
203465b
Refactor payment transaction and product entity structures
gustaavik Jul 2, 2025
1a9bae5
Remove mock implementations of payment provider service, payment tran…
gustaavik Jul 2, 2025
65b72ff
feat: Remove MobilePay market configuration and enhance payment provi…
gustaavik Jul 2, 2025
6397b92
refactor: Remove unused fields from CheckoutDTO for cleaner structure
gustaavik Jul 2, 2025
3e3804e
feat: Enhance transaction handling with idempotency checks and amount…
gustaavik Jul 2, 2025
8605935
Merge pull request #42 from Zenfulcode/cleanup-whole-lotta-shit
gustaavik Jul 2, 2025
8af8199
feat: Implement stock availability checks in checkout process and imp…
gustaavik Jul 2, 2025
826b14a
feat: Implement hard deletion of products and their variants with tra…
gustaavik Jul 2, 2025
d43dd17
feat: Update product DTO conversion to use summary DTO for product li…
gustaavik Jul 2, 2025
e6af56b
Merge pull request #43 from Zenfulcode/migrations-cleanup2
gustaavik Jul 2, 2025
3d53128
feat: Add gorm.io/datatypes and update go.sum with new dependencies
gustaavik Jul 2, 2025
0ca2dbb
feat: Enhance product and variant management with admin-only updates …
gustaavik Jul 3, 2025
c1adfed
feat: Add tests for updating product variant with isDefault changes
gustaavik Jul 3, 2025
1557ca7
feat: Add OrderSummaryDTO to type mappings and update CheckoutComplet…
gustaavik Jul 3, 2025
6e266a0
feat: Improve logging in HealthHandler by adding request log
gustaavik Jul 3, 2025
1886d74
feat: Enable CORS middleware for API routes
gustaavik Jul 3, 2025
95d5ff8
feat: Update product listing filters to conditionally apply active st…
gustaavik Jul 4, 2025
9c247c0
feat: Refactor pagination logic in order listing handlers to use offs…
gustaavik Jul 4, 2025
4560a8b
feat: Update TestEmail handler to use target email from request param…
gustaavik Jul 4, 2025
e021a2d
feat: Enhance order and payment APIs with optional query parameters a…
gustaavik Jul 5, 2025
974bb67
feat: Add currency formatting to order confirmation and notification …
gustaavik Jul 5, 2025
40d91f6
Merge branch 'main' of https://github.com/gkhaavik/Commercify into de…
gustaavik Jul 5, 2025
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
22 changes: 16 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
DB_HOST=localhost
DB_PORT=5432
DB_USER=
DB_PASSWORD=
DB_NAME=commercify
# Database Configuration
# For local development (SQLite)
DB_DRIVER=sqlite
DB_NAME=commercify.db

# For production (PostgreSQL) - uncomment and configure these when using PostgreSQL
# DB_DRIVER=postgres
# DB_HOST=localhost
# DB_PORT=5432
# DB_USER=postgres
# DB_PASSWORD=postgres
# DB_NAME=commercify
# DB_SSL_MODE=disable

# Debug mode for database queries
DB_DEBUG=false

AUTH_JWT_SECRET=your_jwt_secret

Expand All @@ -29,7 +40,6 @@ MOBILEPAY_CLIENT_ID=your_client_id
MOBILEPAY_CLIENT_SECRET=your_client_secret
MOBILEPAY_WEBHOOK_URL=https://your-site.com/api/webhooks/mobilepay
MOBILEPAY_PAYMENT_DESCRIPTION=Commercify Store Purchase
MOBILEPAY_MARKET=NOK

RETURN_URL=https://your-site.com/payment/complete
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5173
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ go.work.sum

# env file
.env
.env.local
.env.production

# SQLite database files
*.db
*.sqlite
*.sqlite3

bin/
commercify
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ RUN rm -f go.work go.work.sum
# Build all three applications
RUN go mod download
RUN go build -o commercify cmd/api/main.go
RUN go build -o commercify-migrate cmd/migrate/main.go
RUN go build -o commercify-seed cmd/seed/main.go

# Create a minimal final image
Expand All @@ -27,16 +26,14 @@ RUN apk add --no-cache ca-certificates tzdata bash

# Copy the binaries from the builder stage
COPY --from=builder /app/commercify /app/commercify
COPY --from=builder /app/commercify-migrate /app/commercify-migrate
COPY --from=builder /app/commercify-seed /app/commercify-seed
COPY --from=builder /app/migrations /app/migrations
COPY --from=builder /app/templates /app/templates

# Copy .env file if it exists (will be overridden by env_file in docker-compose)
# COPY --from=builder /app/.env /app/

# Set executable permissions for all binaries
RUN chmod +x /app/commercify /app/commercify-migrate /app/commercify-seed
RUN chmod +x /app/commercify /app/commercify-seed

# Expose the port
EXPOSE 6091
Expand Down
67 changes: 43 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
.PHONY: help db-start db-stop db-restart db-logs db-clean migrate-up migrate-down seed-data build run test clean docker-build docker-build-tag docker-push docker-build-push
.PHONY: help db-start db-stop db-restart db-logs db-clean seed-data build run test clean docker-build docker-build-tag docker-push docker-build-push dev-sqlite dev-postgres

# Default target
help: ## Show this help message
@echo "Available commands:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

# Database commands
# Development environment setup
dev-postgres: ## Run the application locally with database
@echo "Setting up PostgreSQL development environment..."
@cp .env.production .env 2>/dev/null || true
@echo "Environment configured for PostgreSQL. Starting application..."
@echo "Starting database and waiting for it to be ready..."
make db-start
@sleep 3
go run ./cmd/api

# Database commands (PostgreSQL)
db-start: ## Start PostgreSQL database container
docker compose up -d postgres

Expand All @@ -22,41 +32,40 @@ db-clean: ## Stop and remove PostgreSQL container and volumes
docker compose down postgres
docker volume rm commercify_postgres_data 2>/dev/null || true

# Migration commands
migrate-up: ## Run database migrations up
docker compose run --rm migrate -up

migrate-down: ## Run database migrations down
docker compose run --rm migrate -down

migrate-status: ## Show migration status
docker compose run --rm migrate -status

# Seed data
seed-data: ## Seed database with sample data
docker compose run --rm seed -all

# Application commands
build: ## Build the application
go build -o bin/api ./cmd/api
go build -o bin/migrate ./cmd/migrate
go build -o bin/seed ./cmd/seed
go build -o bin/expire-checkouts ./cmd/expire-checkouts

run: db-start ## Run the application locally with database
@echo "Starting database and waiting for it to be ready..."
@sleep 3
run:
@echo "Setting up SQLite development environment..."
@cp .env.local .env 2>/dev/null || true
@echo "Environment configured for SQLite. Starting application..."
go run ./cmd/api

run-docker: ## Run the entire application stack with Docker
run-docker: ## Run the entire application stack with Docker (PostgreSQL)
docker compose up -d

run-docker-sqlite: ## Run the application with Docker using SQLite
docker compose -f docker-compose.local.yml up -d

stop-docker: ## Stop the entire application stack
docker compose down

stop-docker-sqlite: ## Stop the SQLite application stack
docker compose -f docker-compose.local.yml down

logs: ## Show application logs
docker compose logs -f api

logs-sqlite: ## Show SQLite application logs
docker compose -f docker-compose.local.yml logs -f api

# Docker image commands
docker-build: ## Build Docker image
docker build -t ghcr.io/zenfulcode/commercifygo:latest .
Expand All @@ -76,8 +85,9 @@ docker-push: ## Push Docker image to registry (use REGISTRY and TAG)

docker-build-push: docker-build-tag docker-push ## Build and push Docker image (use REGISTRY and TAG)

docker-dev-build: ## Build Docker image for development
docker build -t ghcr.io/zenfulcode/commercifygo:dev .
docker-dev-push: ## Build Docker image for development
docker build -t ghcr.io/zenfulcode/commercifygo:v2-dev .
docker push ghcr.io/zenfulcode/commercifygo:v2-dev

# Development commands
test: ## Run tests
Expand All @@ -90,12 +100,21 @@ clean: ## Clean build artifacts
rm -rf bin/
go clean

# Database setup for development
dev-setup: db-start migrate-up seed-data ## Setup development environment (start db, migrate, seed)
@echo "Development environment ready!"
# Database setup commands
dev-setup: ## Setup development environment with PostgreSQL (start db, seed)
make db-start
@sleep 3
make seed-data
@echo "Development environment ready with PostgreSQL!"

dev-reset: db-clean db-start seed-data ## Reset PostgreSQL development environment
@echo "Development environment reset with PostgreSQL!"

dev-reset: db-clean db-start migrate-up seed-data ## Reset development environment
@echo "Development environment reset!"
dev-reset-sqlite: ## Reset SQLite development environment
@echo "Resetting SQLite development environment..."
@rm -f commercify.db 2>/dev/null || true
@cp .env.local .env 2>/dev/null || true
@echo "SQLite database reset!"

# Format and lint
fmt: ## Format Go code
Expand Down
9 changes: 2 additions & 7 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,11 @@ func main() {
}

// Connect to database
db, err := database.NewPostgresConnection(cfg.Database)
db, err := database.InitDB(cfg.Database)
if err != nil {
logger.Fatal("Failed to connect to database: %v", err)
}
defer db.Close()

// Run database migrations
if err := database.RunMigrations(db, cfg.Database); err != nil {
logger.Fatal("Failed to run database migrations: %v", err)
}
defer database.Close(db)

// Initialize API server
server := api.NewServer(cfg, db, logger)
Expand Down
4 changes: 2 additions & 2 deletions cmd/expire-checkouts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func main() {
}

// Connect to database
db, err := database.NewPostgresConnection(cfg.Database)
db, err := database.InitDB(cfg.Database)
if err != nil {
logger.Fatal("Failed to connect to database: %v", err)
}
defer db.Close()
defer database.Close(db)

// Initialize dependency container
diContainer := container.NewContainer(cfg, db, logger)
Expand Down
105 changes: 0 additions & 105 deletions cmd/migrate/main.go

This file was deleted.

Loading