Merge pull request 'feat: add printer types' (#40) from fix/point-payment-method-types into main

Reviewed-on: https://gits.altru.id/apksel-dev/apskel-pos-backend/pulls/40
This commit was merged in pull request #40.
This commit is contained in:
2026-10-01 17:43:53 +02:00
25 changed files with 2048 additions and 66 deletions
@@ -39,7 +39,7 @@ func (r *ProductIngredientRepository) Create(ctx context.Context, productIngredi
func (r *ProductIngredientRepository) GetByID(ctx context.Context, id, organizationID uuid.UUID) (*entities.ProductIngredient, error) {
query := `
SELECT pi.id, pi.organization_id, pi.outlet_id, pi.product_id, pi.ingredient_id, pi.quantity, pi.created_at, pi.updated_at,
p.id, p.organization_id, p.category_id, p.sku, p.name, p.description, p.price, p.cost, p.business_type, p.image_url, p.printer_type, p.unit_id, p.has_ingredients, p.metadata, p.is_active, p.created_at, p.updated_at,
p.id, p.organization_id, p.category_id, p.sku, p.name, p.description, p.price, p.cost, p.business_type, p.image_url, p.printer_types, p.unit_id, p.has_ingredients, p.metadata, p.is_active, p.created_at, p.updated_at,
i.id, i.organization_id, i.outlet_id, i.name, i.unit_id, i.cost, i.stock, i.is_semi_finished, i.is_active, i.metadata, i.created_at, i.updated_at
FROM product_ingredients pi
LEFT JOIN products p ON pi.product_id = p.id
@@ -70,7 +70,7 @@ func (r *ProductIngredientRepository) GetByID(ctx context.Context, id, organizat
&product.Cost,
&product.BusinessType,
&product.ImageURL,
&product.PrinterType,
&product.PrinterTypes,
&product.UnitID,
&product.HasIngredients,
&product.Metadata,
@@ -103,7 +103,7 @@ func (r *ProductIngredientRepository) GetByID(ctx context.Context, id, organizat
func (r *ProductIngredientRepository) GetByProductID(ctx context.Context, productID, organizationID uuid.UUID) ([]*entities.ProductIngredient, error) {
query := `
SELECT pi.id, pi.organization_id, pi.outlet_id, pi.product_id, pi.ingredient_id, pi.quantity, pi.created_at, pi.updated_at,
p.id, p.organization_id, p.category_id, p.sku, p.name, p.description, p.price, p.cost, p.business_type, p.image_url, p.printer_type, p.unit_id, p.has_ingredients, p.metadata, p.is_active, p.created_at, p.updated_at,
p.id, p.organization_id, p.category_id, p.sku, p.name, p.description, p.price, p.cost, p.business_type, p.image_url, p.printer_types, p.unit_id, p.has_ingredients, p.metadata, p.is_active, p.created_at, p.updated_at,
i.id, i.organization_id, i.outlet_id, i.name, i.unit_id, i.cost, i.stock, i.is_semi_finished, i.is_active, i.metadata, i.created_at, i.updated_at
FROM product_ingredients pi
LEFT JOIN products p ON pi.product_id = p.id
@@ -143,7 +143,7 @@ func (r *ProductIngredientRepository) GetByProductID(ctx context.Context, produc
&product.Cost,
&product.BusinessType,
&product.ImageURL,
&product.PrinterType,
&product.PrinterTypes,
&product.UnitID,
&product.HasIngredients,
&product.Metadata,
@@ -178,7 +178,7 @@ func (r *ProductIngredientRepository) GetByProductID(ctx context.Context, produc
func (r *ProductIngredientRepository) GetByIngredientID(ctx context.Context, ingredientID, organizationID uuid.UUID) ([]*entities.ProductIngredient, error) {
query := `
SELECT pi.id, pi.organization_id, pi.outlet_id, pi.product_id, pi.ingredient_id, pi.quantity, pi.created_at, pi.updated_at,
p.id, p.organization_id, p.category_id, p.sku, p.name, p.description, p.price, p.cost, p.business_type, p.image_url, p.printer_type, p.unit_id, p.has_ingredients, p.metadata, p.is_active, p.created_at, p.updated_at,
p.id, p.organization_id, p.category_id, p.sku, p.name, p.description, p.price, p.cost, p.business_type, p.image_url, p.printer_types, p.unit_id, p.has_ingredients, p.metadata, p.is_active, p.created_at, p.updated_at,
i.id, i.organization_id, i.outlet_id, i.name, i.unit_id, i.cost, i.stock, i.is_semi_finished, i.is_active, i.metadata, i.created_at, i.updated_at
FROM product_ingredients pi
LEFT JOIN products p ON pi.product_id = p.id
@@ -218,7 +218,7 @@ func (r *ProductIngredientRepository) GetByIngredientID(ctx context.Context, ing
&product.Cost,
&product.BusinessType,
&product.ImageURL,
&product.PrinterType,
&product.PrinterTypes,
&product.UnitID,
&product.HasIngredients,
&product.Metadata,
@@ -0,0 +1,48 @@
package repository
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"apskel-pos-be/internal/entities"
)
// Needs TEST_DATABASE_URL pointing at a migrated database; see walletTestDB.
func TestProductPrinterTypes_AgainstPostgres(t *testing.T) {
db := walletTestDB(t)
ctx := context.Background()
org, category := uuid.New(), uuid.New()
require.NoError(t, db.Exec(`INSERT INTO organizations (id, name, plan_type) VALUES (?, 'printer test', 'basic')`, org).Error)
require.NoError(t, db.Exec(`INSERT INTO categories (id, organization_id, name) VALUES (?, ?, 'Paket')`, category, org).Error)
t.Cleanup(func() {
db.Exec(`DELETE FROM products WHERE organization_id = ?`, org)
db.Exec(`DELETE FROM categories WHERE id = ?`, category)
db.Exec(`DELETE FROM organizations WHERE id = ?`, org)
})
repo := NewProductRepositoryImpl(db)
product := &entities.Product{OrganizationID: org, CategoryID: category, Name: "Paket Makan Minum", Price: 25000}
product.SetPrinterTypes([]string{"kitchen", "bar"})
require.NoError(t, repo.Create(ctx, product))
stored, err := repo.GetByID(ctx, product.ID)
require.NoError(t, err)
assert.Equal(t, entities.StringSlice{"kitchen", "bar"}, stored.PrinterTypes)
stored.SetPrinterTypes([]string{"bar"})
require.NoError(t, repo.Update(ctx, stored))
var printerTypes string
require.NoError(t, db.Raw(`SELECT printer_types::text FROM products WHERE id = ?`, product.ID).Scan(&printerTypes).Error)
assert.Equal(t, `["bar"]`, printerTypes)
// The old single column is gone.
var columns int64
require.NoError(t, db.Raw(`SELECT COUNT(*) FROM information_schema.columns WHERE table_name = 'products' AND column_name = 'printer_type'`).Scan(&columns).Error)
assert.Zero(t, columns)
}