コード例 #1
0
func (self *loadfriendsController) Get(sn *session.Session) {
	friend := new(model.Friend)
	ret_val := returnVal{}
	if !sn.IsLogin {
		ret_val.Status = Fail
		ret_val.Content = RequireLogin
	} else {
		if users, err := friend.LoadFriends(sn.Cache.Values.User_id); err != nil {
			ret_val.Status = Fail
			ret_val.Content = err.Error()
		} else {
			ret_val.Status = Success
			for _, value := range users {
				ret_val.Content += fmt.Sprintf("%d:%s=", value.Id, value.Username)
			}
		}
	}
	self.Controller.Respond(sn.ResponseWriter, "json", ret_val, nil)
}
コード例 #2
0
func (self *respondtorequestController) Post(sn *session.Session) {
	friend := new(model.Friend)
	ret_val := returnVal{}
	if !sn.IsLogin {
		ret_val.Status = Fail
		ret_val.Content = RequireLogin
	} else {
		if err := form2Struct(sn.Request.Form, friend); err != nil {
			ret_val.Status = Fail
			ret_val.Content = err.Error()
		} else {
			acceptOrDecline := sn.Request.FormValue("acceptOrDecline")
			friend.UserB = sn.Cache.Values.User_id
			if acceptOrDecline == "1" {
				if err := friend.Accept(); err != nil {
					ret_val.Status = Fail
					ret_val.Content = err.Error()
				} else {
					ret_val.Status = Success
				}
			} else {
				if err := friend.Decline(); err != nil {
					ret_val.Status = Fail
					ret_val.Content = err.Error()
				} else {
					ret_val.Status = Success
				}
			}
		}
	}
	self.Controller.Respond(sn.ResponseWriter, "json", ret_val, nil)
}
コード例 #3
0
func (self *makerequestController) Post(sn *session.Session) {
	friend := new(model.Friend)
	ret_val := returnVal{}
	if !sn.IsLogin {
		ret_val.Status = Fail
		ret_val.Content = RequireLogin
	} else {
		if err := form2Struct(sn.Request.Form, friend); err != nil {
			ret_val.Status = Fail
			ret_val.Content = err.Error()
		} else {
			friend.UserA = sn.Cache.Values.User_id
			if err := friend.MakeRequest(); err != nil {
				ret_val.Status = Fail
				ret_val.Content = err.Error()
			} else {
				ret_val.Status = Success
			}
		}
	}
	self.Controller.Respond(sn.ResponseWriter, "json", ret_val, nil)
}