[TASK] switch from review to stock microservice
This commit is contained in:
parent
ea15b36a52
commit
66d6022d37
|
@ -1,2 +1,2 @@
|
|||
cmd/review/config.conf
|
||||
cmd/stock/config.conf
|
||||
.idea/
|
||||
|
|
|
@ -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
|
||||
|
|
18
README.md
18
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
|
||||
|
|
|
@ -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)
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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{})
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package models
|
||||
|
||||
func ProductExists(id int64) (bool, error) {
|
||||
return true, nil
|
||||
}
|
|
@ -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{})
|
||||
}
|
|
@ -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")
|
||||
}
|
Reference in New Issue