first
This commit is contained in:
commit
f4be03ceba
1826 changed files with 830924 additions and 0 deletions
38
backend/internal/api/handlers/logs.go
Normal file
38
backend/internal/api/handlers/logs.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/imc-vibe/backend/internal/mail"
|
||||
)
|
||||
|
||||
type LogsHandler struct{}
|
||||
|
||||
func NewLogsHandler() *LogsHandler {
|
||||
return &LogsHandler{}
|
||||
}
|
||||
|
||||
func (h *LogsHandler) List(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
Error(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||
return
|
||||
}
|
||||
|
||||
hours := 1
|
||||
if h := r.URL.Query().Get("hours"); h != "" {
|
||||
if n, err := strconv.Atoi(h); err == nil && n > 0 {
|
||||
hours = n
|
||||
}
|
||||
}
|
||||
|
||||
filter := r.URL.Query().Get("filter")
|
||||
|
||||
entries, err := mail.GetLogs(hours, filter)
|
||||
if err != nil {
|
||||
Error(w, http.StatusInternalServerError, "failed to get logs")
|
||||
return
|
||||
}
|
||||
|
||||
Success(w, entries)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue