feat(handlers): Add helper methods for hybrid SSR

- Add GetPendingRegistrationsData() to DeviceHandler
- Add GetQueueData() to QueueHandler
- Add template types: DeviceData, PendingRegistrationData, ConflictData, QueueItemData
- Add collection types: CollectionData, CollectionDetailData, BookData

All changes are non-breaking and preserve API compatibility
This commit is contained in:
2026-01-31 22:31:33 -05:00
parent 56a9159631
commit cd8f313b16
3 changed files with 101 additions and 13 deletions
+14 -13
View File
@@ -146,11 +146,11 @@ func (h *QueueHandler) ListDeviceQueueItems(c echo.Context) error {
})
}
func (h *QueueHandler) ListAllQueueItems(c echo.Context) error {
func (h *QueueHandler) GetQueueData(c echo.Context) ([]QueueItemResponse, error) {
user := MustGetAuthenticatedUser(c)
if user.Role != "admin" {
return echo.NewHTTPError(http.StatusForbidden, "admin access required")
return nil, echo.NewHTTPError(http.StatusForbidden, "admin access required")
}
limit := 50
@@ -173,21 +173,15 @@ func (h *QueueHandler) ListAllQueueItems(c echo.Context) error {
})
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to list queue items")
return nil, err
}
response := make([]QueueItemResponse, 0, len(items))
for _, item := range items {
mediaTitle := textPtrToString(item.MediaTitle)
response = append(response, QueueItemResponse{
ID: uuid.UUID(item.ID.Bytes).String(),
DeviceID: uuid.UUID(item.DeviceID.Bytes).String(),
DeviceName: item.DeviceName,
DeviceType: item.DeviceType,
MediaItemID: uuidPtrToString(item.MediaItemID),
MediaTitle: mediaTitle,
UserEmail: item.UserEmail,
SyncType: item.SyncType,
Priority: item.Priority.Int32,
Attempts: item.Attempts.Int32,
@@ -199,11 +193,18 @@ func (h *QueueHandler) ListAllQueueItems(c echo.Context) error {
})
}
return response, nil
}
func (h *QueueHandler) ListAllQueueItems(c echo.Context) error {
response, err := h.GetQueueData(c)
if err != nil {
return err
}
return c.JSON(http.StatusOK, map[string]interface{}{
"items": response,
"count": len(response),
"limit": limit,
"offset": offset,
"items": response,
"count": len(response),
})
}