-
Notifications
You must be signed in to change notification settings - Fork 148
integrate frontend service with rating service #581
Conversation
setup HTML templates to have dynamic values of the rating. modify home page and product page handlers to populate product rating(s).
make frontend service not to fail in CI workflow validation by: - defining RATING_SERVICE_ADDR environment variable - making sure that failed call to rating service does not fail GET / request to frontend.
3fd4b74
to
6eb6466
Compare
If you want to try the integration, you can access a test environment using http://35.225.4.62/. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too familiar with go, but overall this looks good to me. Left a couple small comments
} | ||
return nil | ||
} else { | ||
return errors.Errorf("unhandled response code %q", result.StatusCode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest treating any 2xx (or possibly 3xx) as success if there's no error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A question is what would be the right behavior regarding payload processing. Should I try to read and parse the payload the same way for all 2xx? Since many 3xx statuses imply redirect, should the code support?
WDYT to handle all 2xx responses by trying to parse the response and to keep 3xx handled the same way?
renderHTTPError(log, r, w, errors.New("product id not specified"), http.StatusBadRequest) | ||
return | ||
} | ||
rating, _ := strconv.ParseInt(r.FormValue("rating"), 10, 32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the meaning of 10 and 32 here? Perhaps, worth adding a comment if GO doesn't support named parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copy/pasted it from another method in this file:
cloud-ops-sandbox/src/frontend/handlers.go
Lines 174 to 176 in 6eb6466
func (fe *frontendServer) addToCartHandler(w http.ResponseWriter, r *http.Request) { | |
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger) | |
quantity, _ := strconv.ParseUint(r.FormValue("quantity"), 10, 32) |
Looked for this in the internet and it seems to be a usual practice.
Should we deal with this?
Setup HTML templates to have dynamic values of the rating.
Modify home page and product page handlers to populate product rating(s).
Add functionality to submit a new product rating.