|
@@ -21,17 +21,15 @@ func sessionPreloads(db *gorm.DB) *gorm.DB {
|
|
|
}).Preload("Assets")
|
|
}).Preload("Assets")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// GetSessions supports cursor-like incremental pulls with updatedAfter and can
|
|
|
|
|
-// include deletion tombstones for multi-device reconciliation.
|
|
|
|
|
|
|
+// GetSessions is the lightweight first phase of synchronization. It supports
|
|
|
|
|
+// cursor-like incremental pulls and deletion tombstones without preloading
|
|
|
|
|
+// concrete event or asset content.
|
|
|
func (h *SessionHandler) GetSessions(c *gin.Context) {
|
|
func (h *SessionHandler) GetSessions(c *gin.Context) {
|
|
|
userID := c.GetString("userID")
|
|
userID := c.GetString("userID")
|
|
|
- query := sessionPreloads(h.DB).Where("user_id = ?", userID)
|
|
|
|
|
|
|
+ query := h.DB.Where("user_id = ?", userID)
|
|
|
if c.Query("includeDeleted") != "true" {
|
|
if c.Query("includeDeleted") != "true" {
|
|
|
query = query.Where("deleted_at IS NULL")
|
|
query = query.Where("deleted_at IS NULL")
|
|
|
}
|
|
}
|
|
|
- if search := c.Query("search"); search != "" {
|
|
|
|
|
- query = query.Where("title ILIKE ?", "%"+search+"%")
|
|
|
|
|
- }
|
|
|
|
|
if value := c.Query("updatedAfter"); value != "" {
|
|
if value := c.Query("updatedAfter"); value != "" {
|
|
|
updatedAfter, err := time.Parse(time.RFC3339Nano, value)
|
|
updatedAfter, err := time.Parse(time.RFC3339Nano, value)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -45,7 +43,11 @@ func (h *SessionHandler) GetSessions(c *gin.Context) {
|
|
|
respondError(c, http.StatusInternalServerError, 500, "failed to query field records")
|
|
respondError(c, http.StatusInternalServerError, 500, "failed to query field records")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- respondSuccess(c, sessions)
|
|
|
|
|
|
|
+ index := make([]models.SessionSyncIndexItem, 0, len(sessions))
|
|
|
|
|
+ for _, session := range sessions {
|
|
|
|
|
+ index = append(index, session.SyncIndexItem())
|
|
|
|
|
+ }
|
|
|
|
|
+ respondSuccess(c, index)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (h *SessionHandler) GetSessionDetail(c *gin.Context) {
|
|
func (h *SessionHandler) GetSessionDetail(c *gin.Context) {
|