mirror of
https://github.com/simon987/task_tracker.git
synced 2025-12-13 14:59:03 +00:00
monitoring setup, project dashboard, account page
This commit is contained in:
52
api/monitoring.go
Normal file
52
api/monitoring.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/simon987/task_tracker/storage"
|
||||
"math"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type MonitoringSnapshotResponse struct {
|
||||
Ok bool `json:"ok"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Snapshots *[]storage.ProjectMonitoringSnapshot `json:"snapshots,omitempty"`
|
||||
}
|
||||
|
||||
func (api *WebAPI) GetSnapshotsBetween(r *Request) {
|
||||
|
||||
id, err := strconv.ParseInt(r.Ctx.UserValue("id").(string), 10, 64)
|
||||
from := r.Ctx.Request.URI().QueryArgs().GetUintOrZero("from")
|
||||
to := r.Ctx.Request.URI().QueryArgs().GetUintOrZero("to")
|
||||
if err != nil || id <= 0 || from <= 0 || to <= 0 || from >= math.MaxInt32 || to >= math.MaxInt32 {
|
||||
r.Json(MonitoringSnapshotResponse{
|
||||
Ok: false,
|
||||
Message: "Invalid request",
|
||||
}, 400)
|
||||
return
|
||||
}
|
||||
|
||||
snapshots := api.Database.GetMonitoringSnapshotsBetween(id, from, to)
|
||||
r.OkJson(MonitoringSnapshotResponse{
|
||||
Ok: true,
|
||||
Snapshots: snapshots,
|
||||
})
|
||||
}
|
||||
|
||||
func (api *WebAPI) GetNSnapshots(r *Request) {
|
||||
|
||||
id, err := strconv.ParseInt(r.Ctx.UserValue("id").(string), 10, 64)
|
||||
count := r.Ctx.Request.URI().QueryArgs().GetUintOrZero("count")
|
||||
if err != nil || id <= 0 || count <= 0 || count >= 1000 {
|
||||
r.Json(MonitoringSnapshotResponse{
|
||||
Ok: false,
|
||||
Message: "Invalid request",
|
||||
}, 400)
|
||||
return
|
||||
}
|
||||
|
||||
snapshots := api.Database.GetNMonitoringSnapshots(id, count)
|
||||
r.OkJson(MonitoringSnapshotResponse{
|
||||
Ok: true,
|
||||
Snapshots: snapshots,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user