File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,8 @@ func NewHttpServer(config *app.Config, db *gorm.DB) *Http {
8282 w .Write ([]byte ("ok" ))
8383 })
8484
85+ s .router .Get ("/api/check/{repoId}" , s .check )
86+
8587 s .router .Post ("/api/metric" , s .createMetric )
8688
8789 // Protected routes
@@ -126,6 +128,21 @@ type MetricRequest struct {
126128 Pid string `json:"p"`
127129}
128130
131+ func (s * Http ) check (w http.ResponseWriter , r * http.Request ) {
132+ repoId := chi .URLParam (r , "repoId" )
133+
134+ // Get last event for repoId
135+ result , hasResult := s .statsService .LastEvent (repoId )
136+
137+ if ! hasResult {
138+ http .Error (w , "No events found" , http .StatusNotFound )
139+ return
140+ }
141+
142+ // Return timestamp from last event in iso8601 format
143+ w .Write ([]byte (result .Timestamp .Format ("2006-01-02T15:04:05Z" )))
144+ }
145+
129146func (s * Http ) createMetric (w http.ResponseWriter , r * http.Request ) {
130147 // Metric request is different to a eventRequest as only some data comes
131148 // from the json body
You can’t perform that action at this time.
0 commit comments