feat(bookmark): 初始化书签服务并配置路由与权限控制
新增书签服务主程序,使用 Gin 框架搭建 HTTP 服务器,并注册书签相关接口处理器。 配置 CORS 中间件以支持跨域请求。服务监听端口为 8081。 feat(user_np): 初始化用户权限服务并注册认证接口 新增用户权限服务主程序,使用 Gin 框架搭建 HTTP 服务器,并注册登录、注册及修改密码等接口处理器。 服务监听端口为 8082。 refactor(config): 重构 OpenAPI 配置文件结构并拆分模块 将原有合并的 OpenAPI 配置文件按功能模块拆分为 bookmark 和 user_np 两个独立目录, 分别管理各自的 server、client 及 API 定义文件,便于后续维护和扩展。 refactor(vfs): 调整虚拟文件系统 API 接口路径与参数定义 更新 VFS API 配置文件,修改部分接口路径及参数结构, 如将文件路径参数由 path 转为 query 参数,并优化响应结构体定义。
This commit is contained in:
160
internal/handlers/vfs_driver/vfs_bookmark.go
Normal file
160
internal/handlers/vfs_driver/vfs_bookmark.go
Normal file
@ -0,0 +1,160 @@
|
||||
// internal/handlers/vfs_driver/vfs_bookmark.go
|
||||
|
||||
package vfsdriver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
api "git.zzyxyz.com/zzy/zzyxyz_go_api/gen/bookmarks"
|
||||
"git.zzyxyz.com/zzy/zzyxyz_go_api/internal/handlers"
|
||||
"git.zzyxyz.com/zzy/zzyxyz_go_api/internal/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type VfsBookMarkService struct {
|
||||
client *api.ClientWithResponses
|
||||
}
|
||||
|
||||
func NewVfsBookMarkService(serverURL string) (*VfsBookMarkService, error) {
|
||||
client, err := api.NewClientWithResponses(serverURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &VfsBookMarkService{
|
||||
client: client,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Create implements ServiceProxy.
|
||||
func (v *VfsBookMarkService) Create(c *gin.Context, servicePath string, node *models.VfsNode, data []byte) (string, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
// 解析传入的数据为 BookmarkRequest
|
||||
var req api.BookmarkRequest
|
||||
if err := json.Unmarshal(data, &req); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 调用 bookmark 服务创建书签
|
||||
resp, err := v.client.CreateBookmarkWithResponse(ctx, int64(node.ID), req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 处理响应
|
||||
if resp.JSON201 != nil {
|
||||
result, err := json.Marshal(resp.JSON201)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(result), nil
|
||||
}
|
||||
|
||||
// 处理错误情况
|
||||
if resp.JSON400 != nil {
|
||||
return "", fmt.Errorf("bad request: %s", resp.JSON400.Message)
|
||||
}
|
||||
|
||||
if resp.JSON500 != nil {
|
||||
return "", fmt.Errorf("server error: %s", resp.JSON500.Message)
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("unknown error")
|
||||
}
|
||||
|
||||
// Delete implements ServiceProxy.
|
||||
func (v *VfsBookMarkService) Delete(c *gin.Context, servicePath string, node *models.VfsNode) error {
|
||||
ctx := context.Background()
|
||||
|
||||
// 调用 bookmark 服务删除书签
|
||||
resp, err := v.client.DeleteBookmarkWithResponse(ctx, int64(node.ID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 处理响应
|
||||
if resp.StatusCode() == 204 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 处理错误情况
|
||||
if resp.JSON404 != nil {
|
||||
return fmt.Errorf("not found: %s", resp.JSON404.Message)
|
||||
}
|
||||
|
||||
if resp.JSON500 != nil {
|
||||
return fmt.Errorf("server error: %s", resp.JSON500.Message)
|
||||
}
|
||||
|
||||
return fmt.Errorf("unknown error")
|
||||
}
|
||||
|
||||
// Get implements ServiceProxy.
|
||||
func (v *VfsBookMarkService) Get(c *gin.Context, servicePath string, node *models.VfsNode) (any, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
// 调用 bookmark 服务获取书签
|
||||
resp, err := v.client.GetBookmarkWithResponse(ctx, int64(node.ID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 处理响应
|
||||
if resp.JSON200 != nil {
|
||||
return resp.JSON200, nil
|
||||
}
|
||||
|
||||
// 处理错误情况
|
||||
if resp.JSON404 != nil {
|
||||
return nil, fmt.Errorf("not found: %s", resp.JSON404.Message)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("unknown error")
|
||||
}
|
||||
|
||||
// GetName implements ServiceProxy.
|
||||
func (v *VfsBookMarkService) GetName() string {
|
||||
return "bookmark"
|
||||
}
|
||||
|
||||
// Update implements ServiceProxy.
|
||||
func (v *VfsBookMarkService) Update(c *gin.Context, servicePath string, node *models.VfsNode, data []byte) error {
|
||||
ctx := context.Background()
|
||||
|
||||
// 解析传入的数据为 BookmarkRequest
|
||||
var req api.BookmarkRequest
|
||||
if err := json.Unmarshal(data, &req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 调用 bookmark 服务更新书签
|
||||
resp, err := v.client.UpdateBookmarkWithResponse(ctx, int64(node.ID), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 处理响应
|
||||
if resp.JSON200 != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 处理错误情况
|
||||
if resp.JSON400 != nil {
|
||||
return fmt.Errorf("bad request: %s", resp.JSON400.Message)
|
||||
}
|
||||
|
||||
if resp.JSON404 != nil {
|
||||
return fmt.Errorf("not found: %s", resp.JSON404.Message)
|
||||
}
|
||||
|
||||
if resp.JSON500 != nil {
|
||||
return fmt.Errorf("server error: %s", resp.JSON500.Message)
|
||||
}
|
||||
|
||||
return fmt.Errorf("unknown error")
|
||||
}
|
||||
|
||||
var _ handlers.ServiceProxy = (*VfsBookMarkService)(nil)
|
Reference in New Issue
Block a user