Skip to content

Commit

Permalink
Merge pull request goplus#202 from xhyqaq/feat/article-view
Browse files Browse the repository at this point in the history
feat: article view and page view
  • Loading branch information
IRONICBo committed Feb 29, 2024
2 parents f5a8220 + c0d6956 commit e95ac6c
Show file tree
Hide file tree
Showing 8 changed files with 1,031 additions and 447 deletions.
101 changes: 96 additions & 5 deletions cmd/gopcomm/community_yap.gox
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,18 @@ get "/article/:id", ctx => {
}
id := ctx.param("id")
article, err := community.Article(todo, id)
likeState,_:= community.ArticleLikeState(todo,userId,id)
if err != nil {
if err!=nil {
xLog.Error("get article error:", err)
return
}
articleJson, err := json.Marshal(&article)
if err != nil {
xLog.Error("json marshal error:", err)
likeState,err := community.ArticleLikeState(todo,userId,id)
if err!=nil {
xLog.Error("article state err:", err)
return
}
ip := community.GetClientIP(ctx.Request)
community.ArticleLView(todo,id,ip,userId)
articleJson, _ := json.Marshal(&article)
ctx.yap "article", {
"UserId": userId,
"User": user,
Expand Down Expand Up @@ -406,13 +410,18 @@ get "/user/:id", ctx => {
if err != nil {
xLog.Error("json marshal error:", err)
}
isAdmin, err := community.IsAdmin(id)
if err != nil {
xLog.Error("is admin error:", err)
}
ctx.yap "user", {
"Id": id,
"CurrentUser": string(userClaimJson),
"User": user,
"Items": string(itemsJson),
"UserId": userId,
"Next": next,
"IsAdmin": isAdmin,
}
}

Expand Down Expand Up @@ -490,6 +499,33 @@ put "/api/user", ctx => {
}
}

get "/api/users", ctx => {
from := ctx.param("from")
limit := ctx.param("limit")
fromInt, err := strconv.Atoi(from)
if err != nil {
fromInt = 0
}
limitInt, err := strconv.Atoi(limit)
if err != nil {
limitInt = limitConst
}
xLog.Info("from:", fromInt, "limit:", limitInt)
users, next, err := community.ListPageUsers(fromInt, limitInt)
if err != nil {
xLog.Error("get user list error:", err)
ctx.json {
"code": 0,
"err": "get user list failed",
}
}
ctx.json {
"code": 200,
"items": users,
"next": next,
}
}

get "/api/user/unlink", ctx => {
pv := ctx.param("pv")
token, err := core.GetToken(ctx)
Expand Down Expand Up @@ -571,6 +607,61 @@ get "/api/user/:id/medias", ctx => {
}
}

put "/api/public", ctx => {
token, err := core.GetToken(ctx)
id, err := community.ParseJwtToken(token.Value)
if err != nil {
xLog.Error("token parse error")
ctx.json {
"code": 0,
"err": err.Error(),
}
}
publicId := ctx.param("public_id")
publicAuth, err := strconv.ParseBool(ctx.param("public_auth"))
if err != nil {
xLog.Error("parse bool error:", err)
ctx.json {
"code": 0,
"err": "parse bool error",
}
}
ok, err := community.IsAdmin(id)
if err != nil {
xLog.Error("is admin error:", err)
ctx.json {
"code": 500,
"err": "No permissions",
}
}
if !ok {
ctx.json {
"code": 401,
"err": "No permissions",
}
}

ok, err = community.UpdateUserPublicAuth(publicId, publicAuth)
if err != nil {
xLog.Error("update user public auth error:", err)
ctx.json {
"code": 500,
"err": "update user public auth failed",
}
}
if !ok {
ctx.json {
"code": 400,
"err": "update user public auth failed",
}
}

ctx.json {
"code": 200,
"msg": "update success",
}
}

// Media
//
// Media apis
Expand Down
Loading

0 comments on commit e95ac6c

Please sign in to comment.