forked from goplus/builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spx-backend): implement Community API
Fixes goplus#920 Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
- Loading branch information
Showing
56 changed files
with
3,010 additions
and
4,317 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
spx-backend/cmd/spx-backend/delete_project_#owner_#name_liking.yap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Unlike a project. | ||
// | ||
// Request: | ||
// DELETE /project/:owner/:name/liking | ||
|
||
ctx := &Context | ||
|
||
if _, ok := ensureUser(ctx); !ok { | ||
return | ||
} | ||
|
||
if err := ctrl.UnlikeProject(ctx.Context(), ${owner}, ${name}); err != nil { | ||
replyWithInnerError(ctx, err) | ||
return | ||
} | ||
text 204, "", "" |
16 changes: 16 additions & 0 deletions
16
spx-backend/cmd/spx-backend/delete_user_#username_following.yap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Unfollow a user. | ||
// | ||
// Request: | ||
// DELETE /user/:username/following | ||
|
||
ctx := &Context | ||
|
||
if _, ok := ensureUser(ctx); !ok { | ||
return | ||
} | ||
|
||
if err := ctrl.UnfollowUser(ctx.Context(), ${username}); err != nil { | ||
replyWithInnerError(ctx, err) | ||
return | ||
} | ||
text 204, "", "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
spx-backend/cmd/spx-backend/get_project-release_#owner_#project_#release.yap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Get project release by its full name. | ||
// | ||
// Request: | ||
// GET /project-release/:owner/:project/:release | ||
|
||
ctx := &Context | ||
|
||
projectRelease, err := ctrl.GetProjectRelease(ctx.Context(), ${owner}, ${project}, ${release}) | ||
if err != nil { | ||
replyWithInnerError(ctx, err) | ||
return | ||
} | ||
json projectRelease |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// List project releases. | ||
// | ||
// Request: | ||
// GET /project-releases/list | ||
|
||
import ( | ||
"github.com/goplus/builder/spx-backend/internal/controller" | ||
) | ||
|
||
ctx := &Context | ||
|
||
params := controller.NewListProjectReleasesParams() | ||
|
||
if projectFullName := ${projectFullName}; projectFullName != "" { | ||
params.ProjectFullName = &projectFullName | ||
} | ||
|
||
if orderBy := ${orderBy}; orderBy != "" { | ||
params.OrderBy = controller.ListProjectReleasesOrderBy(orderBy) | ||
} | ||
|
||
params.Pagination.Index = ctx.ParamInt("pageIndex", firstPageIndex) | ||
params.Pagination.Size = ctx.ParamInt("pageSize", defaultPageSize) | ||
if ok, msg := params.Validate(); !ok { | ||
replyWithCodeMsg(ctx, errorInvalidArgs, msg) | ||
return | ||
} | ||
|
||
projectReleases, err := ctrl.ListProjectReleases(ctx.Context(), params) | ||
if err != nil { | ||
replyWithInnerError(ctx, err) | ||
return | ||
} | ||
json projectReleases |
21 changes: 21 additions & 0 deletions
21
spx-backend/cmd/spx-backend/get_project_#owner_#name_liking.yap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Check if a project is liked by the authenticated user. | ||
// | ||
// Request: | ||
// GET /project/:owner/:name/liking | ||
|
||
ctx := &Context | ||
|
||
if _, ok := ensureUser(ctx); !ok { | ||
return | ||
} | ||
|
||
hasLiked, err := ctrl.HasLikedProject(ctx.Context(), ${owner}, ${name}) | ||
if err != nil { | ||
replyWithInnerError(ctx, err) | ||
return | ||
} | ||
if hasLiked { | ||
ctx.text 204, "", "" | ||
} else { | ||
ctx.text 404, "", "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Get user by username. | ||
// | ||
// Request: | ||
// GET /user/:username | ||
|
||
ctx := &Context | ||
|
||
user, err := ctrl.GetUser(ctx.Context(), ${username}) | ||
if err != nil { | ||
replyWithInnerError(ctx, err) | ||
return | ||
} | ||
json user |
21 changes: 21 additions & 0 deletions
21
spx-backend/cmd/spx-backend/get_user_#username_following.yap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Check if a user is followed by the authenticated user. | ||
// | ||
// Request: | ||
// GET /user/:username/following | ||
|
||
ctx := &Context | ||
|
||
if _, ok := ensureUser(ctx); !ok { | ||
return | ||
} | ||
|
||
isFollowing, err := ctrl.IsFollowingUser(ctx.Context(), ${username}) | ||
if err != nil { | ||
replyWithInnerError(ctx, err) | ||
return | ||
} | ||
if isFollowing { | ||
ctx.text 204, "", "" | ||
} else { | ||
ctx.text 404, "", "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// List users. | ||
// | ||
// Request: | ||
// GET /users/list | ||
|
||
import ( | ||
"github.com/goplus/builder/spx-backend/internal/controller" | ||
) | ||
|
||
ctx := &Context | ||
|
||
params := controller.NewListUsersParams() | ||
|
||
if follower := ${follower}; follower != "" { | ||
params.Follower = &follower | ||
} | ||
|
||
if followee := ${followee}; followee != "" { | ||
params.Followee = &followee | ||
} | ||
|
||
if orderBy := ${orderBy}; orderBy != "" { | ||
params.OrderBy = controller.ListUsersOrderBy(orderBy) | ||
} | ||
|
||
params.Pagination.Index = ctx.ParamInt("pageIndex", firstPageIndex) | ||
params.Pagination.Size = ctx.ParamInt("pageSize", defaultPageSize) | ||
if ok, msg := params.Validate(); !ok { | ||
replyWithCodeMsg(ctx, errorInvalidArgs, msg) | ||
return | ||
} | ||
|
||
users, err := ctrl.ListUsers(ctx.Context(), params) | ||
if err != nil { | ||
replyWithInnerError(ctx, err) | ||
return | ||
} | ||
json users |
Oops, something went wrong.