Example #1
0
func (r *AclMappingRepo) UpdateByID(id int, aclMapping *domain.AclMapping,
	context usecases.QueryContext) (*domain.AclMapping, error) {

	query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations)
	if err != nil {
		return nil, internalerrors.DatabaseError
	}

	dbName := utils.ToDBName("aclMappings")
	oldAclMapping := &domain.AclMapping{}

	err = query.Where(dbName+".id = ?", id).First(oldAclMapping).Error
	if err != nil {
		if strings.Contains(err.Error(), "record not found") {
			return nil, internalerrors.NotFound
		}

		return nil, internalerrors.DatabaseError
	}

	aclMapping.ID = oldAclMapping.ID
	aclMapping.CreatedAt = oldAclMapping.CreatedAt

	err = r.store.GetDB().Save(&aclMapping).Error
	if err != nil {
		if strings.Contains(err.Error(), "constraint") {
			return nil, internalerrors.NewViolatedConstraint(err.Error())
		}

		return nil, internalerrors.DatabaseError
	}

	return aclMapping, nil
}
Example #2
0
func (i *AclMappingInter) scopeModel(aclMapping *domain.AclMapping) error {
	aclMapping.CreatedAt = time.Time{}
	aclMapping.UpdatedAt = time.Time{}
	aclMapping.Acl = domain.Acl{}
	aclMapping.Role = domain.Role{}

	return nil
}