Unable to get a newly created coffee.
jamime opened this issue · 0 comments
jamime commented
After following the tutorial I decided to implement my own resource to create a coffee.
I installed the latest client which includes support for client.CreateCoffee
.
When creating a new coffee the api does not accept collection
, origin
or color
.
product-api-go/data/connection.go
Lines 430 to 431 in f7ef7a6
When attempting to get the new coffee the following error is raised by the api because the db fields are NULL.
docker_compose-api-1 | 2023-01-06T15:21:53.779Z [ERROR] Unable to get products from database: error="sql: Scan error on column index 3, name "collection": converting NULL to string is unsupported"
product-api-go/data/connection.go
Line 59 in f7ef7a6
Example
go get github.com/hashicorp-demoapp/hashicups-client-go@bd8bf734c61cc7f3863e53b2d6492d3b34797118
// hashicups/debug/debug.go
package main
import (
"encoding/json"
"fmt"
"strconv"
"github.com/hashicorp-demoapp/hashicups-client-go"
)
func main() {
username := "education"
password := "test123"
c, err := hashicups.NewClient(nil, &username, &password)
if err != nil {
fmt.Println(err)
return
}
coffee := hashicups.Coffee{
Name: "name",
Collection: "collection",
Origin: "origin",
Color: "color",
Price: 500,
Description: "description",
}
res, err := c.CreateCoffee(coffee, nil)
if err != nil {
fmt.Println(err)
return
}
tmp, _ := json.Marshal(res)
fmt.Println(string(tmp))
res2, err := c.GetCoffee(strconv.Itoa(res.ID))
if err != nil {
fmt.Println(err)
return
}
tmp, _ = json.Marshal(res2)
fmt.Println(string(tmp))
}
go run hashicups/debug/debug.go
{"id":27,"name":"","teaser":"","collection":"","origin":"","color":"","description":"","price":0,"image":"","ingredients":null}
status: 500, body: Unable to list products