diff --git a/http/good.go b/http/good.go index bb10719..2683eaf 100644 --- a/http/good.go +++ b/http/good.go @@ -37,7 +37,12 @@ func addGood(w http.ResponseWriter, r *http.Request) { } var obj models.Good - lib.Read(r, &obj) + err = lib.Read(r, &obj) + if err != nil { + log.Warn(err.Error()) + http.Error(w, err.Error(), http.StatusBadRequest) + return + } obj.ProductID = id diff --git a/lib/http/io.go b/lib/http/io.go index 6a059e7..e6eb562 100644 --- a/lib/http/io.go +++ b/lib/http/io.go @@ -5,12 +5,13 @@ import ( "encoding/json" "errors" "net/http" + "strings" ) // Function to read data from a http request via json format (input) func Read(r *http.Request, to interface{}) (err error) { - if r.Header.Get("Content-Type") != "application/json" { - err = errors.New("no json data recived") + if !strings.Contains(r.Header.Get("Content-Type"), "application/json") { + err = errors.New("no json request recieved") return } err = json.NewDecoder(r.Body).Decode(to) diff --git a/models/good.go b/models/good.go index 976bc57..2d73b93 100644 --- a/models/good.go +++ b/models/good.go @@ -12,19 +12,19 @@ import ( // Goods managed in this stock microservice type Good struct { - ID int64 - ProductID int64 - Position string - Comment string - FouledAt *time.Time + ID int64 `json:"id"` + ProductID int64 `json:"product_id"` + Position string `json:"position"` + Comment string `json:"comment"` + FouledAt *time.Time `json:"fouled_at"` - RecievedAt *time.Time `sql:"default:current_timestamp"` + RecievedAt *time.Time `sql:"default:current_timestamp" json:"recieved_at"` // Make it temporary unusable - LockedAt *time.Time - LockedSecret string `json:"-"` + LockedAt *time.Time `json:"-"` + LockedSecret string `json:"-"` // Make it unusable - DeletedAt *time.Time - Sended bool + DeletedAt *time.Time `json:"-"` + Sended bool `json:"-"` } // Function to enerate a database and select locked goods with a filter diff --git a/webroot/index.html b/webroot/index.html index 03a96bb..747e3a6 100644 --- a/webroot/index.html +++ b/webroot/index.html @@ -9,11 +9,16 @@ Stock Admin -