refactor(handlers): remove per-user scan settings handlers
Clean up auth.go after migrating to system-wide settings: - Remove UpdateScanSettings handler (moved to system_settings.go) - Remove GetScanSettings handler (moved to system_settings.go) - Remove UpdateScanSettingsRequest type (now in system_settings.go) These handlers are now in SystemSettingsHandler with system-wide scope instead of per-user functionality.
This commit is contained in:
@@ -700,57 +700,6 @@ func (h *AuthHandler) DeleteAccount(c echo.Context) error {
|
|||||||
return c.JSON(http.StatusOK, map[string]string{"message": message})
|
return c.JSON(http.StatusOK, map[string]string{"message": message})
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateScanSettingsRequest struct {
|
|
||||||
ScanFrequencyMinutes int32 `json:"scan_frequency_minutes" validate:"required,min=15,max=1440"`
|
|
||||||
AutoScanEnabled bool `json:"auto_scan_enabled"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateScanSettings handles PUT /api/library/scan-settings
|
|
||||||
func (h *AuthHandler) UpdateScanSettings(c echo.Context) error {
|
|
||||||
user := MustGetAuthenticatedUser(c)
|
|
||||||
|
|
||||||
var req UpdateScanSettingsRequest
|
|
||||||
if err := c.Bind(&req); err != nil {
|
|
||||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid request"})
|
|
||||||
}
|
|
||||||
if err := c.Validate(&req); err != nil {
|
|
||||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()})
|
|
||||||
}
|
|
||||||
|
|
||||||
err := h.db.UpdateScanSettings(c.Request().Context(), database.UpdateScanSettingsParams{
|
|
||||||
ID: user.ID,
|
|
||||||
ScanFrequencyMinutes: pgtype.Int4{Int32: req.ScanFrequencyMinutes, Valid: true},
|
|
||||||
AutoScanEnabled: pgtype.Bool{Bool: req.AutoScanEnabled, Valid: true},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, map[string]string{"message": "scan settings updated successfully"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetScanSettings handles GET /api/library/scan-settings
|
|
||||||
func (h *AuthHandler) GetScanSettings(c echo.Context) error {
|
|
||||||
user := MustGetAuthenticatedUser(c)
|
|
||||||
|
|
||||||
settings, err := h.db.GetScanSettings(c.Request().Context(), user.ID)
|
|
||||||
if err != nil {
|
|
||||||
if err == pgx.ErrNoRows {
|
|
||||||
// If no settings found, return defaults
|
|
||||||
return c.JSON(http.StatusOK, map[string]interface{}{
|
|
||||||
"scan_frequency_minutes": 60,
|
|
||||||
"auto_scan_enabled": true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, map[string]interface{}{
|
|
||||||
"scan_frequency_minutes": settings.ScanFrequencyMinutes.Int32,
|
|
||||||
"auto_scan_enabled": settings.AutoScanEnabled.Bool,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateUserMaxDevicesRequest struct {
|
type UpdateUserMaxDevicesRequest struct {
|
||||||
MaxDevices int32 `json:"max_devices" validate:"required,min=1,max=100"`
|
MaxDevices int32 `json:"max_devices" validate:"required,min=1,max=100"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user