示例#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 getVisitorReviewboardDetail(req *restful.Request, resp *restful.Response) ([]ReviewboardProduct, int) {
	b, visitorid := auth.AuthVisitorHandler(req.Request, resp.ResponseWriter)
	if !b {
		log.Debug("Add a new visitor cookie")
		auth.AddVisitorCookie(req.Request, resp.ResponseWriter)
		return nil, http.StatusNotFound
	} else {
		log.Debug("Get detail for an old visitor, %d", visitorid)
		id, err := strconv.ParseInt(visitorid, 10, 64)
		if err != nil {
			return nil, http.StatusNotFound
		}
		return dbGetReviewboardDetail(2, id)
	}
}