Пример #1
0
func handleCreateMessageChain(w http.ResponseWriter, r *http.Request, ms *base.MessageStore) {
	inquirerId, err := strconv.Atoi(r.FormValue("inquirer_id"))
	if err != nil {
		w.WriteHeader(400)
		fmt.Fprintf(w, "Bad parameters")
		return
	}
	sellerId, err := strconv.Atoi(r.FormValue("seller_id"))
	if err != nil {
		w.WriteHeader(400)
		fmt.Fprintf(w, "Bad parameters")
		return
	}
	listingId, err := strconv.Atoi(r.FormValue("listing_id"))
	if err != nil {
		w.WriteHeader(400)
		fmt.Fprintf(w, "Bad parameters")
		return
	}
	content := r.FormValue("content")
	messageType := r.FormValue("msg_type")

	ms.CreateMessageChain(inquirerId, sellerId, listingId, content, messageType)
	fmt.Fprintf(w, "Created Chain %v", ms.MessageChains)
}
Пример #2
0
func handleSendMessage(w http.ResponseWriter, r *http.Request, ms *base.MessageStore) {
	senderId, err := strconv.Atoi(r.FormValue("sender_id"))
	if err != nil {
		w.WriteHeader(400)
		fmt.Fprintf(w, "Bad parameters")
		return
	}
	msgChainId, err := strconv.Atoi(r.FormValue("message_chain_id"))
	if err != nil {
		w.WriteHeader(400)
		fmt.Fprintf(w, "Bad parameters")
		return
	}
	content := r.FormValue("content")
	messageType := r.FormValue("msg_type")

	ms.SendMessage(senderId, msgChainId, content, messageType)
	fmt.Fprintf(w, "Message Sent %v", ms.MessageChains[msgChainId])
}