mirror of https://github.com/sunface/rust-course
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.
45 lines
1.1 KiB
45 lines
1.1 KiB
4 years ago
|
package api
|
||
|
|
||
|
import (
|
||
|
"database/sql"
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"github.com/imdotdev/im.dev/server/internal/posts"
|
||
|
"github.com/imdotdev/im.dev/server/internal/session"
|
||
|
"github.com/imdotdev/im.dev/server/pkg/common"
|
||
|
)
|
||
|
|
||
|
func GetEditorArticles(c *gin.Context) {
|
||
|
user := session.CurrentUser(c)
|
||
|
ars, err := posts.UserArticles(int64(user.ID))
|
||
|
if err != nil && err != sql.ErrNoRows {
|
||
|
logger.Warn("get user articles error", "error", err)
|
||
|
c.JSON(http.StatusInternalServerError, common.RespInternalError())
|
||
|
return
|
||
|
}
|
||
|
|
||
|
c.JSON(http.StatusOK, common.RespSuccess(ars))
|
||
|
}
|
||
|
|
||
|
func PostEditorArticle(c *gin.Context) {
|
||
|
err := posts.PostArticle(c)
|
||
|
if err != nil {
|
||
|
logger.Warn("post article error", "error", err)
|
||
|
c.JSON(400, common.RespError(err.Error()))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
c.JSON(http.StatusOK, common.RespSuccess(nil))
|
||
|
}
|
||
|
|
||
|
func DeleteEditorArticle(c *gin.Context) {
|
||
|
err := posts.DeleteArticle(c)
|
||
|
if err != nil {
|
||
|
logger.Warn("delete article error", "error", err)
|
||
|
c.JSON(400, common.RespError(err.Error()))
|
||
|
return
|
||
|
}
|
||
|
c.JSON(http.StatusOK, common.RespSuccess(nil))
|
||
|
}
|