//*************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()) }
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()) }
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()) }
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())) } }
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()) }
//*************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())) } }
//*************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())) } }