ui/product.go
func (h *Handler) UpdateProduct(tkn string, product data.Product) error {
	logger := h.logger.Add("method", "UpdateProduct", "product", product)

	if !h.token.Check(tkn) {
		logger.Warn("access denied")
		return ErrAccessDenied
	}

	oldProduct := &data.Product{}
	if err := h.findByPrimaryKey(logger,
		ErrProductNotFound, oldProduct, product.ID); err != nil {
		return err
	}

	if product.Salt == 0 {
		product.Salt = oldProduct.Salt
	}

	if product.Password == "" {
		product.Password = oldProduct.Password
	}

	if product.ServiceEndpointAddress != nil &&
		!isValidSEAddress(*product.ServiceEndpointAddress) {
		return ErrBadServiceEndpointAddress
	}

	if err := update(logger, h.db.Querier, &product); err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	return nil
}
func (h *Handler) UpdateProduct(tkn string, product data.Product) error {
	logger := h.logger.Add("method", "UpdateProduct", "product", product)

	if !h.token.Check(tkn) {
		logger.Warn("access denied")
		return ErrAccessDenied
	}

	oldProduct := &data.Product{}
	if err := h.findByPrimaryKey(logger,
		ErrProductNotFound, oldProduct, product.ID); err != nil {
		return err
	}

	if product.Salt == 0 {
		product.Salt = oldProduct.Salt
	}

	if product.Password == "" {
		product.Password = oldProduct.Password
	}

	if product.ServiceEndpointAddress != nil &&
		!isValidSEAddress(*product.ServiceEndpointAddress) {
		return ErrBadServiceEndpointAddress
	}

	if err := update(logger, h.db.Querier, &product); err != nil {
		logger.Error(err.Error())
		return ErrInternal
	}

	return nil
}
// UpdateProduct updates a product.