Skip to content

Commit 077a37e

Browse files
committed
feat: added ability to search logs by uri encoded name
1 parent 82574f7 commit 077a37e

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

internal/api/logs.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import (
99
)
1010

1111
func LogRoutes(r chi.Router, factory *services.Factory) {
12+
r.Get("/{name}", func(w http.ResponseWriter, r *http.Request) {
13+
name := chi.URLParam(r, "name")
14+
handlers.GetLog(w, r, factory, name)
15+
})
16+
1217
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
1318
handlers.GetAllLogs(w, r, factory)
1419
})

internal/handlers/logging.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,17 @@ func GetAllLogs(w http.ResponseWriter, r *http.Request, f *services.Factory) {
2121
}
2222

2323
// Get log of a specific strategy
24-
// func GetLog(w http.ResponseWriter, r *http.Request, f *services.Factory) {
25-
// var logs []*interface{}
26-
// var filterPayload map[string]interface{}
27-
28-
// var payload map[string]interface{}
29-
// if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
30-
// payload = nil
31-
// }
24+
func GetLog(w http.ResponseWriter, r *http.Request, f *services.Factory, n string) {
25+
var logs []*interface{}
26+
filter := bson.M{"strategy": n}
3227

33-
// err := f.MongoService.All("logs", bson.M(filterPayload), &logs)
34-
// if err != nil {
35-
// WriteHttp(w, http.StatusInternalServerError, "Failed to retrieve logs.", err)
36-
// return
37-
// }
38-
// WriteHttp(w, http.StatusOK, "Successfully fetched all logs", logs)
39-
// }
28+
err := f.MongoService.All("logs", filter, &logs)
29+
if err != nil {
30+
WriteHttp(w, http.StatusInternalServerError, "Failed to retrieve logs.", err)
31+
return
32+
}
33+
WriteHttp(w, http.StatusOK, "Successfully fetched all logs", logs)
34+
}
4035

4136
// Create a new log
4237
func NewLog(w http.ResponseWriter, r *http.Request, f *services.Factory) {

0 commit comments

Comments
 (0)