drift-org / backend

2 stars 0 forks source link

Created find challenge helper function and setup indexes #43

Closed teekenzie closed 3 years ago

teekenzie commented 3 years ago

Contributors

@teekenzie

Relevant issue

Closes #38

Summary of change

Added find challenge function that will return all the challenges that are within a certain miles away from the current location (which is passed into the function) Started setting up indexes to enable $near to be used effectively

Testing/Verification

Added this block of code to main.go

results, err := helpers.FindChallenge(2.234, 1.234, 218)
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(results)

Result of running make run [{{{ObjectID("60caaa7cff0df79a62f2cadb")} {0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC}} {Point [1.234 1.234]} find a bench Try looking for a bench in a park 3} {{{ObjectID("60cab4bcb97d6eb0b7426851")} {0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC}} {Point [-0.236 -0.236]} find a school Try looking for school from the maps 12}]

Objects in Mongo during run {“_id":{"$oid":"60caaa7cff0df79a62f2cadb"},"location":{"type":"Point","coordinates":[{"$numberDouble":"1.234"},{"$numberDouble":"1.234"}]},"taskName":"find a bench","description":"Try looking for a bench in a park","points":{"$numberInt":"3"}} {"_id":{"$oid":"60cab4bcb97d6eb0b7426851"},"location":{"type":"Point","coordinates":[{"$numberDouble":"-0.236"},{"$numberDouble":"-0.236"}]},"taskName":"find a school","description":"Try looking for school from the maps","points":{"$numberInt":"12"}} {"_id":{"$oid":"60cab4fab97d6eb0b7426853"},"location":{"type":"Point","coordinates":[{"$numberDouble":"10.236"},{"$numberDouble":"30.236"}]},"taskName":"find a two stories house","description":"Try walking around the neighborhoods","points":{"$numberInt":"9"}}