feat(db): add parameter for time window in history endpoint

Signed-off-by: Klagarge <remi@heredero.ch>
This commit is contained in:
2026-05-03 17:06:53 +02:00
parent 9163fd494b
commit fcdb5b5485
5 changed files with 25 additions and 4 deletions

View File

@@ -4,7 +4,8 @@
GET http://localhost:8080/api/v1/rooms/{{room-id}}/current GET http://localhost:8080/api/v1/rooms/{{room-id}}/current
### GET history of a room ### GET history of a room
GET http://localhost:8080/api/v1/rooms/{{room-id}}/history @window = 1 day
GET http://localhost:8080/api/v1/rooms/{{room-id}}/history?window={{window}}
### GET all rooms ### GET all rooms
GET http://localhost:8080/api/v1/rooms GET http://localhost:8080/api/v1/rooms

View File

@@ -112,6 +112,13 @@ const docTemplate = `{
"name": "room-id", "name": "room-id",
"in": "path", "in": "path",
"required": true "required": true
},
{
"type": "string",
"default": "1 day",
"description": "Time window (e.g., 1 day, 1 hour, 30 min)",
"name": "window",
"in": "query"
} }
], ],
"responses": { "responses": {

View File

@@ -106,6 +106,13 @@
"name": "room-id", "name": "room-id",
"in": "path", "in": "path",
"required": true "required": true
},
{
"type": "string",
"default": "1 day",
"description": "Time window (e.g., 1 day, 1 hour, 30 min)",
"name": "window",
"in": "query"
} }
], ],
"responses": { "responses": {

View File

@@ -68,6 +68,11 @@ paths:
name: room-id name: room-id
required: true required: true
type: string type: string
- default: 1 day
description: Time window (e.g., 1 day, 1 hour, 30 min)
in: query
name: window
type: string
produces: produces:
- application/json - application/json
responses: responses:

View File

@@ -125,15 +125,16 @@ func (g *RestGateway) getRoomCurrent(c *gin.Context) {
// @Tags rooms // @Tags rooms
// @Produce json // @Produce json
// @Param room-id path string true "Room ID" // @Param room-id path string true "Room ID"
// @Param window query string false "Time window (e.g., 1 day, 1 hour, 30 min)" default(1 day)
// @Success 200 {array} map[string]any // @Success 200 {array} map[string]any
// @Failure 500 {object} map[string]string // @Failure 500 {object} map[string]string
// @Router /rooms/{room-id}/history [get] // @Router /rooms/{room-id}/history [get]
func (g *RestGateway) getRoomHistory(c *gin.Context) { func (g *RestGateway) getRoomHistory(c *gin.Context) {
roomID := c.Param("room-id") roomID := c.Param("room-id")
window := c.DefaultQuery("window", "1 day")
// Default to last 24 hours if not specified query := fmt.Sprintf(` SELECT * FROM "%s" WHERE "room" = '%s' AND time > now() - INTERVAL '%s' ORDER BY time ASC
query := fmt.Sprintf(` SELECT * FROM "%s" WHERE "room" = '%s' AND time > now() - INTERVAL '1 day' ORDER BY time ASC `, g.measurementName, roomID, window)
`, g.measurementName, roomID)
// Using context.Background() as seen in working snippet // Using context.Background() as seen in working snippet
it, err := g.influxGateway.Query(context.Background(), query) it, err := g.influxGateway.Query(context.Background(), query)