github.com/ngocphuongnb/tetua@v0.0.7-alpha/app/web/manage/comment/comment.go (about) 1 package managecomment 2 3 import ( 4 "net/http" 5 6 "github.com/ngocphuongnb/tetua/app/entities" 7 "github.com/ngocphuongnb/tetua/app/repositories" 8 "github.com/ngocphuongnb/tetua/app/server" 9 "github.com/ngocphuongnb/tetua/views" 10 ) 11 12 func Index(c server.Context) (err error) { 13 status := http.StatusOK 14 search := c.Query("q") 15 postID := c.QueryInt("post") 16 userID := c.QueryInt("user") 17 filter := &entities.CommentFilter{ 18 Filter: &entities.Filter{ 19 Page: c.QueryInt("page", 1), 20 Search: search, 21 }, 22 } 23 if postID > 0 { 24 filter.PostIDs = append(filter.PostIDs, postID) 25 } 26 if userID > 0 { 27 filter.UserIDs = append(filter.PostIDs, userID) 28 } 29 paginate, err := repositories.Comment.PaginateWithPost(c.Context(), filter) 30 c.Meta().Title = "Manage comments" 31 32 if err != nil { 33 status = http.StatusBadRequest 34 c.WithError("Load comments error", err) 35 } 36 37 return c.Status(status).Render(views.ManageCommentIndex(paginate, search, userID, postID)) 38 }