func (this *Syncs) Create(req *http.Request, authUser models.AuthUser, render render.Render) { syncs := []models.Sync{} if decode(req, render, &syncs) != nil { return } tx := this.db.Begin() userIds := utils.Set{} for _, sync := range syncs { sync.UserId = authUser.Id if q := tx.Save(&sync); q.Error != nil { tx.Rollback() render.Error(500) return } for _, syncUser := range sync.SyncUsers { syncUser.SyncId = sync.Id if syncUser.UserId != authUser.Id { userIds.Insert(syncUser.UserId) } if q := tx.Save(&syncUser); q.Error != nil { tx.Rollback() render.Error(500) return } } } if q := tx.Commit(); q.Error != nil { tx.Rollback() render.Error(500) return } go this.sendPushNotifications(userIds.ToSlice()) if authUser.FetchSyncs(this.db) != nil { render.Error(500) return } render.JSON(http.StatusOK, map[string]interface{}{"results": authUser.Syncs}) }
func (this *Syncs) Index(authUser models.AuthUser, render render.Render) { if authUser.FetchSyncs(this.db) != nil { render.Error(500) } render.JSON(200, map[string]interface{}{"results": authUser.Syncs}) }