unitep

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnitPresenter

func UnitPresenter(u *pb.UnitInfo, ownerAccount *apiresource.Account) apiresource.Unit

Types

type BulkUpsertUnitsEndpoint

type BulkUpsertUnitsEndpoint struct{}

Creates or updates multiple units of measure for the account, matched by name or abbreviation, then writes asynchronously — 202 with a job to poll.

func (*BulkUpsertUnitsEndpoint) Materialize

type BulkUpsertUnitsRequest

type BulkUpsertUnitsRequest struct {
	// Units to create or update, matched by name or abbreviation within the account.
	Units []UpsertUnitInput `json:"units" validate:"required,min=1,max=1000,dive"`
}

BulkUpsertUnitsRequest is the request to bulk upsert units.

func (*BulkUpsertUnitsRequest) SchemaExample

func (*BulkUpsertUnitsRequest) SchemaExample() any

type CreateUnitEndpoint

type CreateUnitEndpoint struct{}

Creates a unit of measurement owned by your account, in addition to the system units the platform already provides.

The name and abbreviation must each be unique within the account. A unit created here is never a base unit, so its conversion ratio is interpreted relative to the base unit of the chosen dimension.

func (*CreateUnitEndpoint) Materialize

type CreateUnitRequest

type CreateUnitRequest struct {
	// Display name of the unit (e.g. "Gram").
	//
	// Must be unique within the account.
	Name string `json:"name" validate:"required,max=255"`
	// Short abbreviation for the unit (e.g. "g").
	//
	// Must be unique within the account.
	Abbreviation string `json:"abbreviation" validate:"required"`
	// The dimension this unit measures, such as mass, volume, or currency.
	//
	// Units can only be converted to other units of the same dimension, and the dimension cannot be changed after the unit is created.
	Type constants.UnitType `json:"type" validate:"required"`
	// Numerator of the ratio that converts a quantity in this unit into the dimension's base unit.
	//
	// A quantity is converted with `value × (ratio_numerator / ratio_denominator) + (offset_numerator / offset_denominator)`, so a kilogram in a gram-based dimension has a numerator of `1000` and a denominator of `1`.
	RatioNumerator string `json:"ratio_numerator" validate:"required,decimal" format:"decimal"`
	// Denominator of the ratio that converts a quantity in this unit into the dimension's base unit.
	//
	// Must not be zero.
	RatioDenominator string `json:"ratio_denominator" validate:"required,nonzero_decimal" format:"decimal"`
	// Numerator of the conversion offset, applied after the ratio for scales that do not share a zero point, such as temperature.
	//
	// Send `0` for units that convert by ratio alone.
	OffsetNumerator string `json:"offset_numerator" validate:"required,decimal" format:"decimal"`
	// Denominator of the conversion offset.
	//
	// Must not be zero, so send `1` when the unit has no offset.
	OffsetDenominator string `json:"offset_denominator" validate:"required,nonzero_decimal" format:"decimal"`
}

Request to create a unit.

func (*CreateUnitRequest) SchemaExample

func (*CreateUnitRequest) SchemaExample() any

type DeleteUnitEndpoint

type DeleteUnitEndpoint struct{}

Deletes a unit owned by your account.

The unit is also removed from every unit group it belongs to. System units, which are shared across all accounts, cannot be deleted.

func (*DeleteUnitEndpoint) Materialize

type DeleteUnitRequest

type DeleteUnitRequest struct {
	// Unit ID.
	UnitID string `path:"id" validate:"required"`
}

Request to delete a unit.

type ExportUnitsEndpoint

type ExportUnitsEndpoint struct{}

Starts an export of every matching unit and returns the job that tracks it; system units are included, as on the list.

func (*ExportUnitsEndpoint) Materialize

type ExportUnitsRequest

type ExportUnitsRequest struct {
	// Free-text search term matched against unit names.
	Query *string `json:"q"`
}

Filters which units land in the exported file.

func (*ExportUnitsRequest) SchemaExample

func (*ExportUnitsRequest) SchemaExample() any

type ListUnitsEndpoint

type ListUnitsEndpoint struct{}

Returns a paginated list of units for the current account, including both account-owned and global system units.

func (*ListUnitsEndpoint) Materialize

type ListUnitsRequest

type ListUnitsRequest struct {
	apiresource.PaginationRequest
	// Filter by unit dimension.
	Type *constants.UnitType `query:"type"`
	// Return only units that belong to at least one of the given unit groups.
	UnitGroupIDs []string `query:"unit_group_ids"`
}

Request to list units.

type RetrieveUnitEndpoint

type RetrieveUnitEndpoint struct{}

