feat(api): add setup_complete system setting and status handlers
Add 'setup_complete' boolean to the system_settings seed data (defaults
to false) so fresh databases start in the unconfigured state.
Add two new handlers to SystemSettingsHandler:
- SetSetupComplete: marks setup_complete=true in the database
- GetSetupStatus: reads the current setup_complete value, returns
{setup_complete: bool} JSON response, defaults to false if the
setting row is missing or unparseable
This commit is contained in:
@@ -95,6 +95,32 @@ func (h *SystemSettingsHandler) UpdateScanSettings(c *echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *SystemSettingsHandler) SetSetupComplete(c *echo.Context) error {
|
||||
err := h.db.UpdateSystemSetting(c.Request().Context(), database.UpdateSystemSettingParams{
|
||||
SettingKey: "setup_complete",
|
||||
SettingValue: "true",
|
||||
})
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(http.StatusOK, map[string]string{"message": "setup complete"})
|
||||
}
|
||||
|
||||
func (h *SystemSettingsHandler) GetSetupStatus(c *echo.Context) error {
|
||||
val, err := h.db.GetSystemSetting(c.Request().Context(), "setup_complete")
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return c.JSON(http.StatusOK, map[string]bool{"setup_complete": false})
|
||||
}
|
||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||
}
|
||||
complete, err := strconv.ParseBool(val)
|
||||
if err != nil {
|
||||
complete = false
|
||||
}
|
||||
return c.JSON(http.StatusOK, map[string]bool{"setup_complete": complete})
|
||||
}
|
||||
|
||||
func (h *SystemSettingsHandler) GetScanSettings(c *echo.Context) error {
|
||||
scanFrequencySetting, err := h.db.GetSystemSetting(c.Request().Context(), "scan_poll_interval_seconds")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user