1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

feat: GET /heartbeat endpoint (resolves #241)

This commit is contained in:
Steven Tang
2022-01-28 22:28:47 +11:00
committed by Ferdinand Mütsch
parent 7159df30c2
commit e7f3432113
9 changed files with 638 additions and 9 deletions

View File

@@ -1,6 +1,8 @@
package v1
import (
"strconv"
"github.com/muety/wakapi/models"
)
@@ -19,11 +21,34 @@ type HeartbeatEntry struct {
IsWrite bool `json:"is_write"`
Language string `json:"language"`
Project string `json:"project"`
Time models.CustomTime `json:"time"`
Time float64 `json:"time"`
Type string `json:"type"`
UserId string `json:"user_id"`
MachineNameId string `json:"machine_name_id"`
UserAgentId string `json:"user_agent_id"`
CreatedAt models.CustomTime `json:"created_at"`
ModifiedAt models.CustomTime `json:"created_at"`
ModifiedAt models.CustomTime `json:"created_at",omitempty`
}
func ToHeartbeatEntry(entries []*models.Heartbeat) []HeartbeatEntry {
out := make([]HeartbeatEntry, len(entries))
for i := 0; i < len(entries); i++ {
entry := entries[i]
out[i] = HeartbeatEntry{
Id: strconv.FormatUint(entry.ID, 10),
Branch: entry.Branch,
Category: entry.Category,
Entity: entry.Entity,
IsWrite: entry.IsWrite,
Language: entry.Language,
Project: entry.Project,
Time: float64(entry.Time.T().Unix()),
Type: entry.Type,
UserId: entry.UserID,
MachineNameId: entry.Machine,
UserAgentId: entry.UserAgent,
CreatedAt: entry.CreatedAt,
}
}
return out
}