feat(db): add co2-status endpoint in REST API
This endpoint get the co2 status and return for each room if the co2 is too high or in the acceptable level Assisted-by: Junie:gemini-3-flash Signed-off-by: Klagarge <remi@heredero.ch>
This commit is contained in:
@@ -12,6 +12,10 @@ Authorization: Basic {{username}} {{password}}
|
||||
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
|
||||
Authorization: Basic {{username}} {{password}}
|
||||
|
||||
### GET all rooms
|
||||
GET {{host}}/api/v1/rooms
|
||||
Authorization: Basic {{username}} {{password}}
|
||||
|
||||
@@ -159,6 +159,34 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/rooms/co2-status": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"BasicAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Get a list of all rooms with their CO2 status and value",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"rooms"
|
||||
],
|
||||
"summary": "Get CO2 status for all rooms",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/rest.RoomCO2Status"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/rooms/{room-id}/current": {
|
||||
"get": {
|
||||
"security": [
|
||||
@@ -267,6 +295,22 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"rest.RoomCO2Status": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"co2": {
|
||||
"type": "integer"
|
||||
},
|
||||
"is_high": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"room": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"BasicAuth": {
|
||||
"type": "basic"
|
||||
|
||||
@@ -153,6 +153,34 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/rooms/co2-status": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"BasicAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Get a list of all rooms with their CO2 status and value",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"rooms"
|
||||
],
|
||||
"summary": "Get CO2 status for all rooms",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/rest.RoomCO2Status"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/rooms/{room-id}/current": {
|
||||
"get": {
|
||||
"security": [
|
||||
@@ -261,6 +289,22 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"rest.RoomCO2Status": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"co2": {
|
||||
"type": "integer"
|
||||
},
|
||||
"is_high": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"room": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"BasicAuth": {
|
||||
"type": "basic"
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
basePath: /api/v1
|
||||
definitions:
|
||||
rest.RoomCO2Status:
|
||||
properties:
|
||||
co2:
|
||||
type: integer
|
||||
is_high:
|
||||
type: boolean
|
||||
room:
|
||||
type: string
|
||||
type: object
|
||||
host: api.db.e.kb28.ch
|
||||
info:
|
||||
contact: {}
|
||||
@@ -168,6 +178,23 @@ paths:
|
||||
summary: Get history for a room
|
||||
tags:
|
||||
- rooms
|
||||
/rooms/co2-status:
|
||||
get:
|
||||
description: Get a list of all rooms with their CO2 status and value
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/rest.RoomCO2Status'
|
||||
type: array
|
||||
security:
|
||||
- BasicAuth: []
|
||||
summary: Get CO2 status for all rooms
|
||||
tags:
|
||||
- rooms
|
||||
securityDefinitions:
|
||||
BasicAuth:
|
||||
type: basic
|
||||
|
||||
@@ -107,6 +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("/export/csv", g.getExportCSV)
|
||||
}
|
||||
|
||||
@@ -557,3 +558,29 @@ 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
|
||||
// @Tags rooms
|
||||
// @Produce json
|
||||
// @Success 200 {array} RoomCO2Status
|
||||
// @Security BasicAuth
|
||||
// @Router /rooms/co2-status [get]
|
||||
func (g *RestGateway) getRoomCO2Status(c *gin.Context) {
|
||||
g.statusMu.RLock()
|
||||
defer g.statusMu.RUnlock()
|
||||
|
||||
var result []RoomCO2Status
|
||||
for _, status := range g.roomStatus {
|
||||
result = append(result, *status)
|
||||
}
|
||||
|
||||
// Sort by room ID for stability
|
||||
slices.SortFunc(result, func(a, b RoomCO2Status) int {
|
||||
return strings.Compare(a.RoomID, b.RoomID)
|
||||
})
|
||||
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user