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) }
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) }
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) }
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) }
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) }
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) }
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) }