utils

package
v0.0.0-...-1edcefc Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: GPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultPage Set default page to 1
	DefaultPage int64 = 1
	// DefaultLimit Set default max limit to 20
	DefaultLimit int64 = 20
)

Functions

func AddChangelog

func AddChangelog[T any](fieldName string, oldValue, newValue *T, changes *[]models.ChangeLog)

func AddChangelogForObligationClassification

func AddChangelogForObligationClassification(tx *gorm.DB, userId uuid.UUID, oldObClassification, newObClassification *models.ObligationClassification) error

func AddChangelogForObligationType

func AddChangelogForObligationType(tx *gorm.DB, userId uuid.UUID, oldObType, newObType *models.ObligationType) error

func AddChangelogsForLicense

func AddChangelogsForLicense(tx *gorm.DB, userId uuid.UUID,
	newLicense, oldLicense *models.LicenseDB) error

AddChangelogsForLicense adds changelogs for the updated fields on license update

func AddChangelogsForUser

func AddChangelogsForUser(tx *gorm.DB, userId uuid.UUID,
	newUser, oldUser *models.User) error

AddChangelogsForUser adds changelogs for the updated fields on user update

func GetAuditEntity

func GetAuditEntity(c *gin.Context, audit *models.Audit) error

GetAuditEntity is an utility function to fetch obligation or license associated with an audit

func GetKid

func GetKid(token string) (string, error)

https://github.com/lestrrat-go/jwx/discussions/547 Get kid field value from JWS Header

func HashPassword

func HashPassword(user *models.User) error

HashPassword hashes the password of the user using bcrypt. It also trims the username and escapes the HTML characters.

func ParseIdToInt

func ParseIdToInt(c *gin.Context, id string, idType string) (int64, error)

ParseIdToInt convert the string ID from gin.Context to an integer and throw error if conversion fails. Also, update the gin.Context with REST API error.

func PerformLicenseMapActions

func PerformLicenseMapActions(tx *gorm.DB, userId uuid.UUID, license *models.LicenseDB, newObligationIds []uuid.UUID) []error

PerformLicenseMapActions replaces current associated obligations with the list of obligations whose ids are provided in the newObligationIds

func PerformObligationMapActions

func PerformObligationMapActions(tx *gorm.DB, userId uuid.UUID, obligation *models.Obligation, newLicenseIds []uuid.UUID) []error

PerformObligationMapActions replaces current associated licenses with the list of licenses whose ids are provided in the newLicenseIds.

func Populatedb

func Populatedb(datafile string)

Populatedb populates the database with license data from a JSON file.

func PreparePaginateResponse

func PreparePaginateResponse(c *gin.Context, query *gorm.DB,
	responseModel interface{}) models.PaginationInput

PreparePaginateResponse prepares the pagination response for the API. It gets the count of total rows and sets the pagination parameters, also updates the query limit and offset and update the "paginationMeta" and "responseModel" in gin.Context for middleware to process.

func SetSimilarityThreshold

func SetSimilarityThreshold()

SetSimilarityThreshold parses the env var and sets the threshold in Postgres.

func ToggleObligationClassificationActiveStatus

func ToggleObligationClassificationActiveStatus(userId uuid.UUID, tx *gorm.DB, obClassification *models.ObligationClassification) error

func ToggleObligationTypeActiveStatus

func ToggleObligationTypeActiveStatus(userId uuid.UUID, tx *gorm.DB, obType *models.ObligationType) error

func VerifyPassword

func VerifyPassword(inputPassword, dbPassword string) error

VerifyPassword compares the input password with the password stored in the database. Returns nil on success, or an error on failure.

Types

type LicenseImportStatusCode

type LicenseImportStatusCode int

LicenseImportStatusCode is internally used for checking status of a license import

const (
	IMPORT_FAILED LicenseImportStatusCode = iota + 1
	IMPORT_LICENSE_CREATED
	IMPORT_LICENSE_UPDATED
	IMPORT_LICENSE_CREATE_OBLIGATION_ASSOCIATION_FAILED
	IMPORT_LICENSE_UPDATE_OBLIGATION_ASSOCIATION_FAILED
)

Status codes covering various scenarios that can occur on a license import

func InsertOrUpdateLicenseOnImport

func InsertOrUpdateLicenseOnImport(lic *models.LicenseImportDTO, userId uuid.UUID) (string, LicenseImportStatusCode)

type ObligationFieldCreateStatusCode

type ObligationFieldCreateStatusCode int

ObligationTypeStatusCode is internally used for checking status of a obligation type creation

const (
	CREATE_FAILED ObligationFieldCreateStatusCode = iota + 1
	VALIDATION_FAILED
	CONFLICT
	CONFLICT_ACTIVATION_FAILED
	CREATED
)

Status codes covering various scenarios that can occur on a license import

func CreateObClassification

func CreateObClassification(obClassification *models.ObligationClassification, userId uuid.UUID) (error, ObligationFieldCreateStatusCode)

func CreateObType

func CreateObType(obType *models.ObligationType, userId uuid.UUID) (error, ObligationFieldCreateStatusCode)

Jump to

Keyboard shortcuts

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