当前位置: 首页>>代码示例>>Golang>>正文


Golang adapter.WisplyError类代码示例

本文整理汇总了Golang中github.com/cristian-sima/Wisply/models/adapter.WisplyError的典型用法代码示例。如果您正苦于以下问题:Golang WisplyError类的具体用法?Golang WisplyError怎么用?Golang WisplyError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WisplyError类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CreateProgram

// CreateProgram adds a new program into database
func CreateProgram(details map[string]interface{}) (adapter.WisplyError, error) {
	problems := adapter.WisplyError{}
	result := hasValidProgramModifyDetails(details)
	if !result.IsValid {
		problems.Data = result
		return problems, errors.New("Invalid details for the program")
	}
	fieldList := "`institution`, `title`, `code`, `year`, `ucas_code`, `level`, `content`, `subject`"
	questions := "?, ?, ?, ?, ?, ?, ?, ?"
	sql := "INSERT INTO `institution_program` (" + fieldList + ") VALUES (" + questions + ")"
	query, err := database.Connection.Prepare(sql)

	if err != nil {
		return problems, err
	}
	title := details["program-title"].(string)
	code := details["program-code"].(string)
	year := details["program-year"].(string)
	institution := details["program-institution"].(int)
	ucasCode := details["program-ucas-code"].(string)
	level := details["program-level"].(string)
	content := details["program-content"].(string)
	subject := details["program-subject"].(string)
	_, err = query.Exec(institution, title, code, year, ucasCode, level, content, subject)

	return problems, err
}
开发者ID:cristian-sima,项目名称:Wisply,代码行数:28,代码来源:program.go

示例2: Try

// Try It tries to log in the username
func (login *Login) Try(loginDetails map[string]interface{}) (adapter.WisplyError, error) {

	deleteOldTokens()

	thinkMessage := "We think the email or the password were not valid."
	genericMessage := "There was a problem while login. " + thinkMessage

	problem := adapter.WisplyError{}
	result := isValidLogin(loginDetails)
	if !result.IsValid {
		problem.Data = result
		fmt.Println(result.Errors)
		return problem, errors.New("Error")
	}

	email := loginDetails["email"].(string)

	account, err := GetAccountByEmail(email)
	if err != nil {
		problem.Message = genericMessage
		return problem, errors.New(genericMessage)
	}

	passwordString := loginDetails["password"].(string)
	validPassword := checkPasswordIsCorrect(account.Password, passwordString)

	if !validPassword {
		problem.Message = genericMessage
		return problem, errors.New(genericMessage)
	}

	return problem, nil
}
开发者ID:cristian-sima,项目名称:Wisply,代码行数:34,代码来源:login.go

示例3: InsertNewInstitution

// InsertNewInstitution tries to create a new institution
func InsertNewInstitution(institutionDetails map[string]interface{}) (adapter.WisplyError, error) {

	problem := adapter.WisplyError{}

	result := hasValidInstitutionInsertDetails(institutionDetails)
	if !result.IsValid {
		problem.Data = result
		return problem, errors.New("Error")
	}

	name := institutionDetails["name"].(string)
	description := institutionDetails["description"].(string)
	url := institutionDetails["url"].(string)
	logoURL := institutionDetails["logoURL"].(string)
	wikiURL := institutionDetails["wikiURL"].(string)
	wikiID := institutionDetails["wikiID"].(string)

	sql := "INSERT INTO `institution` (`name`, `description`, `url`, `logo_URL`, `wiki_URL`, `wiki_ID`) VALUES (?, ?, ?, ?, ?, ?)"
	query, err := database.Connection.Prepare(sql)
	query.Exec(name, description, url, logoURL, wikiURL, wikiID)

	if err != nil {
		problem.Message = "No institution like that"
		return problem, errors.New("Error")
	}

	return problem, nil
}
开发者ID:cristian-sima,项目名称:Wisply,代码行数:29,代码来源:main.go

示例4: InsertNewRepository

// InsertNewRepository tries to create a new repository
func InsertNewRepository(repositoryDetails map[string]interface{}) (adapter.WisplyError, error) {

	problem := adapter.WisplyError{}

	// check Institution

	_, errInst := NewInstitution(repositoryDetails["institution"].(string))

	if errInst != nil {
		problem.Message = "This institution does not exist"
		return problem, errors.New("Error")
	}

	result := hasValidInsertDetails(repositoryDetails)
	if !result.IsValid {
		problem.Data = result
		return problem, errors.New("Error")
	}

	name := repositoryDetails["name"].(string)
	description := repositoryDetails["description"].(string)
	url := repositoryDetails["url"].(string)
	institutionID := repositoryDetails["institution"].(string)
	category := repositoryDetails["category"].(string)
	publicURL := repositoryDetails["public-url"].(string)
	sql := "INSERT INTO `repository` (`name`, `description`, `url`, `institution`, `category`, `public_url`) VALUES (?, ?, ?, ?, ?, ?)"
	query, err := database.Connection.Prepare(sql)
	query.Exec(name, description, url, institutionID, category, publicURL)
	if err != nil {
		problem.Message = "No repository like that"
		return problem, errors.New("Error")
	}

	return problem, nil
}
开发者ID:cristian-sima,项目名称:Wisply,代码行数:36,代码来源:main.go

示例5: DisplayError

