Skip to content

Commit

Permalink
feat: added ability to search logs by uri encoded name
Browse files Browse the repository at this point in the history
  • Loading branch information
syntaxsdev committed Jan 6, 2025
1 parent 82574f7 commit 077a37e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
5 changes: 5 additions & 0 deletions internal/api/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
)

func LogRoutes(r chi.Router, factory *services.Factory) {
r.Get("/{name}", func(w http.ResponseWriter, r *http.Request) {
name := chi.URLParam(r, "name")
handlers.GetLog(w, r, factory, name)
})

r.Get("/", func(w http.ResponseWriter, r *http.Request) {
handlers.GetAllLogs(w, r, factory)
})
Expand Down
25 changes: 10 additions & 15 deletions internal/handlers/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,17 @@ func GetAllLogs(w http.ResponseWriter, r *http.Request, f *services.Factory) {
}

// Get log of a specific strategy
// func GetLog(w http.ResponseWriter, r *http.Request, f *services.Factory) {
// var logs []*interface{}
// var filterPayload map[string]interface{}

// var payload map[string]interface{}
// if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
// payload = nil
// }
func GetLog(w http.ResponseWriter, r *http.Request, f *services.Factory, n string) {
var logs []*interface{}
filter := bson.M{"strategy": n}

// err := f.MongoService.All("logs", bson.M(filterPayload), &logs)
// if err != nil {
// WriteHttp(w, http.StatusInternalServerError, "Failed to retrieve logs.", err)
// return
// }
// WriteHttp(w, http.StatusOK, "Successfully fetched all logs", logs)
// }
err := f.MongoService.All("logs", filter, &logs)
if err != nil {
WriteHttp(w, http.StatusInternalServerError, "Failed to retrieve logs.", err)
return
}
WriteHttp(w, http.StatusOK, "Successfully fetched all logs", logs)
}

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

0 comments on commit 077a37e

Please sign in to comment.