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:
@@ -489,6 +489,31 @@ func (h *DeviceHandler) RejectDevice(c echo.Context) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *DeviceHandler) GetPendingRegistrationsData(c echo.Context) ([]map[string]interface{}, error) {
|
||||||
|
userID := c.Get("user_id").(string)
|
||||||
|
userUUID, err := uuid.Parse(userID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
registrations := []map[string]interface{}{}
|
||||||
|
for _, reg := range pendingRegistrations {
|
||||||
|
if reg.UserID == userUUID || reg.UserID == (uuid.UUID{}) {
|
||||||
|
registrations = append(registrations, map[string]interface{}{
|
||||||
|
"registration_id": reg.RegistrationID,
|
||||||
|
"device_name": reg.DeviceName,
|
||||||
|
"device_type": reg.DeviceType,
|
||||||
|
"device_identifier": reg.DeviceIdentifier,
|
||||||
|
"expires_at": reg.ExpiresAt,
|
||||||
|
"created_at": reg.CreatedAt,
|
||||||
|
"is_approved": reg.UserID != (uuid.UUID{}),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return registrations, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (h *DeviceHandler) ListPendingRegistrations(c echo.Context) error {
|
func (h *DeviceHandler) ListPendingRegistrations(c echo.Context) error {
|
||||||
userID := c.Get("user_id").(string)
|
userID := c.Get("user_id").(string)
|
||||||
userUUID, err := uuid.Parse(userID)
|
userUUID, err := uuid.Parse(userID)
|
||||||
|
|||||||
+14
-13
@@ -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)
|
user := MustGetAuthenticatedUser(c)
|
||||||
|
|
||||||
if user.Role != "admin" {
|
if user.Role != "admin" {
|
||||||
return echo.NewHTTPError(http.StatusForbidden, "admin access required")
|
return nil, echo.NewHTTPError(http.StatusForbidden, "admin access required")
|
||||||
}
|
}
|
||||||
|
|
||||||
limit := 50
|
limit := 50
|
||||||
@@ -173,21 +173,15 @@ func (h *QueueHandler) ListAllQueueItems(c echo.Context) error {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "failed to list queue items")
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
response := make([]QueueItemResponse, 0, len(items))
|
response := make([]QueueItemResponse, 0, len(items))
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
mediaTitle := textPtrToString(item.MediaTitle)
|
|
||||||
|
|
||||||
response = append(response, QueueItemResponse{
|
response = append(response, QueueItemResponse{
|
||||||
ID: uuid.UUID(item.ID.Bytes).String(),
|
ID: uuid.UUID(item.ID.Bytes).String(),
|
||||||
DeviceID: uuid.UUID(item.DeviceID.Bytes).String(),
|
DeviceID: uuid.UUID(item.DeviceID.Bytes).String(),
|
||||||
DeviceName: item.DeviceName,
|
|
||||||
DeviceType: item.DeviceType,
|
|
||||||
MediaItemID: uuidPtrToString(item.MediaItemID),
|
MediaItemID: uuidPtrToString(item.MediaItemID),
|
||||||
MediaTitle: mediaTitle,
|
|
||||||
UserEmail: item.UserEmail,
|
|
||||||
SyncType: item.SyncType,
|
SyncType: item.SyncType,
|
||||||
Priority: item.Priority.Int32,
|
Priority: item.Priority.Int32,
|
||||||
Attempts: item.Attempts.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{}{
|
return c.JSON(http.StatusOK, map[string]interface{}{
|
||||||
"items": response,
|
"items": response,
|
||||||
"count": len(response),
|
"count": len(response),
|
||||||
"limit": limit,
|
|
||||||
"offset": offset,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,3 +11,65 @@ type PageData struct {
|
|||||||
User User
|
User User
|
||||||
CurrentPage string
|
CurrentPage string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CollectionData struct {
|
||||||
|
ID string
|
||||||
|
Name string
|
||||||
|
Description string
|
||||||
|
Color string
|
||||||
|
Icon string
|
||||||
|
}
|
||||||
|
|
||||||
|
type CollectionDetailData struct {
|
||||||
|
ID string
|
||||||
|
Name string
|
||||||
|
Description string
|
||||||
|
Color string
|
||||||
|
Icon string
|
||||||
|
}
|
||||||
|
|
||||||
|
type BookData struct {
|
||||||
|
MediaItemID string
|
||||||
|
Title string
|
||||||
|
Author string
|
||||||
|
CoverImagePath string
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeviceData struct {
|
||||||
|
ID string
|
||||||
|
DeviceName string
|
||||||
|
DeviceType string
|
||||||
|
SyncEnabled bool
|
||||||
|
AutoSync bool
|
||||||
|
SyncFrequency int32
|
||||||
|
LastSync string
|
||||||
|
LastSeen string
|
||||||
|
}
|
||||||
|
|
||||||
|
type PendingRegistrationData struct {
|
||||||
|
RegistrationID string
|
||||||
|
DeviceName string
|
||||||
|
DeviceType string
|
||||||
|
ExpiresAt string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConflictData struct {
|
||||||
|
ID string
|
||||||
|
MediaItemID string
|
||||||
|
MediaItemTitle string
|
||||||
|
ConflictType string
|
||||||
|
ResolutionStatus string
|
||||||
|
CreatedAt string
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueueItemData struct {
|
||||||
|
ID string
|
||||||
|
DeviceID string
|
||||||
|
DeviceName string
|
||||||
|
DeviceType string
|
||||||
|
SyncType string
|
||||||
|
Status string
|
||||||
|
Priority int32
|
||||||
|
Attempts int32
|
||||||
|
CreatedAt string
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user