Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add header.html #89

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading