mirror of
https://github.com/kaaninchen/Laterna.git
synced 2026-09-17 19:12:48 +00:00
✨ feat(colors): Add a route which lists all available controllers with their metadata
This commit is contained in:
@@ -15,7 +15,7 @@ func CreateController() (int64, error) {
|
||||
logger.DBLogger.Printf("Error creating controller: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
logger.DBLogger.Printf("Error fetching controller ID: %v", err)
|
||||
@@ -70,6 +70,25 @@ func ControllerExists(id int) bool {
|
||||
return count > 0
|
||||
}
|
||||
|
||||
func GetAllColors() ([]models.LampState, error) {
|
||||
rows, err := DB.Query("SELECT id, color, updated_at FROM controllers WHERE id > 0")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var controllers []models.LampState
|
||||
|
||||
for rows.Next() {
|
||||
var state models.LampState
|
||||
if err := rows.Scan(&state.ID, &state.Color, &state.UpdatedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
controllers = append(controllers, state)
|
||||
}
|
||||
return controllers, nil
|
||||
}
|
||||
|
||||
func ViewColor(id int) (*models.LampState, error) {
|
||||
row := DB.QueryRow("SELECT id, color, updated_at FROM controllers WHERE id = ?", id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user