chore: minor fixes

This commit is contained in:
Ferdinand Mütsch 2022-02-13 10:59:14 +01:00
parent e7f3432113
commit e21788b8b5
8 changed files with 633 additions and 577 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@ package v1
import (
"strconv"
"time"
"github.com/muety/wakapi/models"
)
@ -14,27 +15,26 @@ type HeartbeatsViewModel struct {
// that is actually required for the import
type HeartbeatEntry struct {
Id string `json:"id"`
Branch string `json:"branch"`
Category string `json:"category"`
Entity string `json:"entity"`
IsWrite bool `json:"is_write"`
Language string `json:"language"`
Project string `json:"project"`
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",omitempty`
Id string `json:"id"`
Branch string `json:"branch"`
Category string `json:"category"`
Entity string `json:"entity"`
IsWrite bool `json:"is_write"`
Language string `json:"language"`
Project string `json:"project"`
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 time.Time `json:"created_at"`
}
func ToHeartbeatEntry(entries []*models.Heartbeat) []HeartbeatEntry {
out := make([]HeartbeatEntry, len(entries))
func HeartbeatsToCompat(entries []*models.Heartbeat) []*HeartbeatEntry {
out := make([]*HeartbeatEntry, len(entries))
for i := 0; i < len(entries); i++ {
entry := entries[i]
out[i] = HeartbeatEntry{
out[i] = &HeartbeatEntry{
Id: strconv.FormatUint(entry.ID, 10),
Branch: entry.Branch,
Category: entry.Category,
@ -47,7 +47,7 @@ func ToHeartbeatEntry(entries []*models.Heartbeat) []HeartbeatEntry {
UserId: entry.UserID,
MachineNameId: entry.Machine,
UserAgentId: entry.UserAgent,
CreatedAt: entry.CreatedAt,
CreatedAt: entry.CreatedAt.T(),
}
}
return out

View File

@ -14,10 +14,10 @@ import (
)
type HeartbeatsResult struct {
Data []wakatime.HeartbeatEntry `json:"data"`
End string `json:"end"`
Start string `json:"start"`
Timezone string `json:"timezone"`
Data []*wakatime.HeartbeatEntry `json:"data"`
End string `json:"end"`
Start string `json:"start"`
Timezone string `json:"timezone"`
}
type HeartbeatHandler struct {
@ -46,7 +46,7 @@ func (h *HeartbeatHandler) RegisterRoutes(router *mux.Router) {
// @Param date query string true "Date"
// @Param user path string true "Username (or current)"
// @Security ApiKeyAuth
// @Success 200 {object} v1.HeartbeatEntry
// @Success 200 {object} HeartbeatsResult
// @Failure 400 {string} string "bad date"
// @Router /compat/wakatime/v1/users/{user}/heartbeats [get]
func (h *HeartbeatHandler) Get(w http.ResponseWriter, r *http.Request) {
@ -76,7 +76,7 @@ func (h *HeartbeatHandler) Get(w http.ResponseWriter, r *http.Request) {
}
res := HeartbeatsResult{
Data: wakatime.ToHeartbeatEntry(heartbeats),
Data: wakatime.HeartbeatsToCompat(heartbeats),
Start: rangeFrom.UTC().Format(time.RFC3339),
End: rangeTo.UTC().Format(time.RFC3339),
Timezone: timezone.String(),

View File

@ -288,6 +288,7 @@ func mapHeartbeat(
Time: models.CustomTime(time.Unix(0, int64(entry.Time*1e9))),
Origin: OriginWakatime,
OriginId: entry.Id,
CreatedAt: models.CustomTime(entry.CreatedAt),
}).Hashed()
}

View File

@ -1,13 +1,14 @@
// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag
package docs
import (
"bytes"
"encoding/json"
"strings"
"text/template"
"github.com/alecthomas/template"
"github.com/swaggo/swag"
)
@ -15,7 +16,7 @@ var doc = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"description": "{{.Description}}",
"title": "{{.Title}}",
"contact": {
"name": "Ferdinand Mütsch",
@ -191,7 +192,7 @@ var doc = `{
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.HeartbeatEntry"
"$ref": "#/definitions/v1.HeartbeatsResult"
}
},
"400": {
@ -1340,6 +1341,9 @@ var doc = `{
"machine_name_id": {
"type": "string"
},
"modified_at": {
"type": "string"
},
"project": {
"type": "string"
},
@ -1357,6 +1361,26 @@ var doc = `{
}
}
},
"v1.HeartbeatsResult": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.HeartbeatEntry"
}
},
"end": {
"type": "string"
},
"start": {
"type": "string"
},
"timezone": {
"type": "string"
}
}
},
"v1.Project": {
"type": "object",
"properties": {
@ -1703,13 +1727,6 @@ func (s *s) ReadDoc() string {
a, _ := json.Marshal(v)
return string(a)
},
"escape": func(v interface{}) string {
// escape tabs
str := strings.Replace(v.(string), "\t", "\\t", -1)
// replace " with \", and if that results in \\", replace that with \\\"
str = strings.Replace(str, "\"", "\\\"", -1)
return strings.Replace(str, "\\\\\"", "\\\\\\\"", -1)
},
}).Parse(doc)
if err != nil {
return doc
@ -1724,5 +1741,5 @@ func (s *s) ReadDoc() string {
}
func init() {
swag.Register("swagger", &s{})
swag.Register(swag.Name, &s{})
}

View File

@ -176,7 +176,7 @@
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.HeartbeatEntry"
"$ref": "#/definitions/v1.HeartbeatsResult"
}
},
"400": {
@ -1325,6 +1325,9 @@
"machine_name_id": {
"type": "string"
},
"modified_at": {
"type": "string"
},
"project": {
"type": "string"
},
@ -1342,6 +1345,26 @@
}
}
},
"v1.HeartbeatsResult": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.HeartbeatEntry"
}
},
"end": {
"type": "string"
},
"start": {
"type": "string"
},
"timezone": {
"type": "string"
}
}
},
"v1.Project": {
"type": "object",
"properties": {

View File

@ -166,6 +166,8 @@ definitions:
type: string
machine_name_id:
type: string
modified_at:
type: string
project:
type: string
time:
@ -177,6 +179,19 @@ definitions:
user_id:
type: string
type: object
v1.HeartbeatsResult:
properties:
data:
items:
$ref: '#/definitions/v1.HeartbeatEntry'
type: array
end:
type: string
start:
type: string
timezone:
type: string
type: object
v1.Project:
properties:
id:
@ -501,7 +516,7 @@ paths:
"200":
description: OK
schema:
$ref: '#/definitions/v1.HeartbeatEntry'
$ref: '#/definitions/v1.HeartbeatsResult'
"400":
description: bad date
schema:

View File

@ -1 +1 @@
2.1.0
2.2.0