Skip to content

Commit

Permalink
feat(spx-backend): implement Community API
Browse files Browse the repository at this point in the history
Fixes goplus#920

Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
  • Loading branch information
aofei committed Oct 11, 2024
1 parent d3359f1 commit fd28a30
Show file tree
Hide file tree
Showing 37 changed files with 1,873 additions and 4,299 deletions.
235 changes: 90 additions & 145 deletions docs/openapi.yaml

Large diffs are not rendered by default.

31 changes: 10 additions & 21 deletions spx-backend/cmd/spx-backend/get_assets_list.yap
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,37 @@ ctx := &Context
user, _ := controller.UserFromContext(ctx.Context())
params := &controller.ListAssetsParams{}

params.Keyword = ${keyword}
keyword := ${keyword}
if keyword != "" {
params.Keyword = &keyword
}

switch owner := ${owner}; owner {
case "":
if user == nil {
replyWithCode(ctx, errorUnauthorized)
return
}
params.Owner = &user.Name
params.Owner = &user.Username
case "*":
params.Owner = nil
default:
params.Owner = &owner
}

typeParam := ctx.param("type")
params.Type = &typeParam

if category := ${category}; category != "" {
params.Category = &category
}

if assetTypeParam := ${assetType}; assetTypeParam != "" {
assetTypeInt, err := strconv.Atoi(assetTypeParam)
if err != nil {
replyWithCode(ctx, errorInvalidArgs)
return
}
assetType := model.AssetType(assetTypeInt)
params.AssetType = &assetType
}

if filesHash := ${filesHash}; filesHash != "" {
params.FilesHash = &filesHash
}

if isPublicParam := ${isPublic}; isPublicParam != "" {
isPublicInt, err := strconv.Atoi(isPublicParam)
if err != nil {
replyWithCode(ctx, errorInvalidArgs)
return
}
isPublic := model.IsPublic(isPublicInt)
params.IsPublic = &isPublic
}
visibilityParam := ${visibility}
params.Visibility = &visibilityParam

if orderBy := ${orderBy}; orderBy != "" {
params.OrderBy = controller.ListAssetsOrderBy(orderBy)
Expand Down
15 changes: 4 additions & 11 deletions spx-backend/cmd/spx-backend/get_projects_list.yap
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,18 @@ import (
ctx := &Context

user, _ := controller.UserFromContext(ctx.Context())
params := &controller.ListProjectsParams{}
params := controller.NewListProjectsParams()

if isPublicParam := ${isPublic}; isPublicParam != "" {
isPublicInt, err := strconv.Atoi(isPublicParam)
if err != nil {
replyWithCode(ctx, errorInvalidArgs)
return
}
isPublic := model.IsPublic(isPublicInt)
params.IsPublic = &isPublic
}
visibilityParam := ${visibility}
params.Visibility = &visibilityParam

switch owner := ${owner}; owner {
case "":
if user == nil {
replyWithCode(ctx, errorUnauthorized)
return
}
params.Owner = &user.Name
params.Owner = &user.Username
case "*":
params.Owner = nil
default:
Expand Down
Loading

0 comments on commit fd28a30

Please sign in to comment.