コード例 #1
0
ファイル: account_transactions.go プロジェクト: sporto/kic
func (c *AccountTransactions) Create(ctx context.Context) (err error) {
	accountId := ctx.PathValue("account_id")
	data, err := ctx.RequestData()

	if err != nil {
		return goweb.API.RespondWithError(ctx, http.StatusInternalServerError, err.Error())
	}

	dataMap := data.(map[string]interface{})

	transaction := models.Transaction{
		AccountId: accountId,
		Debit:     dataMap["debit"].(float64),
		Credit:    dataMap["credit"].(float64),
		Kind:      dataMap["kind"].(string),
	}

	createServ := &transactions.CreateServ{}
	transactionOut, err := createServ.Run(c.DbSession, transaction)
	if err != nil {
		log.Print(err)
		return goweb.API.RespondWithError(ctx, http.StatusInternalServerError, err.Error())
	}

	return goweb.API.RespondWithData(ctx, transactionOut)
}
コード例 #2
0
ファイル: checks.go プロジェクト: AlexsJones/crashmat
func CheckHeaderIsValidWithBasicAuth(c context.Context) (didpass bool, applicationid int, username string, password string) {

	data, dataError := c.RequestData()
	if dataError != nil {
		log.Println("Data error %s", dataError.Error())
		return false, 0, "", ""
	}

	dataMap := data.(map[string]interface{})

	appd, ok := dataMap["applicationid"]

	if !ok {
		log.Println("Header missing applicationid")
		return false, 0, "", ""
	}

	basicd, ok := dataMap["authorization"]

	if !ok {
		log.Println("Header missing authorization")
		return false, 0, "", ""
	}
	if basicd != "Basic" {
		log.Println("Header missing basic Authorization")
		return false, 0, "", ""
	}

	userd, ok := dataMap["username"]

	if !ok {
		log.Println("Header missing username")
		return false, 0, "", ""
	}

	passd, ok := dataMap["password"]

	if !ok {
		log.Println("Header missing password")
		return false, 0, "", ""
	}

	appi, _ := strconv.Atoi(appd.(string))
	return true, appi, userd.(string), passd.(string)
}
コード例 #3
0
ファイル: checks.go プロジェクト: AlexsJones/crashmat
func CheckHeaderIsValidWithBasicAuthAndRawData(c context.Context) (didpass bool, applicationid int, username string, password string, raw string) {

	data, dataError := c.RequestData()
	if dataError != nil {
		log.Println("Data error %s", dataError.Error())
		return false, 0, "", "", ""
	}

	dataMap := data.(map[string]interface{})

	rawd, ok := dataMap["raw"]
	if !ok {
		log.Println("Header missing raw data")
		return false, 0, "", "", ""
	}
	valid, appid, userd, passd := CheckHeaderIsValidWithBasicAuth(c)
	return valid, appid, userd, passd, rawd.(string)
}
コード例 #4
0
ファイル: goweb-rest-api.go プロジェクト: plainme/powerapi
func (r *ThingsController) Create(ctx context.Context) error {

	data, dataErr := ctx.RequestData()

	if dataErr != nil {
		return goweb.API.RespondWithError(ctx, http.StatusInternalServerError, dataErr.Error())
	}

	dataMap := data.(map[string]interface{})

	thing := new(Thing)
	thing.Id = dataMap["Id"].(string)
	thing.Text = dataMap["Text"].(string)

	r.Things = append(r.Things, thing)

	return goweb.Respond.WithStatus(ctx, http.StatusCreated)

}
コード例 #5
0
ファイル: webgit.go プロジェクト: gustavodecarlo/vtex_trial
func (r *DevelopersController) Create(ctx context.Context) error {
	data, dataErr := ctx.RequestData()
	if dataErr != nil {
		return goweb.API.RespondWithError(ctx, http.StatusInternalServerError, dataErr.Error())
	}

	dataMap := data.(map[string]interface{})

	developer := new(Developer)
	developer.Id = dataMap["Id"].(float64)
	developer.Login = dataMap["Login"].(string)
	developer.Avatar_url = dataMap["Avatar_url"].(string)
	developer.Followers_url = dataMap["Followers_url"].(string)
	developer.Repos_url = dataMap["Repos_url"].(string)
	developer.Score = dataMap["Score"].(float64)
	developer.Price = dataMap["Price"].(float64)

	r.Developers = append(r.Developers, developer)
	return goweb.Respond.WithStatus(ctx, http.StatusCreated)
}
コード例 #6
0
ファイル: tracks_controller.go プロジェクト: ToQoz/Gokuraku
func (c *TracksController) Create(ctx context.Context) error {
	data, dataErr := ctx.RequestData()
	if dataErr != nil {
		return goweb.API.RespondWithError(ctx, http.StatusInternalServerError, dataErr.Error())
	}
	dataMap := data.(map[string]interface{})

	if dataMap["Url"] == nil {
		return goweb.API.RespondWithError(ctx, http.StatusInternalServerError, errors.New("URL required").Error())
	}

	track_url := dataMap["Url"].(string)
	track, err := track.CreateTrackFromUrl(track_url)

	if err != nil {
		log.Println(err.Error())
		return goweb.API.RespondWithError(ctx, http.StatusInternalServerError, err.Error())
	}

	return goweb.API.Respond(ctx, http.StatusCreated, track, nil)
}
コード例 #7
0
func (r *BooksController) Create(ctx context.Context) error {

	data, dataErr := ctx.RequestData()

	if dataErr != nil {
		return goweb.API.RespondWithError(ctx, http.StatusInternalServerError, dataErr.Error())
	}

	dataMap := data.(map[string]interface{})

	// map each value to Book Object
	Book := new(Book)
	Book.Id = dataMap["Id"].(string)
	Book.Title = dataMap["Title"].(string)
	Book.Author = dataMap["Author"].(string)
	Book.Price = dataMap["Price"].(string)

	r.Books = append(r.Books, Book)

	return goweb.Respond.WithStatus(ctx, http.StatusCreated)

}