feat(db): add parameter for time window in history endpoint
Signed-off-by: Klagarge <remi@heredero.ch>
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
GET http://localhost:8080/api/v1/rooms/{{room-id}}/current
|
||||
|
||||
### 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 http://localhost:8080/api/v1/rooms
|
||||
|
||||
@@ -112,6 +112,13 @@ const docTemplate = `{
|
||||
"name": "room-id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"default": "1 day",
|
||||
"description": "Time window (e.g., 1 day, 1 hour, 30 min)",
|
||||
"name": "window",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
||||
@@ -106,6 +106,13 @@
|
||||
"name": "room-id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"default": "1 day",
|
||||
"description": "Time window (e.g., 1 day, 1 hour, 30 min)",
|
||||
"name": "window",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
||||
@@ -68,6 +68,11 @@ paths:
|
||||
name: room-id
|
||||
required: true
|
||||
type: string
|
||||
- default: 1 day
|
||||
description: Time window (e.g., 1 day, 1 hour, 30 min)
|
||||
in: query
|
||||
name: window
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
||||
@@ -125,15 +125,16 @@ func (g *RestGateway) getRoomCurrent(c *gin.Context) {
|
||||
// @Tags rooms
|
||||
// @Produce json
|
||||
// @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
|
||||
// @Failure 500 {object} map[string]string
|
||||
// @Router /rooms/{room-id}/history [get]
|
||||
func (g *RestGateway) getRoomHistory(c *gin.Context) {
|
||||
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 '1 day' ORDER BY time ASC
|
||||
`, g.measurementName, roomID)
|
||||
query := fmt.Sprintf(` SELECT * FROM "%s" WHERE "room" = '%s' AND time > now() - INTERVAL '%s' ORDER BY time ASC
|
||||
`, g.measurementName, roomID, window)
|
||||
|
||||
// Using context.Background() as seen in working snippet
|
||||
it, err := g.influxGateway.Query(context.Background(), query)
|
||||
|
||||
Reference in New Issue
Block a user