// 评论某Topic或回复某评论 func (c Topic) Comment(sid string, id int64, comment string, replyto int64) r.Result { session := c.Sess.GetSession(sid) if c.Sess.IsGuest() { return c.RenderLogin() } if id == 0 { return c.Render(nil, errors.New("Sorry, no topic id.")) } if comment == "" { return c.Render(nil, errors.New("Sorry, the comment content is empty.")) } var commentId int64 var err error topicModule := modules.NewTopic(c.Db, c.Rc) if replyto == 0 { commentId, err = topicModule.Comment(session.SessionVal.UserId, id, comment) } else { commentId, err = topicModule.ReplyComment(session.SessionVal.UserId, id, comment, replyto) } return c.Render(map[string]int64{"comment_id": commentId}, err) }
// 获取当个话题详情. func (c Topic) GetDetail(id int64) r.Result { topicModule := modules.NewTopic(c.Db, c.Rc) topic := topicModule.GetDetail(id) return c.Render(topic, nil) }
// 获取当前profile用户订阅Topic列表. func (c User) GetSubscribeTopicList(uid int64, page int, limit int) r.Result { topicModule := modules.NewTopic(c.Db, c.Rc) var topics *modules.Pager var err error topics, err = topicModule.GetTopicList(page, "", limit, 0, false) return c.Render(topics, err) }
func (c Admin) EditTopic(sid string, tid int64, content, keywords string) r.Result { session := c.Sess.GetSession(sid) if !c.Sess.IsAdmin() { return c.RenderNoAdmin() } res, err := modules.NewTopic(c.Db, c.Rc).EditOne(session.SessionVal.UserId, tid, content, keywords, true) return c.Render(res, err) }
// 不喜欢某Topic. func (c Topic) UnLike(sid string, id int64) r.Result { session := c.Sess.GetSession(sid) if session.Id == 0 { return c.RenderLogin() } res, err := modules.NewTopic(c.Db, c.Rc).UnLike(session.SessionVal.UserId, id) return c.Render(res, err) }
func (c Admin) RemoveTopics(sid string, ids string) r.Result { c.Sess.GetSession(sid) if !c.Sess.IsAdmin() { return c.RenderNoAdmin() } tid := helpers.GetArrayFromString(ids) res, err := modules.NewTopic(c.Db, c.Rc).RemoveTopics(tid) return c.Render(res, err) }
func (c Admin) RemoveUsers(sid string, ids string, withPost bool) r.Result { c.Sess.GetSession(sid) if !c.Sess.IsAdmin() { return c.RenderNoAdmin() } uid := helpers.GetArrayFromString(ids) res, err := modules.NewUser(c.Db).RemoveUsers(uid) if withPost { res, err = modules.NewTopic(c.Db, c.Rc).RemoveUsersTopics(uid) } return c.Render(res, err) }
// 订阅某个topic. func (c Topic) Subscribe(sid string, id int64) r.Result { session := c.Sess.GetSession(sid) if session.Id == 0 { return c.RenderLogin() } if id == 0 { return c.Render(nil, errors.New("no topic id")) } topicModule := modules.NewTopic(c.Db, c.Rc) res, err := topicModule.Subscribe(session.SessionVal.UserId, id) return c.Render(res, err) }
// 获取话题列表. func (c Topic) GetTopicList(sid string, page int, order string, limit int, maxid int, needTotal bool) r.Result { session := c.Sess.GetSession(sid) topicModule := modules.NewTopic(c.Db, c.Rc) var topics *modules.Pager var err error if c.Sess.IsAdmin() { topics, err = topicModule.GetTopicList(page, order, limit, maxid, needTotal) } else if session.Id == 0 { // 未登录用户,只能返回统一标准topic list. topics, err = topicModule.GetTopicList(page, order, limit, maxid, needTotal) } else { // 登陆用户可返回,用户偏好性topic list. topics, err = topicModule.GetTopicListWithPreferences(session.SessionVal.UserId, page, order, limit) } return c.Render(topics, err) }
// 创建话题. func (c Topic) AddNew(sid string, content string, keywords string, bg []byte) r.Result { session := c.Sess.GetSession(sid) if session.Id == 0 { return c.RenderLogin() } attach := &models.Attach{} if len(bg) > 0 { var err error // 尝试上传图片 uploader := modules.NewAttach(c.Db) attach, err = uploader.Upload(c.Request, "bg") if err != nil { return c.Render(nil, err) } } // 保存topic topicModule := modules.NewTopic(c.Db, c.Rc) topic, err := topicModule.AddNew(session.SessionVal.UserId, content, keywords, attach) return c.Render(topic, err) }
func (c Admin) GetAllStat(sid string, date string) r.Result { c.Sess.GetSession(sid) if !c.Sess.IsAdmin() { return c.RenderNoAdmin() } if date == "" { return c.Render(nil, errors.New("Sorry, no date.")) } dateInt, err := time.Parse("2006/01/02", date) if err != nil { return c.Render(nil, err) } dateUInt := dateInt.Unix() userModule := modules.NewUser(c.Db) topicModule := modules.NewTopic(c.Db, c.Rc) // get user stat data. userStat, err := userModule.GetStat(dateUInt) if err != nil { return c.Render(nil, err) } // get topic stat data. topicStat, err := topicModule.GetStat(dateUInt) if err != nil { return c.Render(nil, err) } // get comment stat data. commentStat, err := topicModule.GetCommentStat(dateUInt) if err != nil { return c.Render(nil, err) } // get user date news count. userDateNews, err := userModule.GetOneMonthDateNewCnt(dateUInt) if err != nil { return c.Render(nil, err) } // get topic date news count. topicDateNews, err := topicModule.GetOneMonthDateNewCnt(dateUInt) if err != nil { return c.Render(nil, err) } // get comment date news count. commentDateNews, err := topicModule.GetCommOneMonthDateNewCnt(dateUInt) if err != nil { return c.Render(nil, err) } // response format response := map[string]interface{}{ "detail": map[string]interface{}{ "users": userStat, "topics": topicStat, "comments": commentStat, }, "date": map[string]interface{}{ "users": userDateNews, "topics": topicDateNews, "comments": commentDateNews, }, } return c.Render(response, nil) }
// 获取所有comment list. func (c Topic) GetAllCommentList(page int, limit int) r.Result { topicModule := modules.NewTopic(c.Db, c.Rc) comments, err := topicModule.GetCommentList(0, page, limit, true) return c.Render(comments, err) }
// 获取某Topic下的comment列表 func (c Topic) GetCommentList(id int64, page int, limit int) r.Result { topicModule := modules.NewTopic(c.Db, c.Rc) list, err := topicModule.GetCommentList(id, page, limit, false) return c.Render(list, err) }