unit

package
v1.0.68 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(db *gorm.DB) error

Migrate runs database migrations for the unit module.

Types

type UnitService

type UnitService struct {
	// contains filtered or unexported fields
}

func NewUnitService

func NewUnitService(db *gorm.DB, ctx *context.ERPContext) *UnitService

NewUnitService creates a new instance of UnitService with the given database connection and context.

func (*UnitService) CreateUnit

func (s *UnitService) CreateUnit(data *models.UnitModel) error

func (*UnitService) DeleteUnit

func (s *UnitService) DeleteUnit(id string) error

DeleteUnit deletes an existing unit from the database.

The function takes a unit ID and deletes the associated unit from the database. It returns an error if the deletion of the unit fails.

func (*UnitService) GetUnitByID

func (s *UnitService) GetUnitByID(id string) (*models.UnitModel, error)

GetUnitByID retrieves a unit by its ID.

The function takes a unit ID as a string and returns a pointer to a UnitModel containing the unit details. It returns an error if the retrieval operation fails.

func (*UnitService) GetUnitByName

func (s *UnitService) GetUnitByName(name string) (*models.UnitModel, error)

GetUnitByName retrieves a unit from the database by its name.

It takes a name as input and returns a pointer to a UnitModel and an error. If the unit with the given name is not found, the function creates a new unit with that name and saves it in the database. If the operation is successful, the error is nil. Otherwise, the error contains information about what went wrong.

func (*UnitService) GetUnits

func (s *UnitService) GetUnits(request http.Request, search string) (paginate.Page, error)

GetUnits retrieves a paginated list of units from the database.

It takes an HTTP request and a search query string as input. The method uses GORM to query the database for units, applying the search query to the name, code, and description fields. If the request contains a company ID header, the method filters the result by the company ID or includes entries with a null company ID. The function utilizes pagination to manage the result set and applies any necessary request modifications using the utils.FixRequest utility.

The function returns a paginated page of UnitModel and an error if the operation fails.

func (*UnitService) UpdateUnit

func (s *UnitService) UpdateUnit(id string, data *models.UnitModel) error

UpdateUnit updates an existing unit in the database.

The function takes a unit ID and a pointer to a UnitModel, which contains the data for the updated unit. It returns an error if the update of the unit fails.

Jump to

Keyboard shortcuts

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