mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: minor fixes
This commit is contained in:
parent
e7f3432113
commit
e21788b8b5
File diff suppressed because it is too large
Load Diff
@ -2,6 +2,7 @@ package v1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/muety/wakapi/models"
|
"github.com/muety/wakapi/models"
|
||||||
)
|
)
|
||||||
@ -26,15 +27,14 @@ type HeartbeatEntry struct {
|
|||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
MachineNameId string `json:"machine_name_id"`
|
MachineNameId string `json:"machine_name_id"`
|
||||||
UserAgentId string `json:"user_agent_id"`
|
UserAgentId string `json:"user_agent_id"`
|
||||||
CreatedAt models.CustomTime `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
ModifiedAt models.CustomTime `json:"created_at",omitempty`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToHeartbeatEntry(entries []*models.Heartbeat) []HeartbeatEntry {
|
func HeartbeatsToCompat(entries []*models.Heartbeat) []*HeartbeatEntry {
|
||||||
out := make([]HeartbeatEntry, len(entries))
|
out := make([]*HeartbeatEntry, len(entries))
|
||||||
for i := 0; i < len(entries); i++ {
|
for i := 0; i < len(entries); i++ {
|
||||||
entry := entries[i]
|
entry := entries[i]
|
||||||
out[i] = HeartbeatEntry{
|
out[i] = &HeartbeatEntry{
|
||||||
Id: strconv.FormatUint(entry.ID, 10),
|
Id: strconv.FormatUint(entry.ID, 10),
|
||||||
Branch: entry.Branch,
|
Branch: entry.Branch,
|
||||||
Category: entry.Category,
|
Category: entry.Category,
|
||||||
@ -47,7 +47,7 @@ func ToHeartbeatEntry(entries []*models.Heartbeat) []HeartbeatEntry {
|
|||||||
UserId: entry.UserID,
|
UserId: entry.UserID,
|
||||||
MachineNameId: entry.Machine,
|
MachineNameId: entry.Machine,
|
||||||
UserAgentId: entry.UserAgent,
|
UserAgentId: entry.UserAgent,
|
||||||
CreatedAt: entry.CreatedAt,
|
CreatedAt: entry.CreatedAt.T(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type HeartbeatsResult struct {
|
type HeartbeatsResult struct {
|
||||||
Data []wakatime.HeartbeatEntry `json:"data"`
|
Data []*wakatime.HeartbeatEntry `json:"data"`
|
||||||
End string `json:"end"`
|
End string `json:"end"`
|
||||||
Start string `json:"start"`
|
Start string `json:"start"`
|
||||||
Timezone string `json:"timezone"`
|
Timezone string `json:"timezone"`
|
||||||
@ -46,7 +46,7 @@ func (h *HeartbeatHandler) RegisterRoutes(router *mux.Router) {
|
|||||||
// @Param date query string true "Date"
|
// @Param date query string true "Date"
|
||||||
// @Param user path string true "Username (or current)"
|
// @Param user path string true "Username (or current)"
|
||||||
// @Security ApiKeyAuth
|
// @Security ApiKeyAuth
|
||||||
// @Success 200 {object} v1.HeartbeatEntry
|
// @Success 200 {object} HeartbeatsResult
|
||||||
// @Failure 400 {string} string "bad date"
|
// @Failure 400 {string} string "bad date"
|
||||||
// @Router /compat/wakatime/v1/users/{user}/heartbeats [get]
|
// @Router /compat/wakatime/v1/users/{user}/heartbeats [get]
|
||||||
func (h *HeartbeatHandler) Get(w http.ResponseWriter, r *http.Request) {
|
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{
|
res := HeartbeatsResult{
|
||||||
Data: wakatime.ToHeartbeatEntry(heartbeats),
|
Data: wakatime.HeartbeatsToCompat(heartbeats),
|
||||||
Start: rangeFrom.UTC().Format(time.RFC3339),
|
Start: rangeFrom.UTC().Format(time.RFC3339),
|
||||||
End: rangeTo.UTC().Format(time.RFC3339),
|
End: rangeTo.UTC().Format(time.RFC3339),
|
||||||
Timezone: timezone.String(),
|
Timezone: timezone.String(),
|
||||||
|
@ -288,6 +288,7 @@ func mapHeartbeat(
|
|||||||
Time: models.CustomTime(time.Unix(0, int64(entry.Time*1e9))),
|
Time: models.CustomTime(time.Unix(0, int64(entry.Time*1e9))),
|
||||||
Origin: OriginWakatime,
|
Origin: OriginWakatime,
|
||||||
OriginId: entry.Id,
|
OriginId: entry.Id,
|
||||||
|
CreatedAt: models.CustomTime(entry.CreatedAt),
|
||||||
}).Hashed()
|
}).Hashed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
// This file was generated by swaggo/swag
|
||||||
|
|
||||||
package docs
|
package docs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
|
||||||
|
|
||||||
|
"github.com/alecthomas/template"
|
||||||
"github.com/swaggo/swag"
|
"github.com/swaggo/swag"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ var doc = `{
|
|||||||
"schemes": {{ marshal .Schemes }},
|
"schemes": {{ marshal .Schemes }},
|
||||||
"swagger": "2.0",
|
"swagger": "2.0",
|
||||||
"info": {
|
"info": {
|
||||||
"description": "{{escape .Description}}",
|
"description": "{{.Description}}",
|
||||||
"title": "{{.Title}}",
|
"title": "{{.Title}}",
|
||||||
"contact": {
|
"contact": {
|
||||||
"name": "Ferdinand Mütsch",
|
"name": "Ferdinand Mütsch",
|
||||||
@ -191,7 +192,7 @@ var doc = `{
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "OK",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/v1.HeartbeatEntry"
|
"$ref": "#/definitions/v1.HeartbeatsResult"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
@ -1340,6 +1341,9 @@ var doc = `{
|
|||||||
"machine_name_id": {
|
"machine_name_id": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"modified_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"project": {
|
"project": {
|
||||||
"type": "string"
|
"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": {
|
"v1.Project": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@ -1703,13 +1727,6 @@ func (s *s) ReadDoc() string {
|
|||||||
a, _ := json.Marshal(v)
|
a, _ := json.Marshal(v)
|
||||||
return string(a)
|
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)
|
}).Parse(doc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return doc
|
return doc
|
||||||
@ -1724,5 +1741,5 @@ func (s *s) ReadDoc() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
swag.Register("swagger", &s{})
|
swag.Register(swag.Name, &s{})
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "OK",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/v1.HeartbeatEntry"
|
"$ref": "#/definitions/v1.HeartbeatsResult"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
@ -1325,6 +1325,9 @@
|
|||||||
"machine_name_id": {
|
"machine_name_id": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"modified_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"project": {
|
"project": {
|
||||||
"type": "string"
|
"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": {
|
"v1.Project": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -166,6 +166,8 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
machine_name_id:
|
machine_name_id:
|
||||||
type: string
|
type: string
|
||||||
|
modified_at:
|
||||||
|
type: string
|
||||||
project:
|
project:
|
||||||
type: string
|
type: string
|
||||||
time:
|
time:
|
||||||
@ -177,6 +179,19 @@ definitions:
|
|||||||
user_id:
|
user_id:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
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:
|
v1.Project:
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
@ -501,7 +516,7 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/v1.HeartbeatEntry'
|
$ref: '#/definitions/v1.HeartbeatsResult'
|
||||||
"400":
|
"400":
|
||||||
description: bad date
|
description: bad date
|
||||||
schema:
|
schema:
|
||||||
|
@ -1 +1 @@
|
|||||||
2.1.0
|
2.2.0
|
Loading…
Reference in New Issue
Block a user