mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
d1be4ce2a3
Add OS and editor fields. Introduce aggregations (not working yet).
40 lines
750 B
Go
40 lines
750 B
Go
package routes
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/n1try/wakapi/models"
|
|
"github.com/n1try/wakapi/services"
|
|
"github.com/n1try/wakapi/utils"
|
|
)
|
|
|
|
type AggregationHandler struct {
|
|
AggregationSrvc *services.AggregationService
|
|
}
|
|
|
|
func (h *AggregationHandler) Get(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != "GET" {
|
|
w.WriteHeader(415)
|
|
return
|
|
}
|
|
|
|
user := r.Context().Value(models.UserKey).(*models.User)
|
|
params := r.URL.Query()
|
|
from, err := utils.ParseDate(params.Get("from"))
|
|
if err != nil {
|
|
w.WriteHeader(400)
|
|
w.Write([]byte("Missing 'from' parameter"))
|
|
return
|
|
}
|
|
|
|
to, err := utils.ParseDate(params.Get("to"))
|
|
if err != nil {
|
|
to = time.Now()
|
|
}
|
|
|
|
h.AggregationSrvc.Aggregate(from, to, user)
|
|
|
|
w.WriteHeader(200)
|
|
}
|