38 lines
703 B
Go
38 lines
703 B
Go
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)
|
|
}
|