updated "last" endpoint
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Paul Lecuq 2022-02-09 10:18:28 +01:00
parent 4f66f6fddd
commit 7d36b8e6fe
2 changed files with 8 additions and 2 deletions

View File

@ -25,7 +25,7 @@ func GetIPs(ctx *context.Context, config *config.Config, limit int) (apimailboxe
}
// GetIPs ...
func GetIPsLastDay(ctx *context.Context, config *config.Config, interval string) (apimailboxes []*api.IP, err error) {
func GetIPsLast(ctx *context.Context, config *config.Config, interval string) (apimailboxes []*api.IP, err error) {
var ips []IP
err = config.Db.Where(fmt.Sprintf("updated >= (now()-'%s'::interval)", interval)).Asc("id").Find(&ips)
for _, ml := range ips {

View File

@ -52,9 +52,15 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
ret, err := models.GetIPs(ctx, cfg, limit)
return JSONResult(c, err, ret)
})
// retro-compat
e.GET("/ips/lastday", func(c echo.Context) (err error) {
interval := "1 day"
ret, err := models.GetIPsLastDay(ctx, cfg, interval)
ret, err := models.GetIPsLast(ctx, cfg, interval)
return JSONResult(c, err, ret)
})
e.GET("/ips/last", func(c echo.Context) (err error) {
interval := "10 minutes"
ret, err := models.GetIPsLast(ctx, cfg, interval)
return JSONResult(c, err, ret)
})
e.POST("/ips", func(c echo.Context) (err error) {