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:
@@ -49,7 +49,8 @@ CREATE TABLE IF NOT EXISTS system_settings (
|
|||||||
INSERT INTO system_settings (setting_key, setting_value, description) VALUES
|
INSERT INTO system_settings (setting_key, setting_value, description) VALUES
|
||||||
('scan_poll_interval_seconds', '60', 'How often to scan all libraries in minutes'),
|
('scan_poll_interval_seconds', '60', 'How often to scan all libraries in minutes'),
|
||||||
('auto_scan_enabled', 'true', 'Whether auto-scanning is enabled system-wide'),
|
('auto_scan_enabled', 'true', 'Whether auto-scanning is enabled system-wide'),
|
||||||
('default_timezone', 'UTC', 'System default timezone')
|
('default_timezone', 'UTC', 'System default timezone'),
|
||||||
|
('setup_complete', 'false', 'Whether the initial setup wizard has been completed')
|
||||||
ON CONFLICT (setting_key) DO NOTHING;
|
ON CONFLICT (setting_key) DO NOTHING;
|
||||||
|
|
||||||
-- Create refresh_tokens table
|
-- Create refresh_tokens table
|
||||||
|
|||||||
@@ -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 {
|
func (h *SystemSettingsHandler) GetScanSettings(c *echo.Context) error {
|
||||||
scanFrequencySetting, err := h.db.GetSystemSetting(c.Request().Context(), "scan_poll_interval_seconds")
|
scanFrequencySetting, err := h.db.GetSystemSetting(c.Request().Context(), "scan_poll_interval_seconds")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user