Skip to content

Commit

Permalink
Merge pull request #345 from alimy/pr-user-tweets
Browse files Browse the repository at this point in the history
simple support for user posts filter by style
  • Loading branch information
alimy authored Jul 27, 2023
2 parents d35c34d + 48a1cea commit b560613
Show file tree
Hide file tree
Showing 35 changed files with 338 additions and 90 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to paopao-ce are documented in this file.
- add `pprof` feature support [#327](https://github.com/rocboss/paopao-ce/pull/327)
- use compiler profile-guided optimization (PGO) to further optimize builds. [#327](https://github.com/rocboss/paopao-ce/pull/327)
- frontend: re-add stars page embed to profile page. [#339](https://github.com/rocboss/paopao-ce/pull/339)
- simple support for user posts filter by style(post/comment/media/star). [#345](https://github.com/rocboss/paopao-ce/pull/345)

### Changed
- change man content width to 600px and optimize tweet/comment/replay text length. [#333](https://github.com/rocboss/paopao-ce/pull/333)
Expand Down
8 changes: 8 additions & 0 deletions internal/model/web/loose.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ const (
TagTypeHotExtral TagType = "hot_extral"
)

const (
UserPostsStylePost = "post"
UserPostsStyleComment = "comment"
UserPostsStyleMedia = "media"
UserPostsStyleStar = "star"
)

type TweetCommentsReq struct {
SimpleInfo `form:"-" binding:"-"`
TweetId int64 `form:"id" binding:"required"`
Expand All @@ -45,6 +52,7 @@ type TimelineResp base.PageResp
type GetUserTweetsReq struct {
BaseInfo `form:"-" binding:"-"`
Username string `form:"username" binding:"required"`
Style string `form:"style"`
Page int `form:"-" binding:"-"`
PageSize int `form:"-" binding:"-"`
}
Expand Down
76 changes: 75 additions & 1 deletion internal/servants/web/loose.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,81 @@ func (s *looseSrv) Timeline(req *web.TimelineReq) (*web.TimelineResp, mir.Error)
return (*web.TimelineResp)(resp), nil
}

func (s *looseSrv) GetUserTweets(req *web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) {
func (s *looseSrv) GetUserTweets(req *web.GetUserTweetsReq) (res *web.GetUserTweetsResp, err mir.Error) {
isSelf := (req.User != nil && req.User.Username == req.Username)
switch req.Style {
case web.UserPostsStyleComment:
res, err = s.getUserCommentTweets(req, isSelf)
case web.UserPostsStyleMedia:
res, err = s.getUserMediaTweets(req, isSelf)
case web.UserPostsStyleStar:
res, err = s.getUserStarTweets(req, isSelf)
case web.UserPostsStylePost:
fallthrough
default:
res, err = s.getUserPostTweets(req)
}
return
}

func (s *looseSrv) getUserCommentTweets(req *web.GetUserTweetsReq, isSelf bool) (*web.GetUserTweetsResp, mir.Error) {
// TODO: add implement logic
resp := base.PageRespFrom(nil, req.Page, req.PageSize, 0)
return (*web.GetUserTweetsResp)(resp), nil
}

func (s *looseSrv) getUserMediaTweets(req *web.GetUserTweetsReq, isSelf bool) (*web.GetUserTweetsResp, mir.Error) {
// TODO: add implement logic
resp := base.PageRespFrom(nil, req.Page, req.PageSize, 0)
return (*web.GetUserTweetsResp)(resp), nil
}

func (s *looseSrv) getUserStarTweets(req *web.GetUserTweetsReq, isSelf bool) (*web.GetUserTweetsResp, mir.Error) {
if isSelf {
return s.getSelfStarTweets(req)
}
// TODO: add implement logic for not self star tweets
resp := base.PageRespFrom(nil, req.Page, req.PageSize, 0)
return (*web.GetUserTweetsResp)(resp), nil
}

func (s *looseSrv) getSelfCommentTweets(req *web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) {
// TODO: add implement logic
resp := base.PageRespFrom(nil, req.Page, req.PageSize, 0)
return (*web.GetUserTweetsResp)(resp), nil
}

func (s *looseSrv) getSelfMediaTweets(req *web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) {
// TODO: add implement logic
resp := base.PageRespFrom(nil, req.Page, req.PageSize, 0)
return (*web.GetUserTweetsResp)(resp), nil
}

func (s *looseSrv) getSelfStarTweets(req *web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) {
stars, err := s.Ds.GetUserPostStars(req.User.ID, (req.Page-1)*req.PageSize, req.PageSize)
if err != nil {
logrus.Errorf("Ds.GetUserPostStars err: %s", err)
return nil, web.ErrGetStarsFailed
}
totalRows, err := s.Ds.GetUserPostStarCount(req.User.ID)
if err != nil {
logrus.Errorf("Ds.GetUserPostStars err: %s", err)
return nil, web.ErrGetStarsFailed
}
var posts []*core.Post
for _, star := range stars {
posts = append(posts, star.Post)
}
postsFormated, err := s.Ds.MergePosts(posts)
if err != nil {
logrus.Errorf("Ds.MergePosts err: %s", err)
return nil, web.ErrGetStarsFailed
}
resp := base.PageRespFrom(postsFormated, req.Page, req.PageSize, totalRows)
return (*web.GetUserTweetsResp)(resp), nil
}

func (s *looseSrv) getUserPostTweets(req *web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) {
other, xerr := s.GetUserProfile(&web.GetUserProfileReq{
BaseInfo: req.BaseInfo,
Username: req.Username,
Expand Down
3 changes: 0 additions & 3 deletions mirc/web/v1/loose.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ type Loose struct {
// GetUserTweets 获取用户动态列表
GetUserTweets func(Get, web.GetUserTweetsReq) web.GetUserTweetsResp `mir:"/user/posts"`

// GetUserProfile 获取用户基本信息
GetUserProfile func(Get, web.GetUserProfileReq) web.GetUserProfileResp `mir:"/user/profile"`

// TopicList 获取话题列表
TopicList func(Get, web.TopicListReq) web.TopicListResp `mir:"/tags"`

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/dist/assets/Collection-2999380d.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion web/dist/assets/Collection-b058950d.js

This file was deleted.

Loading

0 comments on commit b560613

Please sign in to comment.