fix(db): return only high co2 room for co2-status endpoint

Signed-off-by: Klagarge <remi@heredero.ch>
This commit is contained in:
2026-05-31 12:21:47 +02:00
parent 811641c58b
commit 89023b86ac
5 changed files with 21 additions and 19 deletions

View File

@@ -13,7 +13,7 @@ GET {{host}}/api/v1/rooms/{{room-id}}/history?window={{window}}
Authorization: Basic {{username}} {{password}} Authorization: Basic {{username}} {{password}}
### GET CO2 status of all rooms ### GET CO2 status of all rooms
GET {{host}}/api/v1/rooms/co2-status GET {{host}}/api/v1/rooms/high-co2
Authorization: Basic {{username}} {{password}} Authorization: Basic {{username}} {{password}}
### GET all rooms ### GET all rooms

View File

@@ -159,21 +159,21 @@ const docTemplate = `{
} }
} }
}, },
"/rooms/co2-status": { "/rooms/high-co2": {
"get": { "get": {
"security": [ "security": [
{ {
"BasicAuth": [] "BasicAuth": []
} }
], ],
"description": "Get a list of all rooms with their CO2 status and value", "description": "Get a list of rooms where CO2 levels are above the threshold",
"produces": [ "produces": [
"application/json" "application/json"
], ],
"tags": [ "tags": [
"rooms" "rooms"
], ],
"summary": "Get CO2 status for all rooms", "summary": "Get rooms with high CO2 levels",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",

View File

@@ -153,21 +153,21 @@
} }
} }
}, },
"/rooms/co2-status": { "/rooms/high-co2": {
"get": { "get": {
"security": [ "security": [
{ {
"BasicAuth": [] "BasicAuth": []
} }
], ],
"description": "Get a list of all rooms with their CO2 status and value", "description": "Get a list of rooms where CO2 levels are above the threshold",
"produces": [ "produces": [
"application/json" "application/json"
], ],
"tags": [ "tags": [
"rooms" "rooms"
], ],
"summary": "Get CO2 status for all rooms", "summary": "Get rooms with high CO2 levels",
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",

View File

@@ -178,9 +178,9 @@ paths:
summary: Get history for a room summary: Get history for a room
tags: tags:
- rooms - rooms
/rooms/co2-status: /rooms/high-co2:
get: get:
description: Get a list of all rooms with their CO2 status and value description: Get a list of rooms where CO2 levels are above the threshold
produces: produces:
- application/json - application/json
responses: responses:
@@ -192,7 +192,7 @@ paths:
type: array type: array
security: security:
- BasicAuth: [] - BasicAuth: []
summary: Get CO2 status for all rooms summary: Get rooms with high CO2 levels
tags: tags:
- rooms - rooms
securityDefinitions: securityDefinitions:

View File

@@ -107,7 +107,7 @@ func (g *RestGateway) setupRoutes() {
v1.GET("/rooms", g.getRooms) v1.GET("/rooms", g.getRooms)
v1.GET("/rooms/:room-id/current", g.getRoomCurrent) v1.GET("/rooms/:room-id/current", g.getRoomCurrent)
v1.GET("/rooms/:room-id/history", g.getRoomHistory) v1.GET("/rooms/:room-id/history", g.getRoomHistory)
v1.GET("/rooms/co2-status", g.getRoomCO2Status) v1.GET("/rooms/high-co2", g.getHighCO2Rooms)
v1.GET("/export/csv", g.getExportCSV) v1.GET("/export/csv", g.getExportCSV)
} }
@@ -569,22 +569,24 @@ func (g *RestGateway) checkCO2() {
} }
} }
// GET /api/v1/rooms/co2-status // GET /api/v1/rooms/high-co2
// getRoomCO2Status godoc // getHighCO2Rooms godoc
// @Summary Get CO2 status for all rooms // @Summary Get rooms with high CO2 levels
// @Description Get a list of all rooms with their CO2 status and value // @Description Get a list of rooms where CO2 levels are above the threshold
// @Tags rooms // @Tags rooms
// @Produce json // @Produce json
// @Success 200 {array} RoomCO2Status // @Success 200 {array} RoomCO2Status
// @Security BasicAuth // @Security BasicAuth
// @Router /rooms/co2-status [get] // @Router /rooms/high-co2 [get]
func (g *RestGateway) getRoomCO2Status(c *gin.Context) { func (g *RestGateway) getHighCO2Rooms(c *gin.Context) {
g.statusMu.RLock() g.statusMu.RLock()
defer g.statusMu.RUnlock() defer g.statusMu.RUnlock()
var result []RoomCO2Status var result = []RoomCO2Status{}
for _, status := range g.roomStatus { for _, status := range g.roomStatus {
result = append(result, *status) if status.IsHigh {
result = append(result, *status)
}
} }
// Sort by room ID for stability // Sort by room ID for stability