コード例 #1
0
ファイル: account.go プロジェクト: shevilangle/sports
func recommendHandler(r *http.Request, w http.ResponseWriter,
	redis *models.RedisLogger, user *models.Account, p Parameter) {

	form := p.(recommendForm)

	excludes := redis.Friends(models.RelFollowing, user.Id)
	excludes = append(excludes, redis.Friends(models.RelBlacklist, user.Id)...)

	users, _ := user.Recommend(excludes)
	var list []*leaderboardResp
	for i, _ := range users {
		if users[i].Id == user.Id {
			continue
		}
		rel := redis.Relationship(user.Id, users[i].Id)
		if rel == models.RelFollowing || rel == models.RelFriend {
			continue
		}

		lb := &leaderboardResp{
			Userid:   users[i].Id,
			Score:    users[i].Props.Score,
			Level:    users[i].Level(),
			Profile:  users[i].Profile,
			Nickname: users[i].Nickname,
			Gender:   users[i].Gender,
			LastLog:  users[i].LastLogin.Unix(),
			Birth:    users[i].Birth,
			Location: users[i].Loc,
			Addr:     users[i].LocAddr,
			Phone:    users[i].Phone,
			Actor:    users[i].Actor,
		}
		lb.Distance, _ = redis.RecStats(users[i].Id)
		lb.Status = users[i].LatestArticle().Title
		list = append(list, lb)
	}

	respData := map[string]interface{}{
		"members_list":  list,
		"page_frist_id": form.Paging.First,
		"page_last_id":  form.Paging.Last,
	}
	writeResponse(r.RequestURI, w, respData, nil)
}
コード例 #2
0
ファイル: article.go プロジェクト: shevilangle/sports
func articleListHandler(request *http.Request, resp http.ResponseWriter,
	redis *models.RedisLogger, user *models.Account, p Parameter) {
	var articles []models.Article
	var err error
	form := p.(articleListForm)

	if len(form.Tag) > 0 {
		_, articles, err = models.GetArticles(form.Tag, &form.Paging, true)
	} else if form.Circle {
		followings := redis.Friends(models.RelFollowing, user.Id)
		followings = append(followings, user.Id) // self included
		_, articles, err = models.GetFollowingsArticles(followings, &form.Paging)
	} else {
		excludes := redis.Friends(models.RelFollowing, user.Id)
		excludes = append(excludes, redis.Friends(models.RelBlacklist, user.Id)...)
		excludes = append(excludes, user.Id)
		recommends, _ := user.Recommend(excludes)
		ids := []string{}
		for i, _ := range recommends {
			ids = append(ids, recommends[i].Id)
		}
		_, articles, err = models.GetRecommendArticles(ids, &form.Paging)
	}

	jsonStructs := make([]*articleJsonStruct, len(articles))
	for i, _ := range articles {
		u := &models.Account{}
		u.FindByUserid(articles[i].Author)
		author := convertUser(u, redis)
		jsonStructs[i] = convertArticle(user, &articles[i], author)
	}

	respData := make(map[string]interface{})
	respData["page_frist_id"] = form.Paging.First
	respData["page_last_id"] = form.Paging.Last
	//respData["page_item_count"] = total
	respData["articles_without_content"] = jsonStructs
	writeResponse(request.RequestURI, resp, respData, err)
}