func (i *AclInter) scopeModel(acl *domain.Acl) error { acl.CreatedAt = time.Time{} acl.UpdatedAt = time.Time{} acl.AclMappings = []domain.AclMapping{} return nil }
func (r *AclRepo) UpdateByID(id int, acl *domain.Acl, context usecases.QueryContext) (*domain.Acl, error) { query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations) if err != nil { return nil, internalerrors.DatabaseError } dbName := utils.ToDBName("acls") oldAcl := &domain.Acl{} err = query.Where(dbName+".id = ?", id).First(oldAcl).Error if err != nil { if strings.Contains(err.Error(), "record not found") { return nil, internalerrors.NotFound } return nil, internalerrors.DatabaseError } acl.ID = oldAcl.ID acl.CreatedAt = oldAcl.CreatedAt err = r.store.GetDB().Save(&acl).Error if err != nil { if strings.Contains(err.Error(), "constraint") { return nil, internalerrors.NewViolatedConstraint(err.Error()) } return nil, internalerrors.DatabaseError } return acl, nil }