Returns a unit by ID, including both account-owned and global system units.

func (*RetrieveUnitEndpoint) Materialize

type RetrieveUnitRequest

type RetrieveUnitRequest struct {
	// Unit ID.
	UnitID string `path:"id" validate:"required"`
}

Request to retrieve a unit.

type UnitSvcConfig

type UnitSvcConfig struct {
	// CoreClient (required) is the core-service gRPC client.
	CoreClient pb.CoreServiceClient
}

type UpdateUnitEndpoint

type UpdateUnitEndpoint struct{}

Partially updates a unit owned by your account.

System units cannot be modified, and a unit's dimension is fixed once it is created.

func (*UpdateUnitEndpoint) Materialize

type UpdateUnitRequest

type UpdateUnitRequest struct {
	// Unit ID.
	UnitID string `path:"id" validate:"required"`
	// Display name of the unit.
	//
	// Must be unique within the account.
	Name field.Optional[string] `json:"name,omitzero" validate:"omitempty,max=255"`
	// Short abbreviation for the unit.
	//
	// Must be unique within the account.
	Abbreviation field.Optional[string] `json:"abbreviation,omitzero" validate:"omitempty"`
	// Numerator of the ratio that converts a quantity in this unit into the dimension's base unit.
	//
	// A quantity is converted with `value × (ratio_numerator / ratio_denominator) + (offset_numerator / offset_denominator)`.
	RatioNumerator field.Optional[string] `json:"ratio_numerator,omitzero" validate:"omitempty,decimal" format:"decimal"`
	// Denominator of the ratio that converts a quantity in this unit into the dimension's base unit.
	//
	// Must not be zero.
	RatioDenominator field.Optional[string] `json:"ratio_denominator,omitzero" validate:"omitempty,nonzero_decimal" format:"decimal"`
	// Numerator of the conversion offset, applied after the ratio for scales that do not share a zero point, such as temperature.
	OffsetNumerator field.Optional[string] `json:"offset_numerator,omitzero" validate:"omitempty,decimal" format:"decimal"`
	// Denominator of the conversion offset.
	//
	// Must not be zero.
	OffsetDenominator field.Optional[string] `json:"offset_denominator,omitzero" validate:"omitempty,nonzero_decimal" format:"decimal"`
}

Request to partially update a unit.

func (*UpdateUnitRequest) SchemaExample

func (*UpdateUnitRequest) SchemaExample() any

type UpsertUnitInput

type UpsertUnitInput struct {
	// Display name of the unit (e.g. "Gram"). A row matching a system unit fails — system
	// units cannot be modified.
	Name string `json:"name" validate:"required,max=255"`
	// Short abbreviation for the unit (e.g. "g"). Also used for matching — see `name`.
	Abbreviation string `json:"abbreviation" validate:"required,max=191"`
	// Unit dimension code. Create-only — a row that changes an existing unit's dimension fails.
	Type constants.UnitType `json:"type" validate:"required"`
	// Conversion ratio numerator relative to the base unit, as a decimal string.
	RatioNumerator string `json:"ratio_numerator" validate:"required" format:"decimal"`
	// Conversion ratio denominator relative to the base unit, as a decimal string.
	RatioDenominator string `json:"ratio_denominator" validate:"required" format:"decimal"`
	// Conversion offset numerator, as a decimal string.
	OffsetNumerator string `json:"offset_numerator" validate:"required" format:"decimal"`
	// Conversion offset denominator, as a decimal string.
	OffsetDenominator string `json:"offset_denominator" validate:"required" format:"decimal"`
	// Whether the unit is its dimension's base unit. Bulk upsert never creates a base unit
	// and rejects a change to an existing one.
	IsBaseUnit bool `json:"is_base_unit"`
}

UpsertUnitInput is the input for a single unit in a bulk upsert operation.

type ValidateUnitsEndpoint

type ValidateUnitsEndpoint struct{}

Resolves a batch of unit abbreviations to the units they refer to.

Each abbreviation is matched case-insensitively against the account's units, including shared system units, and returned under the key it was sent with. Keys whose abbreviation matches no unit are omitted from the response, which is how invalid abbreviations are identified.

type ValidateUnitsRequest

type ValidateUnitsRequest struct {
	// Abbreviations to look up, keyed by any identifier you choose.
	//
	// The keys are echoed back on the matching units, so a spreadsheet import can use row numbers or column names to trace each abbreviation back to its source.
	UnitMap map[string]string `json:"unit_map" validate:"required"`
}

Request to validate units by abbreviation.

func (*ValidateUnitsRequest) SchemaExample

func (*ValidateUnitsRequest) SchemaExample() any

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL