Ejemplo n.º 1
0
//*************Message Service Methods ***************
func (serv MsgService) GetMessages(convoId string) string {
	var data ReturnData.ReturnData
	data = Msg.GetMessages(convoId)
	if data.Success {
		serv.ResponseBuilder().SetResponseCode(200)
	} else {
		serv.ResponseBuilder().SetResponseCode(400).WriteAndOveride([]byte(data.ToString()))
	}
	return string(data.ToString())
}
Ejemplo n.º 2
0
func GetDialoguesForLocation(locationId string) RD.ReturnData {
	returnData := RD.ReturnData{}
	dbSession := Connection.GetDBSession()
	dbSession.SetMode(mgo.Monotonic, true)
	dataBase := strings.SplitAfter(os.Getenv("MONGOHQ_URL"), "/")
	c := dbSession.DB(dataBase[3]).C("Dialogue")

	res := []Dialogue{}
	err := c.Find(bson.M{"venue.fourid": locationId}).All(&res)
	if err != nil {
		log.Println("Found Nothing Or Something went wrong fetching the Dialogue")
		returnData.ErrorMsg = err.Error()
		returnData.Status = "400"
		returnData.Success = false
	} else {
		log.Println(res)
		returnData.ErrorMsg = "All is well"
		returnData.Status = "200"
		returnData.Success = true
		jsonRes, _ := json.Marshal(res)
		returnData.JsonData = jsonRes
		log.Println(string(jsonRes))
	}
	return returnData
}
Ejemplo n.º 3
0
func (u *UserMetaData) SaveUserMetaData() RD.ReturnData {
	returnData := RD.ReturnData{}
	dbSession := Connection.GetDBSession()
	dbSession.SetMode(mgo.Monotonic, true)
	dataBase := strings.SplitAfter(os.Getenv("MONGOHQ_URL"), "/")
	c := dbSession.DB(dataBase[3]).C("jove")

	u.Id = bson.NewObjectId()
	u.Created_on = time.Now()

	err := c.Insert(u)
	if err != nil {
		log.Print(err.Error())
		returnData.ErrorMsg = err.Error()
		returnData.Success = false
		returnData.Status = "422"
	} else {
		returnData.Success = true
		jsonData, _ := json.Marshal(&u)
		returnData.JsonData = jsonData
		returnData.Status = "201"
	}

	return returnData
}
Ejemplo n.º 4
0
func (msg *Message) SaveMessage(conversationId string) RD.ReturnData {
	returnData := RD.ReturnData{}
	dbSession := Connection.GetDBSession()
	dbSession.SetMode(mgo.Monotonic, true)
	dataBase := strings.SplitAfter(os.Getenv("MONGOHQ_URL"), "/")
	c := dbSession.DB(dataBase[3]).C("conversation")
	msg.CreatedOn = time.Now()

	err := c.Update(bson.M{"_id": bson.ObjectIdHex(conversationId)}, bson.M{
		"$push": bson.M{"messages": bson.M{
			"_id":         bson.NewObjectId(),
			"msg_text":    msg.MsgText,
			"user_id":     msg.UserId,
			"user_handle": msg.UserHandle,
			"created_on":  msg.CreatedOn,
		}}})

	if err != nil {
		log.Println(err.Error())
		returnData.ErrorMsg = err.Error()
		returnData.Success = false
		returnData.Status = "422"
	} else {
		jsonData := []byte("{}")
		returnData.Success = true
		returnData.JsonData = jsonData
		returnData.Status = "201"
	}
	return returnData
}
Ejemplo n.º 5
0
func (conv *Conversation) CreateConversation() (RD.ReturnData, Conversation) {
	returnData := RD.ReturnData{}
	dbSession := Connection.GetDBSession()
	dbSession.SetMode(mgo.Monotonic, true)
	dataBase := strings.SplitAfter(os.Getenv("MONGOHQ_URL"), "/")
	c := dbSession.DB(dataBase[3]).C("conversation")
	conv.Id = bson.NewObjectId()
	conv.Created_On = time.Now()
	conv.Is_Approved = true

	err := c.Insert(&conv)
	if err != nil {
		log.Print(err.Error())
		returnData.ErrorMsg = err.Error()
		returnData.Success = false
		returnData.Status = "422"
	} else {

		returnData.Success = true
		jsonData, _ := json.Marshal(&conv)
		returnData.JsonData = jsonData
		returnData.Status = "201"
	}

	return returnData, *conv
}
Ejemplo n.º 6
0
func (serv MsgService) SaveMessage(posted, convoId string) {
	var data ReturnData.ReturnData
	var str []string
	str = strings.Split(posted, "=")
	msg := Msg.Message{}
	err := json.Unmarshal([]byte(str[1]), &msg)
	if err != nil {
		log.Println(err.Error())
		serv.ResponseBuilder().SetResponseCode(400).WriteAndOveride(nil)
		return
	} else {
		data = msg.SaveMessage(convoId)
	}
	if data.Success {
		serv.ResponseBuilder().SetResponseCode(201).Write([]byte(data.ToString()))
	} else {
		serv.ResponseBuilder().SetResponseCode(400).WriteAndOveride([]byte(data.ToString()))
	}
}
Ejemplo n.º 7
0
func (serv MsgService) GetMessage(msgId string) string {
	var data ReturnData.ReturnData
	data.Success = true
	data.JsonData = []byte("Get Message call")
	data.Status = "200"
	if data.Success {
		serv.ResponseBuilder().SetResponseCode(200)
	} else {
		serv.ResponseBuilder().SetResponseCode(400).WriteAndOveride([]byte(data.ToString()))
	}
	return string(data.ToString())
}
Ejemplo n.º 8
0
//*************Conversation Service Methods ***********
func (serv ConversationService) CreateConversation(posted string) {
	var returnData ReturnData.ReturnData
	var formData []string
	formData = strings.Split(posted, "=")
	conv := Conversation.Conversation{}
	err := json.Unmarshal([]byte(formData[1]), &conv)
	if err != nil {
		log.Println("conversation marshelling error>>>>>" + err.Error())
		serv.ResponseBuilder().SetResponseCode(400).WriteAndOveride([]byte(err.Error()))
		return
	} else {
		returnData, _ = conv.CreateConversation()
	}

	if returnData.Success {
		serv.ResponseBuilder().SetResponseCode(201).Write([]byte(returnData.ToString()))
	} else {
		serv.ResponseBuilder().SetResponseCode(400).WriteAndOveride([]byte(returnData.ToString()))
	}

}
Ejemplo n.º 9
0
//*************User Service Methods ***************
func (serv UserService) RegisterUser(posted string) {

	type newUser struct {
		Name        string `json:"name" bson:"name"`
		Email       string `json:"email" bson:"email"`
		Handle      string `json:"handle" bson:"handle"`
		Password    string `json:"password" bson:"password"`
		PhoneNumber string `json:"phone" bson:"phone"`
	}

	var data ReturnData.ReturnData
	var formData []string
	formData = strings.Split(posted, "=")
	user := User.User{}
	tempUser := newUser{}
	err := json.Unmarshal([]byte(formData[1]), &tempUser)

	if err != nil {
		log.Println(err.Error())
		serv.ResponseBuilder().SetResponseCode(400).WriteAndOveride(nil)
		return
	} else {
		user_id := User.CreateUserLogin(tempUser.Email, tempUser.Password)
		user.UserId, _ = strconv.Atoi(user_id)
		user.Name = tempUser.Name
		user.Email = tempUser.Email
		user.Handle = tempUser.Handle
		user.PhoneNumber = tempUser.PhoneNumber
		data = user.CreateUser()
	}
	if data.Success {
		serv.ResponseBuilder().SetResponseCode(201).Write([]byte(data.ToString()))
	} else {
		serv.ResponseBuilder().SetResponseCode(400).WriteAndOveride([]byte(data.ToString()))
	}
}
Ejemplo n.º 10
0
func DeleteConversation(conversationId string) RD.ReturnData {
	returnData := RD.ReturnData{}
	dbSession := Connection.GetDBSession()
	dbSession.SetMode(mgo.Monotonic, true)
	dataBase := strings.SplitAfter(os.Getenv("MONGOHQ_URL"), "/")
	c := dbSession.DB(dataBase[3]).C("conversation")

	err := c.Remove(bson.ObjectIdHex(conversationId))
	// err := c.Find(bson.M{"venue.fourid": locationId}).One(&res)
	if err != nil {
		log.Println("Found Nothing. Something went wrong fetching the Conversation document")
		log.Println(err)
		returnData.ErrorMsg = err.Error()
		returnData.Status = "400"
		returnData.Success = false
	} else {
		returnData.ErrorMsg = "All is well"
		returnData.Status = "200"
		returnData.Success = true
		returnData.JsonData = nil
	}
	return returnData
}
Ejemplo n.º 11
0
func (D *Dialogue) DeleteDialogue() RD.ReturnData {
	returnData := RD.ReturnData{}
	dbSession := Connection.GetDBSession()
	dbSession.SetMode(mgo.Monotonic, true)
	dataBase := strings.SplitAfter(os.Getenv("MONGOHQ_URL"), "/")
	c := dbSession.DB(dataBase[3]).C("Dialogue")

	// err := c.Remove(bson.ObjectIdHex(DialogueId))
	err := c.Remove(D.Id)

	if err != nil {
		log.Println("Found Nothing. Something went wrong fetching the Dialogue document")
		log.Println(err)
		returnData.ErrorMsg = err.Error()
		returnData.Status = "400"
		returnData.Success = false
	} else {
		returnData.ErrorMsg = "All is well"
		returnData.Status = "200"
		returnData.Success = true
		returnData.JsonData = nil
	}
	return returnData
}
Ejemplo n.º 12
0
func (D *Dialogue) CreateDialogue() (RD.ReturnData, Dialogue) {
	returnData := RD.ReturnData{}
	dbSession := Connection.GetDBSession()
	dbSession.SetMode(mgo.Monotonic, true)
	dataBase := strings.SplitAfter(os.Getenv("MONGOHQ_URL"), "/")
	c := dbSession.DB(dataBase[3]).C("Dialogue")
	D.Id = bson.NewObjectId()
	D.CreatedOn = time.Now()
	D.IsApproved = true

	err := c.Insert(&D)
	if err != nil {
		log.Print(err.Error())
		returnData.ErrorMsg = err.Error()
		returnData.Success = false
		returnData.Status = "422"
	} else {
		returnData.Success = true
		returnData.JsonData = []byte(D.DialogueToJSON())
		returnData.Status = "201"
	}

	return returnData, *D
}
Ejemplo n.º 13
0
func GetMessages(conversationId string) RD.ReturnData {
	returnData := RD.ReturnData{}
	dbSession := Connection.GetDBSession()
	dbSession.SetMode(mgo.Monotonic, true)
	dataBase := strings.SplitAfter(os.Getenv("MONGOHQ_URL"), "/")
	c := dbSession.DB(dataBase[3]).C("conversation")

	Msgs := []Message{}
	m := Messages{}
	err := c.Find(bson.M{"_id": bson.ObjectIdHex(conversationId)}).Select(bson.M{"messages": 1}).One(&m)
	if err != nil {
		log.Println(err.Error())
		returnData.ErrorMsg = err.Error()
		returnData.Success = false
		returnData.Status = "422"
	} else {
		log.Println(Msgs)
		jsonData, _ := json.Marshal(&m)
		returnData.Success = true
		returnData.JsonData = jsonData
		returnData.Status = "201"
	}
	return returnData
}
Ejemplo n.º 14
0
func (serv UserService) GetUser(userid string) string {
	var response string
	var err error
	var data ReturnData.ReturnData
	response, err = User.GetUserById(userid)
	if err != nil {
		data.Status = "400"
		data.Success = false
		data.ErrorMsg = err.Error()
		serv.ResponseBuilder().SetResponseCode(200)
	} else {
		data.ErrorMsg = "All is well"
		data.Status = "200"
		data.Success = true
		data.JsonData = []byte(response)
		serv.ResponseBuilder().SetResponseCode(400).WriteAndOveride([]byte(data.ToString()))
	}

	return string(data.ToString())
}
Ejemplo n.º 15
0
func (serv ConversationService) GetConversationsForLocation(locationId string) string {
	var data ReturnData.ReturnData
	response, err := Conversation.GetConversationsForLocation(locationId)
	if err != nil {
		data.ErrorMsg = err.Error()
		data.Status = "400"
		data.Success = false
		serv.ResponseBuilder().SetResponseCode(400).WriteAndOveride([]byte(data.ToString()))
	} else {
		data.Status = "200"
		data.Success = true
		data.JsonData = response
		serv.ResponseBuilder().SetResponseCode(200)
	}

	return string(data.ToString())
}