func GetReplyByHash(enc Encoder, db gorp.SqlExecutor, parms martini.Params) (int, string) { var warning *models.Warning hash := parms["hash"] respReply := getReplyRespHash(hash, db) readReply := getReplyReadHash(hash, db) if respReply == nil && readReply == nil { fmt.Println("FAILED: neither resp or read hash matches") return http.StatusBadRequest, "" } else if respReply != nil { respReply.Read_hash = "" warning = GetWarning(respReply.Id_warning, db) warning.WarnResp = respReply } else if readReply != nil { readReply.Resp_hash = "" warning = GetWarning(readReply.Id_warning, db) warning.WarnResp = readReply } clearReturn(warning) return http.StatusOK, Must(enc.EncodeOne(warning)) }
// After registered in the Database, the warn is processed in order to verify: // - @isSameWarnSentByIp // - @isSameWarnSentTwiceOrMoreDifferentIp // - if none of above occurs the warn is processed by its type(Email, SMS, Whatsapp, etc...) // - @routers.email.ProcessEmail // - @routers.sms.ProcessSMS func processWarn(warning *models.Warning, db gorp.SqlExecutor, status *models.DefaultStruct) { fmt.Println("processWarn") status.Lang_key = warning.Lang_key if isSameWarnSentByIp(warning, db) { status.Id = http.StatusBadRequest status.Name = strings.Replace(messages.GetLocaleMessage(warning.Lang_key, "MSG_SMS_SAME_WARN_BY_IP"), "{{ip}}", warning.Ip, 1) status.Name = strings.Replace(status.Name, "{{time}}", "2", 1) } else if isSameWarnSentTwiceOrMoreDifferentIp(warning, db) { status.Id = http.StatusBadRequest status.Name = strings.Replace(messages.GetLocaleMessage(warning.Lang_key, "MSG_SMS_SAME_WARN_DIFF_IP"), "{{time}}", "2", 1) } else { if warning.WarnResp != nil && warning.WarnResp.Reply_to != "" { ProcessWarnReply(warning, db) } else { warning.WarnResp = nil } switch warning.Id_contact_type { case 1: go ProcessEmail(warning, db) case 2: ProcessSMS(warning, db, status) case 3: go ProcessWhatsapp(warning, db) default: return } } }