Files
hamview/server/handlers_radios.go
maze 13afa08e8a
Some checks failed
Test and build / Test and lint (push) Failing after 36s
Test and build / Build collector (push) Failing after 43s
Test and build / Build receiver (push) Failing after 42s
Checkpoint
2026-03-05 15:38:18 +01:00

69 lines
1.4 KiB
Go

package server
import (
"net/http"
"github.com/labstack/echo/v4"
"git.maze.io/ham/hamview/schema"
)
// handleGetRadios returns a list of radio stations/receivers.
//
// Endpoint: GET /api/v1/radios
// Endpoint: GET /api/v1/radios/:protocol
//
// Path Parameters:
// - protocol (optional): Filter by protocol name (e.g., "meshcore", "aprs")
//
// Response: 200 OK
//
// []Radio - Array of radio objects
//
// Response: 500 Internal Server Error
//
// ErrorResponse - Error retrieving radios
//
// Example Request:
//
// GET /api/v1/radios
// GET /api/v1/radios/meshcore
//
// Example Response:
//
// [
// {
// "id": 1,
// "name": "Station-Alpha",
// "is_online": true,
// "manufacturer": "Heltec",
// "device": "WiFi LoRa 32 V3",
// "modulation": "LoRa",
// "protocol": "meshcore",
// "latitude": 52.3667,
// "longitude": 4.8945,
// "frequency": 868.1,
// "bandwidth": 125.0,
// "created_at": "2026-01-01T12:00:00Z",
// "updated_at": "2026-03-05T10:30:00Z"
// }
// ]
func (s *Server) handleGetRadios(c echo.Context) error {
var (
radios []*schema.Radio
err error
)
if protocol := c.Param("protocol"); protocol != "" {
radios, err = schema.GetRadiosByProtocol(c.Request().Context(), protocol)
} else {
radios, err = schema.GetRadios(c.Request().Context())
}
if err != nil {
return s.apiError(c, err)
}
return c.JSON(http.StatusOK, radios)
}