Skip to content

Commit

Permalink
Merge pull request #89 from Baihhh/markdown
Browse files Browse the repository at this point in the history
chore: add header.html
  • Loading branch information
IRONICBo authored Feb 1, 2024
2 parents a07d339 + 703a203 commit 5c32532
Show file tree
Hide file tree
Showing 6 changed files with 381 additions and 321 deletions.
59 changes: 26 additions & 33 deletions cmd/gopcomm/community_yap.gox
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (

const (
layoutUS = "January 2, 2006"
limitConst = 10
)

todo := context.TODO()
Expand Down Expand Up @@ -147,10 +148,6 @@ get "/delete", ctx => {
}

get "/", ctx => {
// from := ctx.param("from")
from := ctx.param("page")
limit := ctx.param("limit")
// todo middleware
// Get User Info
var user *core.User
token, err := ctx.Request.Cookie("token")
Expand All @@ -160,25 +157,33 @@ get "/", ctx => {
xLog.Error("get user error:", err)
}
}

page, err := strconv.Atoi(from)
if err != nil {
page = 1
// Get Article Info
articles, next, _ := community.listArticle(todo, core.MarkBegin, limitConst, "")
articlesJson, _ := json.Marshal(&articles)
ctx.yap "home", {
"User": user,
"Items": strings.Replace(string(articlesJson), `\"`, `"`, -1),
"Next": next,
}
}

get "/get", ctx => {
from := ctx.param("from")
limit := ctx.param("limit")
searchValue := ctx.param("value")

limitInt, err := strconv.Atoi(limit)
if err != nil {
limitInt = 20
limitInt = limitConst
}
// Get Article Info
// articles, next, _ := community.listArticle(todo, from, limitInt)
articles, total, _ := community.articles(todo, page, limitInt, "")
ctx.yap "home", {
"User": user,
"Items": articles,
"Page": page,
"TotalPage": (total + limitInt - 1) / limitInt,
"Total": total,
articles, next, _ := community.listArticle(todo, from, limitInt, searchValue)
// articles, total, _ := community.articles(todo, page, limitInt, "")
ctx.json {
"code": 200,
"items": articles,
"next": next,
"value": searchValue,
}
}

Expand All @@ -191,17 +196,6 @@ get "/search", ctx => {
}
}

from := ctx.param("page")
limit := ctx.param("limit")
limitInt, err := strconv.Atoi(limit)
if err != nil {
limitInt = 10
}
page, err := strconv.Atoi(from)
if err != nil {
page = 1
}

// todo middleware
var user *core.User
token, err := ctx.Request.Cookie("token")
Expand All @@ -212,14 +206,13 @@ get "/search", ctx => {
}
}

articles, total, _ := community.articles(todo, page, limitInt, searchValue)
articles, next, _ := community.listArticle(todo, core.MarkBegin, limitConst, searchValue)
articlesJson, _ := json.Marshal(&articles)
ctx.yap "home", {
"User": user,
"Items": articles,
"Items": strings.Replace(string(articlesJson), `\"`, `"`, -1),
"Value": searchValue,
"Page": page,
"TotalPage": (total + limitInt - 1) / limitInt,
"Total": total,
"Next": next,
}
}

Expand Down
Loading

0 comments on commit 5c32532

Please sign in to comment.