Skip to content

Commit

Permalink
Add: get user draft
Browse files Browse the repository at this point in the history
  • Loading branch information
excing committed Feb 19, 2021
1 parent cd14c1b commit 7912020
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
42 changes: 21 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,34 +177,34 @@ func main() {

v1.PUT("/draft", authorizeRequired, handle(newDraft))
v1.PUT("/draft/content", authorizeRequired, handle(putDraftContent))
v1.PUT("/response")
v1.PUT("/response/content")
// v1.PUT("/response")
// v1.PUT("/response/content")

v1.POST("/reaction")
v1.POST("/star")
v1.POST("/node")
v1.POST("/publish", authorizeRequired, handle(publishArticle))
// v1.POST("/reaction")
// v1.POST("/star")
// v1.POST("/node")
// v1.POST("/publish", authorizeRequired, handle(publishArticle))

v1.GET("/draft", authorizeRequired)
v1.GET("/article", authentication, handle(getArticle))
v1.GET("/article/responses")
v1.GET("/article/versions")
v1.GET("/article/reactions")
// v1.GET("/article", authentication, handle(getArticle))
// v1.GET("/article/responses")
// v1.GET("/article/versions")
// v1.GET("/article/reactions")

v1.GET("/articles")
// v1.GET("/articles")

v1.GET("/tags", authentication, handle(getTags))
v1.GET("/tag/articles")
v1.GET("/tag/nodes")
// v1.GET("/tags", authentication, handle(getTags))
// v1.GET("/tag/articles")
// v1.GET("/tag/nodes")

v1.GET("/node/articles")
v1.GET("/node")
// v1.GET("/node/articles")
// v1.GET("/node")

v1.GET("/user/tags")
v1.GET("/user/nodes")
// v1.GET("/user/tags")
// v1.GET("/user/nodes")
v1.GET("/user/draft", authorizeRequired, handle(getUserDraft))
v1.GET("/user/drafts", authorizeRequired, handle(getUserDrafts))
v1.GET("/user/articles", authorizeRequired, handle(getUserArticles))
v1.GET("/search")
// v1.GET("/user/articles", authorizeRequired, handle(getUserArticles))
// v1.GET("/search")

router.Run(fmt.Sprint(":", config.Port))
}
32 changes: 32 additions & 0 deletions rest_get_user_draft.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"knowlgraph.com/ent/user"
"knowlgraph.com/ent/version"
)

func getUserDraft(c *Context) error {
_userID, _ := c.Get(GinKeyUserID)

id, err := c.GetQueryInt("id")
if err != nil {
return c.BadRequest(err.Error())
}

_draft, err := client.Version.Query().
Where(version.And(
version.HasUserWith(user.IDEQ(_userID.(int))),
version.IDEQ(id))).
WithContent().
Only(ctx)

if err != nil {
return c.NotFound(err.Error())
}

if _draft.Status == version.StatusReview || _draft.Status == version.StatusRelease {
return c.Conflict("The draft has been published")
}

return c.Ok(_draft)
}
File renamed without changes.

0 comments on commit 7912020

Please sign in to comment.