// DisplayError shows a complex error message
// (ussually after the validation of fields)
func (controller *Message) DisplayError(err adapter.WisplyError) {
	content := err.GetMessage()
	if err.Data != nil {
		language := beego.AppConfig.String("language")
		controller.Data["validationFailed"] = true
		controller.Data["validationErrors"] = err.Data.TranslateTo(language)
	}
	controller.displayMessage("error", content)
}
开发者ID:cristian-sima,项目名称:Wisply,代码行数:11,代码来源:message.go

示例6: Modify

// Modify changes the details of the institution
func (institution *Institution) Modify(institutionDetails map[string]interface{}) (adapter.WisplyError, error) {
	var problem = adapter.WisplyError{}
	result := hasValidInstitutionModifyDetails(institutionDetails)
	if !result.IsValid {
		problem.Data = result
		return problem, errors.New("It does not have valid details")
	}
	err := institution.updateInstitutionInDatabase(institutionDetails)
	return problem, err
}
开发者ID:cristian-sima,项目名称:Wisply,代码行数:11,代码来源:institution.go

示例7: Modify

// Modify changes the details of the repository
func (repository *Repository) Modify(repositoryDetails map[string]interface{}) (adapter.WisplyError, error) {
	var problem = adapter.WisplyError{}
	result := hasValidProgramModifyDetails(repositoryDetails)
	if !result.IsValid {
		problem.Data = result
		return problem, errors.New("It does not have valid details")
	}
	err := repository.updateDatabase(repositoryDetails)
	return problem, err
}
开发者ID:cristian-sima,项目名称:Wisply,代码行数:11,代码来源:repository.go

示例8: Try

// Try It tries to create a new account
func (register *Register) Try(userDetails map[string]interface{}) (adapter.WisplyError, error) {
	var problem = adapter.WisplyError{}

	result := isValidRegister(userDetails)
	if !result.IsValid {
		problem.Data = result
		return problem, errors.New("Error")
	}

	email := userDetails["email"].(string)
	emailUsed := register.checkEmailExists(email)
	if emailUsed {
		problem.Message = "Hmmm, the email " + email + " is already used."
		return problem, errors.New("Error")
	}

	register.createNewAccount(userDetails)

	return problem, nil
}
开发者ID:cristian-sima,项目名称:Wisply,代码行数:21,代码来源:register.go

示例9: Modify

// Modify changes the details of the module
func (module Module) Modify(details map[string]interface{}) (adapter.WisplyError, error) {
	problems := adapter.WisplyError{}
	result := hasValidModuleModifyDetails(details)
	if !result.IsValid {
		problems.Data = result
		return problems, errors.New("Problem with the fields")
	}
	setClause := "SET `title`=?, `content`=?, `code`=?, `credits`=?, `year`=?"
	whereClause := "WHERE `id`= ?"
	sql := "UPDATE `institution_module` " + setClause + " " + whereClause
	query, err := database.Connection.Prepare(sql)
	if err != nil {
		fmt.Println(err)
	}
	title := details["module-title"].(string)
	content := details["module-content"].(string)
	code := details["module-code"].(string)
	credits := details["module-credits"].(string)
	year := details["module-year"].(string)
	query.Exec(title, content, code, credits, year, module.id)
	return problems, err
}
开发者ID:cristian-sima,项目名称:Wisply,代码行数:23,代码来源:module.go

示例10: CreateModule

// CreateModule adds a new module into database
func CreateModule(details map[string]interface{}) (adapter.WisplyError, error) {
	problems := adapter.WisplyError{}
	result := hasValidModuleModifyDetails(details)
	if !result.IsValid {
		problems.Data = result
		return problems, errors.New("Invalid details for the module")
	}
	fieldList := "`title`, `content`, `code`, `credits`, `year`, `institution`"
	questions := "?, ?, ?, ?, ?, ?"
	sql := "INSERT INTO `institution_module` (" + fieldList + ") VALUES (" + questions + ")"
	query, err := database.Connection.Prepare(sql)

	if err != nil {
		return problems, err
	}
	title := details["module-title"].(string)
	content := details["module-content"].(string)
	code := details["module-code"].(string)
	credits := details["module-credits"].(string)
	year := details["module-year"].(string)
	institution := details["module-institution"].(int)
	_, err = query.Exec(title, content, code, credits, year, institution)
	return problems, err
}
开发者ID:cristian-sima,项目名称:Wisply,代码行数:25,代码来源:module.go

示例11: Modify

// Modify changes the details of the program
func (program Program) Modify(details map[string]interface{}) (adapter.WisplyError, error) {
	problems := adapter.WisplyError{}
	result := hasValidProgramModifyDetails(details)
	if !result.IsValid {
		problems.Data = result
		return problems, errors.New("Problem with the fields")
	}
	setClause := "SET `title`=?, `code`=?, `year`=?, `ucas_code`=?, `level`=?, `content`=?, `subject`=? "
	whereClause := "WHERE `id`= ?"
	sql := "UPDATE `institution_program` " + setClause + " " + whereClause
	query, err := database.Connection.Prepare(sql)
	if err != nil {
		fmt.Println(err)
	}
	title := details["program-title"].(string)
	code := details["program-code"].(string)
	year := details["program-year"].(string)
	ucasCode := details["program-ucas-code"].(string)
	level := details["program-level"].(string)
	content := details["program-content"].(string)
	subject := details["program-subject"].(string)
	query.Exec(title, code, year, ucasCode, level, content, subject, program.id)
	return problems, err
}
开发者ID:cristian-sima,项目名称:Wisply,代码行数:25,代码来源:program.go


注:本文中的github.com/cristian-sima/Wisply/models/adapter.WisplyError类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。