mirror of
https://github.com/simon987/task_tracker.git
synced 2025-12-10 21:48:52 +00:00
monitoring setup, project dashboard, account page
This commit is contained in:
@@ -67,10 +67,6 @@ func (api *WebAPI) Login(r *Request) {
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess.Set("manager", manager)
|
||||
|
||||
logrus.Debug("SET")
|
||||
logrus.Debug(sess.ID())
|
||||
logrus.Debug(manager)
|
||||
|
||||
r.OkJson(LoginResponse{
|
||||
Manager: manager,
|
||||
Ok: true,
|
||||
@@ -135,8 +131,6 @@ func (api *WebAPI) AccountDetails(r *Request) {
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
logrus.Debug("GET")
|
||||
logrus.Debug(sess.ID())
|
||||
|
||||
if manager == nil {
|
||||
r.OkJson(AccountDetails{
|
||||
|
||||
18
api/main.go
18
api/main.go
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/buaazp/fasthttprouter"
|
||||
"github.com/kataras/go-sessions"
|
||||
"github.com/robfig/cron"
|
||||
"github.com/simon987/task_tracker/config"
|
||||
"github.com/simon987/task_tracker/storage"
|
||||
"github.com/valyala/fasthttp"
|
||||
@@ -16,6 +17,7 @@ type WebAPI struct {
|
||||
Database *storage.Database
|
||||
SessionConfig sessions.Config
|
||||
Session *sessions.Sessions
|
||||
Cron *cron.Cron
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
@@ -32,10 +34,23 @@ func Index(r *Request) {
|
||||
r.OkJson(info)
|
||||
}
|
||||
|
||||
func (api *WebAPI) setupMonitoring() {
|
||||
|
||||
api.Cron = cron.New()
|
||||
schedule := cron.Every(config.Cfg.MonitoringInterval)
|
||||
api.Cron.Schedule(schedule, cron.FuncJob(api.Database.MakeProjectSnapshots))
|
||||
api.Cron.Start()
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"every": config.Cfg.MonitoringInterval.String(),
|
||||
}).Info("Started monitoring")
|
||||
}
|
||||
|
||||
func New() *WebAPI {
|
||||
|
||||
api := new(WebAPI)
|
||||
api.Database = &storage.Database{}
|
||||
api.setupMonitoring()
|
||||
|
||||
api.router = &fasthttprouter.Router{}
|
||||
|
||||
@@ -71,6 +86,9 @@ func New() *WebAPI {
|
||||
api.router.GET("/project/get/:id", LogRequestMiddleware(api.ProjectGet))
|
||||
api.router.POST("/project/update/:id", LogRequestMiddleware(api.ProjectUpdate))
|
||||
api.router.GET("/project/list", LogRequestMiddleware(api.ProjectGetAllProjects))
|
||||
api.router.GET("/project/monitoring-between/:id", LogRequestMiddleware(api.GetSnapshotsBetween))
|
||||
api.router.GET("/project/monitoring/:id", LogRequestMiddleware(api.GetNSnapshots))
|
||||
api.router.GET("/project/assignees/:id", LogRequestMiddleware(api.ProjectGetAssigneeStats))
|
||||
|
||||
api.router.POST("/task/create", LogRequestMiddleware(api.TaskCreate))
|
||||
api.router.GET("/task/get/:project", LogRequestMiddleware(api.TaskGetFromProject))
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
@@ -49,6 +49,12 @@ type GetAllProjectsResponse struct {
|
||||
Projects *[]storage.Project `json:"projects,omitempty"`
|
||||
}
|
||||
|
||||
type GetAssigneeStatsResponse struct {
|
||||
Ok bool `json:"ok"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Assignees *[]storage.AssignedTasks `json:"assignees"`
|
||||
}
|
||||
|
||||
func (api *WebAPI) ProjectCreate(r *Request) {
|
||||
|
||||
createReq := &CreateProjectRequest{}
|
||||
@@ -203,3 +209,16 @@ func (api *WebAPI) ProjectGetAllProjects(r *Request) {
|
||||
Projects: projects,
|
||||
})
|
||||
}
|
||||
|
||||
func (api *WebAPI) ProjectGetAssigneeStats(r *Request) {
|
||||
|
||||
id, err := strconv.ParseInt(r.Ctx.UserValue("id").(string), 10, 64)
|
||||
handleErr(err, r) //todo handle invalid id
|
||||
|
||||
stats := api.Database.GetAssigneeStats(id, 16)
|
||||
|
||||
r.OkJson(GetAssigneeStatsResponse{
|
||||
Ok: true,
|
||||
Assignees: stats,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user