Skip to content

Commit

Permalink
finish GET route
Browse files Browse the repository at this point in the history
  • Loading branch information
g00gol committed Oct 8, 2023
1 parent d672b56 commit a69455a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
20 changes: 19 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,23 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
"configurations": [
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": 157645
},
{
"name": "Connect to server",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "${workspaceFolder}",
"port": 8080,
"host": "127.0.0.1"
}

]
}
1 change: 0 additions & 1 deletion backend/db/repos_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

func GetReposByFilters(filter any) ([]types.Repo, error) {
log.Println("Getting repos by filters", filter)
collection := GetCollection("repos")

// Specify options to use for string comparison
Expand Down
8 changes: 6 additions & 2 deletions backend/utils/construct_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ func ConstructFilters(r *http.Request, model interface{}) bson.D {

for i := 0; i < typ.NumField(); i++ {
field := typ.Field(i)
param := strings.ToLower(field.Name)

bsonTag := field.Tag.Get("bson")
if bsonTag == "" {
continue
}
param := strings.Split(bsonTag, ",")[0]

if values, ok := r.URL.Query()[param]; ok && len(values) > 0 {
if field.Type.Kind() == reflect.Slice {
// Split the comma-delimited string into a slice of strings
elements := strings.Split(values[0], ",")
filter = append(filter, bson.E{Key: param, Value: bson.D{{Key: "$in", Value: elements}}})
} else {
Expand Down

0 comments on commit a69455a

Please sign in to comment.