fix(db): return only high co2 room for co2-status endpoint
Signed-off-by: Klagarge <remi@heredero.ch>
This commit is contained in:
@@ -13,7 +13,7 @@ GET {{host}}/api/v1/rooms/{{room-id}}/history?window={{window}}
|
||||
Authorization: Basic {{username}} {{password}}
|
||||
|
||||
### GET CO2 status of all rooms
|
||||
GET {{host}}/api/v1/rooms/co2-status
|
||||
GET {{host}}/api/v1/rooms/high-co2
|
||||
Authorization: Basic {{username}} {{password}}
|
||||
|
||||
### GET all rooms
|
||||
|
||||
@@ -159,21 +159,21 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/rooms/co2-status": {
|
||||
"/rooms/high-co2": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"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": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"rooms"
|
||||
],
|
||||
"summary": "Get CO2 status for all rooms",
|
||||
"summary": "Get rooms with high CO2 levels",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
|
||||
@@ -153,21 +153,21 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/rooms/co2-status": {
|
||||
"/rooms/high-co2": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"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": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"rooms"
|
||||
],
|
||||
"summary": "Get CO2 status for all rooms",
|
||||
"summary": "Get rooms with high CO2 levels",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
|
||||
@@ -178,9 +178,9 @@ paths:
|
||||
summary: Get history for a room
|
||||
tags:
|
||||
- rooms
|
||||
/rooms/co2-status:
|
||||
/rooms/high-co2:
|
||||
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:
|
||||
- application/json
|
||||
responses:
|
||||
@@ -192,7 +192,7 @@ paths:
|
||||
type: array
|
||||
security:
|
||||
- BasicAuth: []
|
||||
summary: Get CO2 status for all rooms
|
||||
summary: Get rooms with high CO2 levels
|
||||
tags:
|
||||
- rooms
|
||||
securityDefinitions:
|
||||
|
||||
@@ -107,7 +107,7 @@ func (g *RestGateway) setupRoutes() {
|
||||
v1.GET("/rooms", g.getRooms)
|
||||
v1.GET("/rooms/:room-id/current", g.getRoomCurrent)
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -569,22 +569,24 @@ func (g *RestGateway) checkCO2() {
|
||||
}
|
||||
}
|
||||
|
||||
// GET /api/v1/rooms/co2-status
|
||||
// getRoomCO2Status godoc
|
||||
// @Summary Get CO2 status for all rooms
|
||||
// @Description Get a list of all rooms with their CO2 status and value
|
||||
// GET /api/v1/rooms/high-co2
|
||||
// getHighCO2Rooms godoc
|
||||
// @Summary Get rooms with high CO2 levels
|
||||
// @Description Get a list of rooms where CO2 levels are above the threshold
|
||||
// @Tags rooms
|
||||
// @Produce json
|
||||
// @Success 200 {array} RoomCO2Status
|
||||
// @Security BasicAuth
|
||||
// @Router /rooms/co2-status [get]
|
||||
func (g *RestGateway) getRoomCO2Status(c *gin.Context) {
|
||||
// @Router /rooms/high-co2 [get]
|
||||
func (g *RestGateway) getHighCO2Rooms(c *gin.Context) {
|
||||
g.statusMu.RLock()
|
||||
defer g.statusMu.RUnlock()
|
||||
|
||||
var result []RoomCO2Status
|
||||
var result = []RoomCO2Status{}
|
||||
for _, status := range g.roomStatus {
|
||||
result = append(result, *status)
|
||||
if status.IsHigh {
|
||||
result = append(result, *status)
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by room ID for stability
|
||||
|
||||
Reference in New Issue
Block a user