Skip to content

Commit

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

Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
  • Loading branch information
aofei committed Oct 11, 2024
1 parent d3359f1 commit 7a503b2
Show file tree
Hide file tree
Showing 37 changed files with 1,893 additions and 4,081 deletions.
55 changes: 12 additions & 43 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ paths:
in: query
schema:
$ref: "#/components/schemas/Project/properties/owner"
description: Filter projects by the owner's username.
description: |
Filter projects by the owner's username.
Defaults to the authenticated user if not specified. Use `*` to include projects from all users.
- name: remixedFrom
in: query
schema:
Expand Down Expand Up @@ -349,12 +352,9 @@ paths:
schema:
type: object
required:
- name
- files
- isPublic
properties:
name:
$ref: "#/components/schemas/Project/properties/name"
files:
$ref: "#/components/schemas/Project/properties/files"
isPublic:
Expand Down Expand Up @@ -598,8 +598,6 @@ paths:
$ref: "#/components/schemas/Asset/properties/files"
filesHash:
$ref: "#/components/schemas/Asset/properties/filesHash"
preview:
$ref: "#/components/schemas/Asset/properties/preview"
isPublic:
$ref: "#/components/schemas/Asset/properties/isPublic"
responses:
Expand All @@ -626,7 +624,10 @@ paths:
in: query
schema:
$ref: "#/components/schemas/User/properties/username"
description: Filter assets by owner's username.
description: |
Filter assets by owner's username.
Defaults to the authenticated user if not specified. Use `*` to include assets from all users.
- name: category
in: query
schema:
Expand Down Expand Up @@ -661,11 +662,10 @@ paths:
schema:
type: string
enum:
- default
- time
- clickCount
- cTime
- uTime
examples:
- default
- cTime
description: Field by which to order the results.
- $ref: "#/components/parameters/SortOrder"
- $ref: "#/components/parameters/PageIndex"
Expand Down Expand Up @@ -742,8 +742,6 @@ paths:
$ref: "#/components/schemas/Asset/properties/files"
filesHash:
$ref: "#/components/schemas/Asset/properties/filesHash"
preview:
$ref: "#/components/schemas/Asset/properties/preview"
isPublic:
$ref: "#/components/schemas/Asset/properties/isPublic"
responses:
Expand All @@ -769,23 +767,6 @@ paths:
"204":
description: Successfully deleted the asset.

/asset/{id}/click:
post:
tags:
- Assets
summary: Increment the click count of an asset
description: Increase the click count of the specified asset.
parameters:
- name: id
in: path
required: true
schema:
$ref: "#/components/schemas/Model/properties/id"
description: ID of the asset for which to increase click count.
responses:
"204":
description: Successfully increased the click count.

/aigc/matting:
post:
tags:
Expand Down Expand Up @@ -1023,6 +1004,7 @@ components:
$ref: "#/components/schemas/User/properties/username"
remixedFrom:
$ref: "#/components/schemas/ProjectReleaseFullName"
nullable: true
description: Full name of the project release from which the project is remixed.
name:
type: string
Expand Down Expand Up @@ -1186,21 +1168,8 @@ components:
examples:
- h1:qUqP5cyxm6YcTAhz05Hph5gvu9M=
description: Hash of the asset files.
preview:
type: string
format: uri
examples:
- https://builder.goplus.org/asset_preview.png
description: URL of the asset's preview image.
isPublic:
$ref: "#/components/schemas/IsPublic"
clickCount:
type: integer
format: int64
minimum: 0
examples:
- 1
description: Number of times the asset has been clicked.

UpInfo:
type: object
Expand Down
7 changes: 5 additions & 2 deletions spx-backend/cmd/spx-backend/get_assets_list.yap
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ 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:
Expand Down
4 changes: 2 additions & 2 deletions spx-backend/cmd/spx-backend/get_projects_list.yap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
ctx := &Context

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

if isPublicParam := ${isPublic}; isPublicParam != "" {
isPublicInt, err := strconv.Atoi(isPublicParam)
Expand All @@ -31,7 +31,7 @@ case "":
replyWithCode(ctx, errorUnauthorized)
return
}
params.Owner = &user.Name
params.Owner = &user.Username
case "*":
params.Owner = nil
default:
Expand Down
Loading

0 comments on commit 7a503b2

Please sign in to comment.