コード例 #1
0
ファイル: enquire.go プロジェクト: henrydo/ags
func addProductToReviewboard(req *restful.Request, resp *restful.Response) {
	log.Debug("Try to add product to reviewboard")
	p := new(ReviewboardProduct)
	err := req.ReadEntity(&p)
	if err != nil {
		resp.WriteErrorString(http.StatusBadRequest, http.StatusText(http.StatusBadRequest))
		return
	}
	var id int64
	var ret int
	b, userid := auth.AuthHandler(req.Request, resp.ResponseWriter)
	if !b {
		log.Debug("This is a visitor")
		b, visitorid := auth.AuthVisitorHandler(req.Request, resp.ResponseWriter)
		if !b {
			id = auth.AddVisitorCookie(req.Request, resp.ResponseWriter)
		} else {
			id, _ = strconv.ParseInt(visitorid, 10, 64)
		}
		ret = dbAddProductToReviewboard(2, id, p)
	} else {
		id, err := strconv.ParseInt(userid, 10, 64)
		if err != nil {
			ret = http.StatusInternalServerError
		} else {
			ret = dbAddProductToReviewboard(1, id, p)
		}
	}

	if ret == http.StatusOK {
		resp.WriteHeader(http.StatusOK)
	} else {
		resp.WriteErrorString(ret, http.StatusText(ret))
	}
}
コード例 #2
0
ファイル: enquire.go プロジェクト: henrydo/ags
func getReviewboardDetail(req *restful.Request, resp *restful.Response) {
	log.Debug("Try to get reviewboard detail")
	b, userid := auth.AuthHandler(req.Request, resp.ResponseWriter)
	var ret int
	var ps []ReviewboardProduct
	c := new(Reviewboard)
	if !b {
		log.Debug("This is a visitor")
		ps, ret = getVisitorReviewboardDetail(req, resp)
		c.Identity = "Visitor"
		c.Products = ps
	} else {
		id, err := strconv.ParseInt(userid, 10, 64)
		if err != nil {
			ret = http.StatusInternalServerError
		} else {
			ps, ret = dbGetReviewboardDetail(1, id)
			c.Identity = "Customer"
			c.Products = ps
		}
	}

	if ret == http.StatusOK {
		resp.WriteEntity(c)
	} else {
		resp.WriteErrorString(ret, http.StatusText(ret))
	}
}