func (place *Place) getListPlace(getList GetListPlace) ListPlace { list := ListPlace{} var curs *r.Cursor if strings.Compare(getList.Filter, "") == 0 && strings.Compare(getList.Venue, "") == 0 { curs, _ = r.Table("places").Filter(r.Row.Field("Validated").Eq(true)).Slice(getList.Offset, getList.Offset+getList.Limit).OrderBy("-PostNb").Run(api.Sess) } else if strings.Compare(getList.Filter, "") != 0 && strings.Compare(getList.Venue, "") == 0 { curs, _ = r.Table("places").Filter(r.Row.Field("Validated").Eq(true)).Filter(func(customer r.Term) interface{} { return customer.Field(getList.Filter).Downcase().Match("^" + strings.ToLower(getList.FilterValue)) }).Slice(getList.Offset, getList.Offset+getList.Limit).OrderBy("-PostNb").Run(api.Sess) } else if strings.Compare(getList.Filter, "") == 0 && strings.Compare(getList.Venue, "") != 0 { curs, _ = r.Table("places").Filter(r.Row.Field("Validated").Eq(true)).Filter(r.Row.Field("Type").Eq(getList.Venue)).Slice(getList.Offset, getList.Offset+getList.Limit).OrderBy("-PostNb").Run(api.Sess) } else if strings.Compare(getList.Filter, "") != 0 && strings.Compare(getList.Venue, "") != 0 { curs, _ = r.Table("places").Filter(r.Row.Field("Validated").Eq(true)).Filter(func(customer r.Term) interface{} { return customer.Field(getList.Filter).Downcase().Match("^" + strings.ToLower(getList.FilterValue)) }).Filter(r.Row.Field("Type").Eq(getList.Venue)).Slice(getList.Offset, getList.Offset+getList.Limit).OrderBy("-PostNb").Run(api.Sess) } curs.All(&list.Places) return list }
func (place *Place) getPendingPlaces(request *restful.Request, response *restful.Response) { var err error var curs *r.Cursor listPlace := ListPlace{} if place.user.Group == 100 { curs, err = r.Table("places").Filter(r.Row.Field("Validated").Eq(false)).OrderBy("CreateAt").Limit(20).Run(api.Sess) } else { curs, err = r.Table("places").Filter(r.Row.Field("Validated").Eq(false)).Filter(r.Row.Field("UserId").Eq(place.user.Id)).OrderBy("-CreateAt").Limit(20).Run(api.Sess) } err = curs.All(&listPlace.Places) if err != nil { response.WriteHeaderAndEntity(http.StatusInternalServerError, err.Error()) return } response.WriteHeaderAndEntity(http.StatusOK, listPlace) helpers.PrintLog(request, response, place.user.Name) }
func (expected Err) assert(suite suite.Suite, obtainerCursor *r.Cursor, obtainedErr error) { // If the error is nil then attempt to read from the cursor and see if an // error is returned if obtainedErr == nil { var res []interface{} obtainedErr = obtainerCursor.All(&res) } if suite.Error(obtainedErr) { return } obtainedType := reflect.TypeOf(obtainedErr).String() obtainedMessage := strings.TrimPrefix(obtainedErr.Error(), "gorethink: ") obtainedMessage = exceptionRegex.ReplaceAllString(obtainedMessage, "${message}") suite.Equal(expected.Type, obtainedType) if expected.Regex != "" { suite.Regexp(expected.Regex, obtainedMessage) } if expected.Message != "" { suite.Equal(expected.Message, obtainedMessage) } }
func (expected Expected) assert(suite suite.Suite, obtainedCursor *r.Cursor, obtainedErr error) { if suite.NoError(obtainedErr, "Query returned unexpected error") { return } expectedVal := reflect.ValueOf(expected.Val) // If expected value is nil then ensure cursor is nil (assume that an // invalid reflect value is because expected value is nil) if !expectedVal.IsValid() || (expectedVal.Kind() == reflect.Ptr && expectedVal.IsNil()) { suite.True(obtainedCursor.IsNil(), "Expected nil cursor") return } expectedType := expectedVal.Type() expectedKind := expectedType.Kind() if expectedKind == reflect.Array || expectedKind == reflect.Slice || expected.Fetch { if expectedType.Elem().Kind() == reflect.Uint8 { // Decode byte slices slightly differently var obtained = []byte{} err := obtainedCursor.One(&obtained) suite.NoError(err, "Error returned when reading query response") compare.Assert(suite.T(), expected, obtained) } else { var obtained = []interface{}{} if expected.Fetch { var v interface{} for obtainedCursor.Next(&v) { obtained = append(obtained, v) if expected.FetchCount != 0 && len(obtained) >= expected.FetchCount { break } } suite.NoError(obtainedCursor.Err(), "Error returned when reading query response") } else { err := obtainedCursor.All(&obtained) suite.NoError(err, "Error returned when reading query response") } compare.Assert(suite.T(), expected, obtained) } } else if expectedKind == reflect.Map { var obtained map[string]interface{} err := obtainedCursor.One(&obtained) suite.NoError(err, "Error returned when reading query response") compare.Assert(suite.T(), expected, obtained) } else { var obtained interface{} err := obtainedCursor.One(&obtained) suite.NoError(err, "Error returned when reading query response") compare.Assert(suite.T(), expected, obtained) } }