本文整理汇总了Golang中Model.NewTopic函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTopic函数的具体用法?Golang NewTopic怎么用?Golang NewTopic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTopic函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: IncrTopicReply
func IncrTopicReply(tid string, uid int) (err error) {
err = model.NewTopic().Where("tid="+tid).Increment("reply", 1)
if err != nil {
logger.Errorln("更新帖子reply数失败:", err)
}
return
}
示例2: NewTopicHandler
// 新建帖子
// uri: /topics/new{json:(|.json)}
func NewTopicHandler(rw http.ResponseWriter, req *http.Request) {
nodes := genNodes()
vars := mux.Vars(req)
title := req.FormValue("title")
// 请求新建帖子页面
if title == "" || req.Method != "POST" || vars["json"] == "" {
req.Form.Set(filter.CONTENT_TPL_KEY, "/template/topics/new.html")
filter.SetData(req, map[string]interface{}{"nodes": nodes})
return
}
user, _ := filter.CurrentUser(req)
// 入库
topic := model.NewTopic()
topic.Uid = user["uid"].(int)
topic.Nid = util.MustInt(req.FormValue("nid"))
topic.Title = req.FormValue("title")
topic.Content = req.FormValue("content")
errMsg, err := service.PublishTopic(topic)
if err != nil {
fmt.Fprint(rw, `{"errno": 1, "error":"`, errMsg, `"}`)
return
}
fmt.Fprint(rw, `{"errno": 0, "error":""}`)
}
示例3: FindTopicByTid
// 获得帖子详细信息(包括详细回复)
// 为了避免转换,tid传string类型
func FindTopicByTid(tid string) (topicMap map[string]interface{}, replies []map[string]interface{}, err error) {
condition := "tid=" + tid
// 帖子信息
topic := model.NewTopic()
err = topic.Where(condition).Find()
if err != nil {
logger.Errorln("topic service FindTopicByTid Error:", err)
return
}
// 帖子不存在
if topic.Tid == 0 {
return
}
topicMap = make(map[string]interface{})
util.Struct2Map(topicMap, topic)
// 节点名字
topicMap["node"] = model.GetNodeName(topic.Nid)
// 回复信息(评论)
replies, owerUser, lastReplyUser := FindObjComments(tid, strconv.Itoa(model.TYPE_TOPIC), topic.Uid, topic.Lastreplyuid)
topicMap["user"] = owerUser
// 有人回复
if topic.Lastreplyuid != 0 {
topicMap["lastreplyusername"] = lastReplyUser.Username
}
return
}
示例4: TopicsTotal
// 话题总数
func TopicsTotal() (total int) {
total, err := model.NewTopic().Count()
if err != nil {
logger.Errorln("topic service TopicsTotal error:", err)
}
return
}
示例5: FindTopicByTid
// 获得帖子详细信息(包括详细回复)
// 为了避免转换,tid传string类型
func FindTopicByTid(tid string) (topicMap map[string]interface{}, replies []map[string]interface{}, err error) {
condition := "tid=" + tid
// 帖子信息
topic := model.NewTopic()
err = topic.Where(condition).Find()
if err != nil {
logger.Errorln("topic service FindTopicByTid Error:", err)
return
}
// 帖子不存在
if topic.Tid == 0 {
return
}
topicMap = make(map[string]interface{})
util.Struct2Map(topicMap, topic)
topicEx := model.NewTopicEx()
err = topicEx.Where(condition).Find()
if err != nil {
logger.Errorln("topic service FindTopicByTid Error:", err)
return
}
if topicEx.Tid == 0 {
return
}
util.Struct2Map(topicMap, topicEx)
// 节点名字
topicMap["node"] = model.GetNodeName(topic.Nid)
// 回复信息(评论)
replyList, err := model.NewComment().Where("objid=" + tid + " and objtype=" + strconv.Itoa(model.TYPE_TOPIC)).FindAll()
if err != nil {
logger.Errorln("topic service FindTopicByTid Error:", err)
return
}
replyNum := len(replyList)
uids := make(map[int]int, replyNum+1)
uids[topic.Uid] = topic.Uid
for _, reply := range replyList {
uids[reply.Uid] = reply.Uid
}
// 获得用户信息
userMap := getUserInfos(uids)
topicMap["user"] = userMap[topic.Uid]
// 有人回复
if topic.Lastreplyuid != 0 {
topicMap["lastreplyusername"] = userMap[topicMap["lastreplyuid"].(int)].Username
}
replies = make([]map[string]interface{}, 0, replyNum)
for _, reply := range replyList {
tmpMap := make(map[string]interface{})
util.Struct2Map(tmpMap, reply)
tmpMap["user"] = userMap[reply.Uid]
replies = append(replies, tmpMap)
}
return
}
示例6: FindTopic
// 获取单个 Topic 信息(用于编辑)
func FindTopic(tid string) *model.Topic {
topic := model.NewTopic()
err := topic.Where("tid=?", tid).Find()
if err != nil {
logger.Errorf("FindTopic [%s] error:%s\n", tid, err)
}
return topic
}
示例7: IndexingTopic
// 索引帖子
func IndexingTopic(isAll bool) {
solrClient := NewSolrClient()
topicObj := model.NewTopic()
topicExObj := model.NewTopicEx()
limit := strconv.Itoa(MaxRows)
if isAll {
id := 0
for {
topicList, err := topicObj.Where("tid>?", id).Limit(limit).FindAll()
if err != nil {
logger.Errorln("IndexingTopic error:", err)
break
}
if len(topicList) == 0 {
break
}
tids := util.Models2Intslice(topicList, "Tid")
tmpStr := strings.Repeat("?,", len(tids))
query := "tid in(" + tmpStr[:len(tmpStr)-1] + ")"
args := make([]interface{}, len(tids))
for i, tid := range tids {
args[i] = tid
}
topicExList, err := topicExObj.Where(query, args...).FindAll()
if err != nil {
logger.Errorln("IndexingTopic error:", err)
break
}
topicExMap := make(map[int]*model.TopicEx, len(topicExList))
for _, topicEx := range topicExList {
topicExMap[topicEx.Tid] = topicEx
}
for _, topic := range topicList {
if id < topic.Tid {
id = topic.Tid
}
topicEx, _ := topicExMap[topic.Tid]
document := model.NewDocument(topic, topicEx)
addCommand := model.NewDefaultArgsAddCommand(document)
solrClient.Push(addCommand)
}
solrClient.Post()
}
}
}
示例8: FindTopicsByTids
// 获取多个帖子详细信息
func FindTopicsByTids(tids []int) []*model.Topic {
inTids := util.Join(tids, ",")
topics, err := model.NewTopic().Where("tid in(" + inTids + ")").FindAll()
if err != nil {
logger.Errorln("topic service FindRecentReplies error:", err)
return nil
}
return topics
}
示例9: FindTopicsByNid
// 获得某个节点下的帖子列表(侧边栏推荐)
func FindTopicsByNid(nid, curTid string) (topics []*model.Topic) {
var err error
topics, err = model.NewTopic().Where("nid=" + nid + " and tid!=" + curTid).Limit("0,10").FindAll()
if err != nil {
logger.Errorln("topic service FindTopicsByNid Error:", err)
return
}
return
}
示例10: getTopicOwner
// 通过tid获得话题的所有者
func getTopicOwner(tid int) int {
// 帖子信息
topic := model.NewTopic()
err := topic.Where("tid=" + strconv.Itoa(tid)).Find()
if err != nil {
logger.Errorln("topic service getTopicOwner Error:", err)
return 0
}
return topic.Uid
}
示例11: UpdateComment
// 更新该帖子的回复信息
// cid:评论id;objid:被评论对象id;uid:评论者;cmttime:评论时间
func (self TopicComment) UpdateComment(cid, objid, uid int, cmttime string) {
tid := strconv.Itoa(objid)
// 更新最后回复信息
stringBuilder := util.NewBuffer().Append("lastreplyuid=").AppendInt(uid).Append(",lastreplytime=").Append(cmttime)
err := model.NewTopic().Set(stringBuilder.String()).Where("tid=" + tid).Update()
if err != nil {
logger.Errorln("更新帖子最后回复人信息失败:", err)
}
// 更新回复数(TODO:暂时每次都更新表)
IncrTopicReply(tid, uid)
}
示例12: FindNoticeTopic
// 获得社区最新公告
func FindNoticeTopic() (topic *model.Topic) {
topics, err := model.NewTopic().Where("nid=15").Limit("0,1").Order("mtime DESC").FindAll()
if err != nil {
logger.Errorln("topic service FindTopicsByNid Error:", err)
return
}
if len(topics) > 0 {
topic = topics[0]
}
return
}
示例13: FindRecentTopics
// 获得某个用户最近的帖子
func FindRecentTopics(uid int) []*model.Topic {
topics, err := model.NewTopic().Where("uid=" + strconv.Itoa(uid)).Order("ctime DESC").Limit("0, 5").FindAll()
if err != nil {
logger.Errorln("topic service FindRecentTopics error:", err)
return nil
}
for _, topic := range topics {
topic.Node = model.GetNodeName(topic.Nid)
}
return topics
}
示例14: FindTopicsByWhere
func FindTopicsByWhere(where, order, limit string) (topics []map[string]interface{}, total int) {
topicObj := model.NewTopic()
if where != "" {
topicObj.Where(where)
}
if order != "" {
topicObj.Order(order)
}
if limit != "" {
topicObj.Limit(limit)
}
topicList, err := topicObj.FindAll()
if err != nil {
logger.Errorln("topic service topicObj.FindAll Error:", err)
return
}
// 获得总帖子数
total, err = topicObj.Count()
if err != nil {
logger.Errorln("topic service topicObj.Count Error:", err)
return
}
count := len(topicList)
tids := make([]int, count)
uids := make(map[int]int)
nids := make([]int, count)
for i, topic := range topicList {
tids[i] = topic.Tid
uids[topic.Uid] = topic.Uid
if topic.Lastreplyuid != 0 {
uids[topic.Lastreplyuid] = topic.Lastreplyuid
}
nids[i] = topic.Nid
}
userMap := getUserInfos(uids)
// 获取节点信息
nodes := model.GetNodesName(nids)
topics = make([]map[string]interface{}, count)
for i, topic := range topicList {
tmpMap := make(map[string]interface{})
util.Struct2Map(tmpMap, topic)
tmpMap["user"] = userMap[topic.Uid]
// 有人回复
if tmpMap["lastreplyuid"].(int) != 0 {
tmpMap["lastreplyusername"] = userMap[tmpMap["lastreplyuid"].(int)].Username
}
tmpMap["node"] = nodes[tmpMap["nid"].(int)]
topics[i] = tmpMap
}
return
}
示例15: FindTopicsByIds
// 获取多个主题详细信息
func FindTopicsByIds(ids []int) []*model.Topic {
if len(ids) == 0 {
return nil
}
inIds := util.Join(ids, ",")
topics, err := model.NewTopic().Where("tid in(" + inIds + ")").FindAll()
if err != nil {
logger.Errorln("topic service FindTopicsByIds error:", err)
return nil
}
return topics
}