diff --git a/.gitignore b/.gitignore index ac492e9..9e216d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -cmd/review/config.conf +cmd/stock/config.conf .idea/ diff --git a/.travis.yml b/.travis.yml index d1835e9..cb6289e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,4 @@ install: - go get "golang.org/x/tools/cmd/cover" script: - ./.test-coverage - - go install github.com/genofire/hs_master-kss-monolith/cmd/review + - go install github.com/genofire/hs_master-kss-monolith/cmd/stock diff --git a/README.md b/README.md index 209af12..04f959f 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,17 @@ -# Review-Microservice +# Stock-Microservice This is a microservice cutted out of a [Monolith](https://gitlab.com/matthiasstock/monolith). [![Build Status](https://travis-ci.org/genofire/hs_master-kss-monolith.svg?branch=master)](https://travis-ci.org/genofire/hs_master-kss-monolith) [![Coverage Status](https://coveralls.io/repos/github/genofire/hs_master-kss-monolith/badge.svg?branch=master)](https://coveralls.io/github/genofire/hs_master-kss-monolith?branch=master) -## Features of this review mircoservice -* with firstname, lastname, stars and text -* without login -* binded by a productid +## Features of this stock mircoservice +* save goods via product with timestamp, if it was found and there place in a warehouse (in the admin front end) + * add new goods + * manual delete of goods, e.g if the good get fouled + * remove a good from warehouse, if it was send to customer + * lock goods, if a customer has it in his bill (and release after time x, if it was not send to customer) +* customer front end + * display availability with something like a traffic lights + +### Nice to have / Can-But-Must-Not-Feature +* display of statistics values like how many goods was removed in a time range +* traffic light in admin front end of goods which get fouled in next time or is already fouled diff --git a/cmd/review/main.go b/cmd/stock/main.go similarity index 100% rename from cmd/review/main.go rename to cmd/stock/main.go diff --git a/http/review.go b/http/good.go similarity index 80% rename from http/review.go rename to http/good.go index 806b865..b6450f2 100644 --- a/http/review.go +++ b/http/good.go @@ -12,7 +12,7 @@ import ( "github.com/genofire/hs_master-kss-monolith/models" ) -func listReview(w http.ResponseWriter, r *http.Request) { +func listGoods(w http.ResponseWriter, r *http.Request) { log := logger.HTTP(r) id, err := strconv.ParseInt(pat.Param(r, "productid"), 10, 64) if err != nil { @@ -21,11 +21,11 @@ func listReview(w http.ResponseWriter, r *http.Request) { return } log = log.WithField("productid", id) - var list []*models.Review + var list []*models.Good result := database.Read.Where("product_id = ?", id).Find(&list) if result.RowsAffected == 0 { - log.Warn("no reviews found") - http.Error(w, "no reviews found", http.StatusNotFound) + log.Warn("no goods found") + http.Error(w, "no goods found", http.StatusNotFound) return } lib.Write(w, list) diff --git a/http/review_test.go b/http/good_test.go similarity index 58% rename from http/review_test.go rename to http/good_test.go index a1bd9fb..cfe7f34 100644 --- a/http/review_test.go +++ b/http/good_test.go @@ -10,27 +10,24 @@ import ( "github.com/genofire/hs_master-kss-monolith/test" ) -func TestReview(t *testing.T) { +func TestGood(t *testing.T) { assertion, router := test.Init(t) BindAPI(router) session := test.NewSession(router) - result, w := session.JSONRequest("GET", "/api/review/a", nil) + result, w := session.JSONRequest("GET", "/api/good/a", nil) assertion.Equal(http.StatusNotAcceptable, w.StatusCode) - result, w = session.JSONRequest("GET", "/api/review/1", nil) + result, w = session.JSONRequest("GET", "/api/good/1", nil) assertion.Equal(http.StatusNotFound, w.StatusCode) - database.Write.Create(&models.Review{ - ProductID: 3, - FirstName: "Max", - LastName: "Mustmann", - RatingStars: 3, - Text: "blub", + database.Write.Create(&models.Good{ + ProductID: 3, + Comment: "blub", }) - result, w = session.JSONRequest("GET", "/api/review/3", nil) + result, w = session.JSONRequest("GET", "/api/good/3", nil) assertion.Equal(http.StatusOK, w.StatusCode) assertion.Len(result, 1) diff --git a/http/main.go b/http/main.go index d58b990..25f413c 100644 --- a/http/main.go +++ b/http/main.go @@ -7,5 +7,5 @@ import ( func BindAPI(router *goji.Mux) { router.HandleFunc(pat.Get("/api/status"), status) - router.HandleFunc(pat.Get("/api/review/:productid"), listReview) + router.HandleFunc(pat.Get("/api/good/:productid"), listGoods) } diff --git a/http/status.go b/http/status.go index 6e89321..0d40d1c 100644 --- a/http/status.go +++ b/http/status.go @@ -11,9 +11,16 @@ import ( func status(w http.ResponseWriter, r *http.Request) { log := logger.HTTP(r) - var reviews []*models.Review + var good []*models.Good var count int64 - database.Read.Find(&reviews).Count(&count) - lib.Write(w, map[string]interface{}{"status": "running", "review_count": count}) + var avg int64 + database.Read.Find(&good).Count(&count) //.Avg(&avg) + lib.Write(w, map[string]interface{}{ + "status": "running", + "good": map[string]interface{}{ + "count": count, + "avg": avg, + }, + }) log.Info("done") } diff --git a/http/status_test.go b/http/status_test.go index 0ec61db..c7b6d6e 100644 --- a/http/status_test.go +++ b/http/status_test.go @@ -17,7 +17,8 @@ func TestStatus(t *testing.T) { result := r.(map[string]interface{}) assertion.Equal(http.StatusOK, w.StatusCode) assertion.Equal("running", result["status"]) - assertion.Equal(float64(0), result["review_count"]) + good := result["good"].(map[string]interface{}) + assertion.Equal(float64(0), good["count"]) test.Close() } diff --git a/models/good.go b/models/good.go new file mode 100644 index 0000000..e72f081 --- /dev/null +++ b/models/good.go @@ -0,0 +1,13 @@ +package models + +import "github.com/genofire/hs_master-kss-monolith/lib/database" + +type Good struct { + ID int64 + ProductID int64 + Comment string +} + +func init() { + database.AddModel(&Good{}) +} diff --git a/models/product.go b/models/product.go new file mode 100644 index 0000000..f7ee002 --- /dev/null +++ b/models/product.go @@ -0,0 +1,5 @@ +package models + +func ProductExists(id int64) (bool, error) { + return true, nil +} diff --git a/models/review.go b/models/review.go deleted file mode 100644 index 3fe3f44..0000000 --- a/models/review.go +++ /dev/null @@ -1,28 +0,0 @@ -package models - -import "github.com/genofire/hs_master-kss-monolith/lib/database" - -type Review struct { - ID int64 - ProductID int64 - LocaleLanguage string - FirstName string - LastName string - RatingStars int64 - Text string -} - -func (r *Review) DisplayName() string { - if len(r.FirstName) > 0 { - if len(r.LastName) > 0 { - last := []byte(r.LastName) - return r.FirstName + " " + string(last[0]) + "." - } - return r.FirstName - } - return "Anonymous" -} - -func init() { - database.AddModel(&Review{}) -} diff --git a/models/review_test.go b/models/review_test.go deleted file mode 100644 index 7c48eab..0000000 --- a/models/review_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package models - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestDisplayName(t *testing.T) { - assert := assert.New(t) - - r := Review{} - assert.Equal("", r.FirstName, "wrong firstname") - assert.Equal("", r.LastName, "wrong lastname") - assert.Equal("Anonymous", r.DisplayName(), "No name") - - r.FirstName = "Max" - assert.Equal("Max", r.FirstName, "wrong firstname") - assert.Equal("", r.LastName, "wrong lastname") - assert.Equal("Max", r.DisplayName(), "Only Firstname") - - r.LastName = "Mustermann" - assert.Equal("Max", r.FirstName, "wrong firstname") - assert.Equal("Mustermann", r.LastName, "wrong lastname") - assert.Equal("Max M.", r.DisplayName(), "Shorted Name") - - r.FirstName = "" - assert.Equal("", r.FirstName, "wrong firstname") - assert.Equal("Mustermann", r.LastName, "wrong lastname") - assert.Equal("Anonymous", r.DisplayName(), "displayname: no firstname") -}