You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.6 KiB

4 years ago
package api
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/imdotdev/im.dev/server/internal/story"
"github.com/imdotdev/im.dev/server/internal/user"
"github.com/imdotdev/im.dev/server/pkg/common"
)
func GetEditorPosts(c *gin.Context) {
user := user.CurrentUser(c)
4 years ago
ars, err := story.UserPosts(user, user.ID)
4 years ago
if err != nil {
c.JSON(err.Status, common.RespError(err.Message))
return
}
c.JSON(http.StatusOK, common.RespSuccess(ars))
}
func GetUserPosts(c *gin.Context) {
4 years ago
userID := c.Param("userID")
4 years ago
user := user.CurrentUser(c)
posts, err := story.UserPosts(user, userID)
if err != nil {
c.JSON(err.Status, common.RespError(err.Message))
return
}
c.JSON(http.StatusOK, common.RespSuccess(posts))
}
func GetTagPosts(c *gin.Context) {
tagID, _ := strconv.ParseInt(c.Param("id"), 10, 64)
user := user.CurrentUser(c)
posts, err := story.TagPosts(user, tagID)
if err != nil {
c.JSON(err.Status, common.RespError(err.Message))
return
}
c.JSON(http.StatusOK, common.RespSuccess(posts))
}
func GetHomePosts(c *gin.Context) {
filter := c.Param("filter")
user := user.CurrentUser(c)
posts, err := story.HomePosts(user, filter)
if err != nil {
c.JSON(err.Status, common.RespError(err.Message))
return
}
c.JSON(http.StatusOK, common.RespSuccess(posts))
}
4 years ago
func GetBookmarkPosts(c *gin.Context) {
filter := c.Param("filter")
user := user.CurrentUser(c)
posts, err := story.BookmarkPosts(user, filter)
if err != nil {
c.JSON(err.Status, common.RespError(err.Message))
return
}
c.JSON(http.StatusOK, common.RespSuccess(posts))
}