func clearReturn(entity *models.Warning) { entity.Message = "" entity.Ip = "" entity.Browser = "" entity.Operating_system = "" entity.Device = "" entity.Raw = "" entity.Created_by = "" entity.Last_modified_by = "" entity.Last_modified_date = "" entity.WarnResp.Reply_to = "" entity.WarnResp.Ip = "" entity.WarnResp.Browser = "" entity.WarnResp.Operating_system = "" entity.WarnResp.Device = "" entity.WarnResp.Raw = "" if entity.WarnResp.Reply_date == "0000-00-00 00:00:00" { entity.WarnResp.Reply_date = "" } if entity.WarnResp.Response_read == "0000-00-00 00:00:00" { entity.WarnResp.Response_read = "" } }
// Receives a warning tru, inserts the request and process the warning and then respond to the interface //TODO: use (session sessions.Session, r *http.Request) to prevent flood func AddWarning(entity models.Warning, enc Encoder, db gorp.SqlExecutor, r *http.Request) (int, string) { fmt.Println("AddWarning") if isInvalidWarning(&entity) { return http.StatusBadRequest, Must(enc.EncodeOne(entity)) } status := &models.DefaultStruct{ Id: http.StatusOK, Name: messages.GetLocaleMessage(entity.Lang_key, "MSG_WARNING_SENT_SUCCESS"), Lang_key: entity.Lang_key, Type: models.MSG_TYPE_WARNING, } entity.Sent = false entity.Created_by = "system" //entity.Created_date = time.Now().String() err := db.Insert(&entity) checkErr(err, "INSERT WARNING ERROR") if err != nil { return http.StatusBadRequest, Must(enc.EncodeOne(entity)) } ingnored := InIgnoreList(db, entity.Contact) if ingnored != nil && ingnored.Confirmed { status = &models.DefaultStruct{ Id: http.StatusBadRequest, Name: messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNORED_USER"), Lang_key: entity.Lang_key, Type: models.MSG_TYPE_WARNING, } } else { processWarn(&entity, db, status) } return http.StatusCreated, Must(enc.EncodeOne(status)) }