update
This commit is contained in:
parent
29a8dcf827
commit
ce9bd1ccfe
347
docs/docs.go
347
docs/docs.go
@ -50,41 +50,17 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.DocumentBlock"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "文档块不存在",
|
||||
@ -117,10 +93,7 @@ const docTemplate = `{
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
}
|
||||
"description": "OK"
|
||||
},
|
||||
"404": {
|
||||
"description": "文档块不存在",
|
||||
@ -164,31 +137,16 @@ const docTemplate = `{
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
}
|
||||
"description": "OK"
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "文档块不存在",
|
||||
@ -227,41 +185,17 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/leafdev_top_Leaf_leaf-library-3_internal_entity.Collection"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "工作空间不存在",
|
||||
@ -304,23 +238,11 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.DocumentDTO"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "无权访问",
|
||||
@ -353,7 +275,7 @@ const docTemplate = `{
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "集<EFBFBD><EFBFBD>ID",
|
||||
"description": "集合ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
@ -363,20 +285,8 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/leafdev_top_Leaf_leaf-library-3_internal_entity.Collection"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "集合不存在",
|
||||
@ -420,41 +330,17 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/leafdev_top_Leaf_leaf-library-3_internal_entity.Collection"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "集合不存在",
|
||||
@ -529,41 +415,17 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/dto.DocumentDTO"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "无权访问",
|
||||
@ -606,23 +468,11 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/entity.DocumentBlock"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "文档不存在",
|
||||
@ -666,41 +516,17 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.DocumentBlock"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "文档不存在",
|
||||
@ -737,20 +563,8 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/dto.DocumentDTO"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "无权访问",
|
||||
@ -800,41 +614,17 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.Document"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "文档不存在",
|
||||
@ -867,10 +657,7 @@ const docTemplate = `{
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
}
|
||||
"description": "OK"
|
||||
},
|
||||
"404": {
|
||||
"description": "文档不存在",
|
||||
@ -898,14 +685,6 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/entity.Workspace"
|
||||
@ -913,10 +692,6 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "创建一个新的工作空间",
|
||||
@ -945,32 +720,12 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.Workspace"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
@ -978,10 +733,6 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/workspaces/{id}": {
|
||||
@ -1010,20 +761,8 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.Workspace"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "工作空间不存在",
|
||||
@ -1056,10 +795,7 @@ const docTemplate = `{
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
}
|
||||
"description": "OK"
|
||||
},
|
||||
"404": {
|
||||
"description": "工作空间不存在",
|
||||
@ -1071,6 +807,42 @@ const docTemplate = `{
|
||||
}
|
||||
},
|
||||
"/workspaces/{id}/members": {
|
||||
"get": {
|
||||
"description": "根据工作空间ID获取工作空间的成员",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Workspace"
|
||||
],
|
||||
"summary": "获取工作空间的成员",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "工作空间ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/entity.Workspace"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "工作空间不存在",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "向工作空间添加新成员",
|
||||
"consumes": [
|
||||
@ -1105,41 +877,17 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.WorkspaceMember"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "工作空间不存在",
|
||||
@ -1227,23 +975,11 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/leafdev_top_Leaf_leaf-library-3_internal_entity.Collection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "工作空间不存在",
|
||||
@ -1270,7 +1006,6 @@ const docTemplate = `{
|
||||
"dto.CreateBlockRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"content",
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
|
@ -41,41 +41,17 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.DocumentBlock"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "文档块不存在",
|
||||
@ -108,10 +84,7 @@
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
}
|
||||
"description": "OK"
|
||||
},
|
||||
"404": {
|
||||
"description": "文档块不存在",
|
||||
@ -155,31 +128,16 @@
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
}
|
||||
"description": "OK"
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "文档块不存在",
|
||||
@ -218,41 +176,17 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/leafdev_top_Leaf_leaf-library-3_internal_entity.Collection"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "工作空间不存在",
|
||||
@ -295,23 +229,11 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.DocumentDTO"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "无权访问",
|
||||
@ -344,7 +266,7 @@
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "集<EFBFBD><EFBFBD>ID",
|
||||
"description": "集合ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
@ -354,20 +276,8 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/leafdev_top_Leaf_leaf-library-3_internal_entity.Collection"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "集合不存在",
|
||||
@ -411,41 +321,17 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/leafdev_top_Leaf_leaf-library-3_internal_entity.Collection"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "集合不存在",
|
||||
@ -520,41 +406,17 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/dto.DocumentDTO"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "无权访问",
|
||||
@ -597,23 +459,11 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/entity.DocumentBlock"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "文档不存在",
|
||||
@ -657,41 +507,17 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.DocumentBlock"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "文档不存在",
|
||||
@ -728,20 +554,8 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/dto.DocumentDTO"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"403": {
|
||||
"description": "无权访问",
|
||||
@ -791,41 +605,17 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.Document"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "文档不存在",
|
||||
@ -858,10 +648,7 @@
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
}
|
||||
"description": "OK"
|
||||
},
|
||||
"404": {
|
||||
"description": "文档不存在",
|
||||
@ -889,14 +676,6 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/entity.Workspace"
|
||||
@ -904,10 +683,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "创建一个新的工作空间",
|
||||
@ -936,32 +711,12 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.Workspace"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
@ -969,10 +724,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/workspaces/{id}": {
|
||||
@ -1001,20 +752,8 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.Workspace"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "工作空间不存在",
|
||||
@ -1047,10 +786,7 @@
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
}
|
||||
"description": "OK"
|
||||
},
|
||||
"404": {
|
||||
"description": "工作空间不存在",
|
||||
@ -1062,6 +798,42 @@
|
||||
}
|
||||
},
|
||||
"/workspaces/{id}/members": {
|
||||
"get": {
|
||||
"description": "根据工作空间ID获取工作空间的成员",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Workspace"
|
||||
],
|
||||
"summary": "获取工作空间的成员",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "工作空间ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/entity.Workspace"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "工作空间不存在",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "向工作空间添加新成员",
|
||||
"consumes": [
|
||||
@ -1096,41 +868,17 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/entity.WorkspaceMember"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "参数验证失败",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.ValidateError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "工作空间不存在",
|
||||
@ -1218,23 +966,11 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/dto.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/leafdev_top_Leaf_leaf-library-3_internal_entity.Collection"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "工作空间不存在",
|
||||
@ -1261,7 +997,6 @@
|
||||
"dto.CreateBlockRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"content",
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
|
@ -15,7 +15,6 @@ definitions:
|
||||
type:
|
||||
type: string
|
||||
required:
|
||||
- content
|
||||
- type
|
||||
type: object
|
||||
dto.CreateCollectionRequest:
|
||||
@ -222,8 +221,6 @@ paths:
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/dto.Response'
|
||||
"404":
|
||||
description: 文档块不存在
|
||||
schema:
|
||||
@ -253,23 +250,13 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/entity.DocumentBlock'
|
||||
type: object
|
||||
"400":
|
||||
description: 参数验证失败
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/dto.ValidateError'
|
||||
type: array
|
||||
type: object
|
||||
"404":
|
||||
description: 文档块不存在
|
||||
schema:
|
||||
@ -299,19 +286,12 @@ paths:
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/dto.Response'
|
||||
"400":
|
||||
description: 参数验证失败
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/dto.ValidateError'
|
||||
type: array
|
||||
type: object
|
||||
"404":
|
||||
description: 文档块不存在
|
||||
schema:
|
||||
@ -337,23 +317,13 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/leafdev_top_Leaf_leaf-library-3_internal_entity.Collection'
|
||||
type: object
|
||||
"400":
|
||||
description: 参数验证失败
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/dto.ValidateError'
|
||||
type: array
|
||||
type: object
|
||||
"404":
|
||||
description: 工作空间不存在
|
||||
schema:
|
||||
@ -382,14 +352,9 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/dto.DocumentDTO'
|
||||
type: array
|
||||
type: object
|
||||
"403":
|
||||
description: 无权访问
|
||||
schema:
|
||||
@ -431,7 +396,7 @@ paths:
|
||||
- application/json
|
||||
description: 根据集合ID获取集合详情
|
||||
parameters:
|
||||
- description: 集<EFBFBD><EFBFBD>ID
|
||||
- description: 集合ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
@ -442,12 +407,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/leafdev_top_Leaf_leaf-library-3_internal_entity.Collection'
|
||||
type: object
|
||||
"404":
|
||||
description: 集合不存在
|
||||
schema:
|
||||
@ -477,23 +437,13 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/leafdev_top_Leaf_leaf-library-3_internal_entity.Collection'
|
||||
type: object
|
||||
"400":
|
||||
description: 参数验证失败
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/dto.ValidateError'
|
||||
type: array
|
||||
type: object
|
||||
"404":
|
||||
description: 集合不存在
|
||||
schema:
|
||||
@ -519,23 +469,13 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/dto.DocumentDTO'
|
||||
type: object
|
||||
"400":
|
||||
description: 参数验证失败
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/dto.ValidateError'
|
||||
type: array
|
||||
type: object
|
||||
"403":
|
||||
description: 无权访问
|
||||
schema:
|
||||
@ -564,14 +504,9 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/entity.DocumentBlock'
|
||||
type: array
|
||||
type: object
|
||||
"404":
|
||||
description: 文档不存在
|
||||
schema:
|
||||
@ -601,23 +536,13 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/entity.DocumentBlock'
|
||||
type: object
|
||||
"400":
|
||||
description: 参数验证失败
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/dto.ValidateError'
|
||||
type: array
|
||||
type: object
|
||||
"404":
|
||||
description: 文档不存在
|
||||
schema:
|
||||
@ -641,8 +566,6 @@ paths:
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/dto.Response'
|
||||
"404":
|
||||
description: 文档不存在
|
||||
schema:
|
||||
@ -666,12 +589,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/dto.DocumentDTO'
|
||||
type: object
|
||||
"403":
|
||||
description: 无权访问
|
||||
schema:
|
||||
@ -705,23 +623,13 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/entity.Document'
|
||||
type: object
|
||||
"400":
|
||||
description: 参数验证失败
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/dto.ValidateError'
|
||||
type: array
|
||||
type: object
|
||||
"404":
|
||||
description: 文档不存在
|
||||
schema:
|
||||
@ -740,14 +648,9 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/entity.Workspace'
|
||||
type: array
|
||||
type: object
|
||||
summary: 列出工作空间列表
|
||||
tags:
|
||||
- Workspace
|
||||
@ -768,23 +671,13 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/entity.Workspace'
|
||||
type: object
|
||||
"400":
|
||||
description: 参数验证失败
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/dto.ValidateError'
|
||||
type: array
|
||||
type: object
|
||||
summary: 创建工作空间
|
||||
tags:
|
||||
- Workspace
|
||||
@ -804,8 +697,6 @@ paths:
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/dto.Response'
|
||||
"404":
|
||||
description: 工作空间不存在
|
||||
schema:
|
||||
@ -829,12 +720,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/entity.Workspace'
|
||||
type: object
|
||||
"404":
|
||||
description: 工作空间不存在
|
||||
schema:
|
||||
@ -843,6 +729,30 @@ paths:
|
||||
tags:
|
||||
- Workspace
|
||||
/workspaces/{id}/members:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 根据工作空间ID获取工作空间的成员
|
||||
parameters:
|
||||
- description: 工作空间ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/entity.Workspace'
|
||||
"404":
|
||||
description: 工作空间不存在
|
||||
schema:
|
||||
$ref: '#/definitions/dto.Response'
|
||||
summary: 获取工作空间的成员
|
||||
tags:
|
||||
- Workspace
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
@ -865,23 +775,13 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
$ref: '#/definitions/entity.WorkspaceMember'
|
||||
type: object
|
||||
"400":
|
||||
description: 参数验证失败
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/dto.ValidateError'
|
||||
type: array
|
||||
type: object
|
||||
"404":
|
||||
description: 工作空间不存在
|
||||
schema:
|
||||
@ -940,14 +840,9 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/dto.Response'
|
||||
- properties:
|
||||
data:
|
||||
items:
|
||||
$ref: '#/definitions/leafdev_top_Leaf_leaf-library-3_internal_entity.Collection'
|
||||
type: array
|
||||
type: object
|
||||
"404":
|
||||
description: 工作空间不存在
|
||||
schema:
|
||||
|
@ -2,16 +2,15 @@ package interceptor
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/base/conf"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/base/logger"
|
||||
authService "leafdev.top/Leaf/leaf-library-3/internal/services/auth"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/constants"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/errs"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/constants"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/errs"
|
||||
|
||||
authInterceptor "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/auth"
|
||||
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
|
||||
"google.golang.org/grpc"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/base/conf"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/base/logger"
|
||||
authService "leafdev.top/Leaf/leaf-library-3/internal/services/auth"
|
||||
)
|
||||
|
||||
var ignoreAuthApis = map[string]bool{
|
||||
|
@ -1,14 +1,17 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/pkg/response"
|
||||
"net/http"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto"
|
||||
_ "leafdev.top/Leaf/leaf-library-3/internal/entity"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/errs"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/pkg/validator"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/services/auth"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/services/collection"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/services/workspace"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/errs"
|
||||
)
|
||||
|
||||
type CollectionController struct {
|
||||
@ -36,38 +39,38 @@ func NewCollectionController(
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body dto.CreateCollectionRequest true "创建集合请求"
|
||||
// @Success 200 {object} dto.Response{data=entity.Collection}
|
||||
// @Failure 400 {object} dto.Response{data=[]dto.ValidateError} "参数验证失败"
|
||||
// @Success 200 {object} entity.Collection
|
||||
// @Failure 400 {object} []dto.ValidateError "参数验证失败"
|
||||
// @Failure 404 {object} dto.Response "工作空间不存在"
|
||||
// @Router /collections [post]
|
||||
func (c *CollectionController) CreateCollection(ctx *fiber.Ctx) error {
|
||||
var req dto.CreateCollectionRequest
|
||||
if err := ctx.BodyParser(&req); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
if validationErrors, ok, err := validator.Struct(req); !ok {
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
return dto.Ctx(ctx).Message((*validationErrors)[0].Message).Status(fiber.StatusBadRequest).Send()
|
||||
return response.Ctx(ctx).Message((*validationErrors)[0].Message).Status(fiber.StatusBadRequest).Send()
|
||||
}
|
||||
|
||||
// 检查工作空间是否存在
|
||||
exists, err := c.workspaceService.Exists(ctx.Context(), req.WorkspaceID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !exists {
|
||||
return dto.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
collection, err := c.collectionService.Create(ctx.Context(), req.WorkspaceID, req.Name)
|
||||
collectionEntity, err := c.collectionService.Create(ctx.Context(), req.WorkspaceID, req.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(collection).Send()
|
||||
return response.Ctx(ctx).Success(collectionEntity).Send()
|
||||
}
|
||||
|
||||
// GetCollection 获取集合
|
||||
@ -76,30 +79,30 @@ func (c *CollectionController) CreateCollection(ctx *fiber.Ctx) error {
|
||||
// @Tags Collection
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "集<EFBFBD><EFBFBD>ID"
|
||||
// @Success 200 {object} dto.Response{data=entity.Collection}
|
||||
// @Param id path int true "集合ID"
|
||||
// @Success 200 {object} entity.Collection
|
||||
// @Failure 404 {object} dto.Response "集合不存在"
|
||||
// @Router /collections/{id} [get]
|
||||
func (c *CollectionController) GetCollection(ctx *fiber.Ctx) error {
|
||||
var req dto.GetCollectionRequest
|
||||
if err := ctx.ParamsParser(&req); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
exists, err := c.collectionService.Exists(ctx.Context(), req.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !exists {
|
||||
return dto.Ctx(ctx).Error(errs.ErrCollectionNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrCollectionNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
collection, err := c.collectionService.Get(ctx.Context(), req.ID)
|
||||
collectionEntity, err := c.collectionService.Get(ctx.Context(), req.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(collection).Send()
|
||||
return response.Ctx(ctx).Success(collectionEntity).Send()
|
||||
}
|
||||
|
||||
// ListCollections 列出工作空间下的所有集合
|
||||
@ -109,30 +112,30 @@ func (c *CollectionController) GetCollection(ctx *fiber.Ctx) error {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param workspace_id path int true "工作空间ID"
|
||||
// @Success 200 {object} dto.Response{data=[]entity.Collection}
|
||||
// @Success 200 {object} []entity.Collection
|
||||
// @Failure 404 {object} dto.Response "工作空间不存在"
|
||||
// @Router /workspaces/{workspace_id}/collections [get]
|
||||
func (c *CollectionController) ListCollections(ctx *fiber.Ctx) error {
|
||||
var req dto.ListCollectionsRequest
|
||||
if err := ctx.ParamsParser(&req); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
// 检<EFBFBD><EFBFBD><EFBFBD>工作空间是否存在
|
||||
// 检查工作空间是否存在
|
||||
exists, err := c.workspaceService.Exists(ctx.Context(), req.WorkspaceID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !exists {
|
||||
return dto.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
collections, err := c.collectionService.List(ctx.Context(), req.WorkspaceID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(collections).Send()
|
||||
return response.Ctx(ctx).Success(collections).Send()
|
||||
}
|
||||
|
||||
// UpdateCollection 更新集合
|
||||
@ -143,59 +146,59 @@ func (c *CollectionController) ListCollections(ctx *fiber.Ctx) error {
|
||||
// @Produce json
|
||||
// @Param id path int true "集合ID"
|
||||
// @Param request body dto.UpdateCollectionRequest true "更新集合请求"
|
||||
// @Success 200 {object} dto.Response{data=entity.Collection}
|
||||
// @Failure 400 {object} dto.Response{data=[]dto.ValidateError} "参数验证失败"
|
||||
// @Success 200 {object} entity.Collection
|
||||
// @Failure 400 {object} []dto.ValidateError "参数验证失败"
|
||||
// @Failure 404 {object} dto.Response "集合不存在"
|
||||
// @Router /collections/{id} [put]
|
||||
func (c *CollectionController) UpdateCollection(ctx *fiber.Ctx) error {
|
||||
var params dto.CollectionIDParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
var req dto.UpdateCollectionRequest
|
||||
if err := ctx.BodyParser(&req); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
if validationErrors, ok, err := validator.Struct(req); !ok {
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
return dto.Ctx(ctx).Data(validationErrors).Status(fiber.StatusBadRequest).Send()
|
||||
return response.Ctx(ctx).Data(validationErrors).Status(fiber.StatusBadRequest).Send()
|
||||
}
|
||||
|
||||
// 检查集合是否存在
|
||||
collection, err := c.collectionService.Get(ctx.Context(), params.ID)
|
||||
collectionEntity, err := c.collectionService.Get(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if collection == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrCollectionNotExists).Status(fiber.StatusNotFound).Send()
|
||||
if collectionEntity == nil {
|
||||
return response.Ctx(ctx).Error(errs.ErrCollectionNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查用户是否有权限访问该集合
|
||||
user := c.authService.GetUser(ctx)
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), collection.WorkspaceId)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), collectionEntity.WorkspaceId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspace)
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspaceEntity)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !isMember {
|
||||
return dto.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
}
|
||||
|
||||
// 更新集合
|
||||
collection, err = c.collectionService.Update(ctx.Context(), params.ID, req.Name)
|
||||
collectionEntity, err = c.collectionService.Update(ctx.Context(), params.ID, req.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(collection).Send()
|
||||
return response.Ctx(ctx).Success(collectionEntity).Send()
|
||||
}
|
||||
|
||||
// DeleteCollection 删除集合
|
||||
@ -211,38 +214,38 @@ func (c *CollectionController) UpdateCollection(ctx *fiber.Ctx) error {
|
||||
func (c *CollectionController) DeleteCollection(ctx *fiber.Ctx) error {
|
||||
var params dto.CollectionIDParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
// 检查集合是否存在
|
||||
collection, err := c.collectionService.Get(ctx.Context(), params.ID)
|
||||
collectionEntity, err := c.collectionService.Get(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if collection == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrCollectionNotExists).Status(fiber.StatusNotFound).Send()
|
||||
if collectionEntity == nil {
|
||||
return response.Ctx(ctx).Error(errs.ErrCollectionNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查用户是否有权限访问该集合
|
||||
user := c.authService.GetUser(ctx)
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), collection.WorkspaceId)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), collectionEntity.WorkspaceId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspace)
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspaceEntity)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !isMember {
|
||||
return dto.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
}
|
||||
|
||||
// 删除集合
|
||||
err = c.collectionService.Delete(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(nil).Send()
|
||||
return response.Ctx(ctx).Success(nil).Send()
|
||||
}
|
||||
|
@ -2,13 +2,15 @@ package controller
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/errs"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/pkg/response"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/pkg/validator"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/services/auth"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/services/collection"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/services/document"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/services/workspace"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/errs"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type DocumentController struct {
|
||||
@ -39,76 +41,76 @@ func NewDocumentController(
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body dto.CreateDocumentRequest true "创建文档请求"
|
||||
// @Success 200 {object} dto.Response{data=dto.DocumentDTO}
|
||||
// @Failure 400 {object} dto.Response{data=[]dto.ValidateError} "参数验证失败"
|
||||
// @Success 200 {object} dto.DocumentDTO
|
||||
// @Failure 400 {object} []dto.ValidateError "参数验证失败"
|
||||
// @Failure 403 {object} dto.Response "无权访问"
|
||||
// @Failure 404 {object} dto.Response "集合不存在或父文档不存在"
|
||||
// @Router /documents [post]
|
||||
func (c *DocumentController) CreateDocument(ctx *fiber.Ctx) error {
|
||||
var req dto.CreateDocumentRequest
|
||||
if err := ctx.BodyParser(&req); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
if validationErrors, ok, err := validator.Struct(req); !ok {
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
return dto.Ctx(ctx).Data(validationErrors).Status(fiber.StatusBadRequest).Send()
|
||||
return response.Ctx(ctx).Data(validationErrors).Status(fiber.StatusBadRequest).Send()
|
||||
}
|
||||
|
||||
// 检查集合是否存在
|
||||
collection, err := c.collectionService.Get(ctx.Context(), req.CollectionID)
|
||||
collectionEntity, err := c.collectionService.Get(ctx.Context(), req.CollectionID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if collection == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrCollectionNotExists).Status(fiber.StatusNotFound).Send()
|
||||
if collectionEntity == nil {
|
||||
return response.Ctx(ctx).Error(errs.ErrCollectionNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查用户是否有权限访问该集合
|
||||
user := c.authService.GetUser(ctx)
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), collection.WorkspaceId)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), collectionEntity.WorkspaceId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if workspace == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
if workspaceEntity == nil {
|
||||
return response.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspace)
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspaceEntity)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !isMember {
|
||||
return dto.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
}
|
||||
|
||||
// 如果是子文档,检查父文档是否存在且属于同一个集合
|
||||
if req.ParentID != nil {
|
||||
parentDoc, err := c.documentService.Get(ctx.Context(), *req.ParentID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if parentDoc == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
if parentDoc.CollectionId != req.CollectionID {
|
||||
return dto.Ctx(ctx).Error(errs.ErrInvalidParentDocument).Status(fiber.StatusBadRequest).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrInvalidParentDocument).Status(fiber.StatusBadRequest).Send()
|
||||
}
|
||||
}
|
||||
|
||||
doc, err := c.documentService.Create(ctx.Context(), req.Name, req.WorkspaceID, req.CollectionID, req.ParentID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
docDTO, err := c.documentService.ToDTO(ctx.Context(), doc)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(docDTO).Send()
|
||||
return response.Ctx(ctx).Success(docDTO).Send()
|
||||
}
|
||||
|
||||
// GetDocument 获取文档
|
||||
@ -118,49 +120,49 @@ func (c *DocumentController) CreateDocument(ctx *fiber.Ctx) error {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "文档ID"
|
||||
// @Success 200 {object} dto.Response{data=dto.DocumentDTO}
|
||||
// @Success 200 {object} dto.DocumentDTO
|
||||
// @Failure 403 {object} dto.Response "无权访问"
|
||||
// @Failure 404 {object} dto.Response "文档不存在"
|
||||
// @Router /documents/{id} [get]
|
||||
func (c *DocumentController) GetDocument(ctx *fiber.Ctx) error {
|
||||
var params dto.DocumentIDParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
doc, err := c.documentService.Get(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if doc == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查用户是否有权限访问该文档
|
||||
user := c.authService.GetUser(ctx)
|
||||
collection, err := c.collectionService.Get(ctx.Context(), doc.CollectionId)
|
||||
collectionEntity, err := c.collectionService.Get(ctx.Context(), doc.CollectionId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), collection.WorkspaceId)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), collectionEntity.WorkspaceId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspace)
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspaceEntity)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !isMember {
|
||||
return dto.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
}
|
||||
|
||||
docDTO, err := c.documentService.ToDTO(ctx.Context(), doc)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(docDTO).Send()
|
||||
return response.Ctx(ctx).Success(docDTO).Send()
|
||||
}
|
||||
|
||||
// ListDocuments 列出集合或父文档下的所有文档
|
||||
@ -171,63 +173,63 @@ func (c *DocumentController) GetDocument(ctx *fiber.Ctx) error {
|
||||
// @Produce json
|
||||
// @Param collection_id path int true "集合ID"
|
||||
// @Param parent_id query int false "父文档ID,不传则获取根文档"
|
||||
// @Success 200 {object} dto.Response{data=[]dto.DocumentDTO}
|
||||
// @Success 200 {object} []dto.DocumentDTO
|
||||
// @Failure 403 {object} dto.Response "无权访问"
|
||||
// @Failure 404 {object} dto.Response "集合不存在或父文档不存在"
|
||||
// @Router /collections/{collection_id}/documents [get]
|
||||
func (c *DocumentController) ListDocuments(ctx *fiber.Ctx) error {
|
||||
var pathParams dto.ListDocumentsPathParam
|
||||
if err := ctx.ParamsParser(&pathParams); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
var queryParams dto.ListDocumentsQueryParam
|
||||
if err := ctx.QueryParser(&queryParams); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
// 检查集合是否存在
|
||||
collection, err := c.collectionService.Get(ctx.Context(), pathParams.CollectionID)
|
||||
collectionEntity, err := c.collectionService.Get(ctx.Context(), pathParams.CollectionID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if collection == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrCollectionNotExists).Status(fiber.StatusNotFound).Send()
|
||||
if collectionEntity == nil {
|
||||
return response.Ctx(ctx).Error(errs.ErrCollectionNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查用户是否有权限访问该集合
|
||||
user := c.authService.GetUser(ctx)
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), collection.WorkspaceId)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), collectionEntity.WorkspaceId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspace)
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspaceEntity)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !isMember {
|
||||
return dto.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
}
|
||||
|
||||
// 如果指定了父文档,检查父文档是否存在且属于同一个集合
|
||||
if queryParams.ParentID != nil {
|
||||
parentDoc, err := c.documentService.Get(ctx.Context(), *queryParams.ParentID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if parentDoc == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
if parentDoc.CollectionId != pathParams.CollectionID {
|
||||
return dto.Ctx(ctx).Error(errs.ErrInvalidParentDocument).Status(fiber.StatusBadRequest).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrInvalidParentDocument).Status(fiber.StatusBadRequest).Send()
|
||||
}
|
||||
}
|
||||
|
||||
// 获取文档列表
|
||||
docs, err := c.documentService.List(ctx.Context(), pathParams.CollectionID, queryParams.ParentID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
// 转换为 DTO
|
||||
@ -235,12 +237,12 @@ func (c *DocumentController) ListDocuments(ctx *fiber.Ctx) error {
|
||||
for i, doc := range docs {
|
||||
docDTO, err := c.documentService.ToDTO(ctx.Context(), doc)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
dtos[i] = docDTO
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(dtos).Send()
|
||||
return response.Ctx(ctx).Success(dtos).Send()
|
||||
}
|
||||
|
||||
// UpdateDocument 更新文档
|
||||
@ -251,39 +253,39 @@ func (c *DocumentController) ListDocuments(ctx *fiber.Ctx) error {
|
||||
// @Produce json
|
||||
// @Param id path int true "文档ID"
|
||||
// @Param request body dto.UpdateDocumentRequest true "更新文档请求"
|
||||
// @Success 200 {object} dto.Response{data=entity.Document}
|
||||
// @Failure 400 {object} dto.Response{data=[]dto.ValidateError} "参数验证失败"
|
||||
// @Success 200 {object} entity.Document
|
||||
// @Failure 400 {object} []dto.ValidateError "参数验证失败"
|
||||
// @Failure 404 {object} dto.Response "文档不存在"
|
||||
// @Router /documents/{id} [put]
|
||||
func (c *DocumentController) UpdateDocument(ctx *fiber.Ctx) error {
|
||||
var params dto.DocumentIDParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
var req dto.UpdateDocumentRequest
|
||||
if err := ctx.BodyParser(&req); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
if validationErrors, ok, err := validator.Struct(req); !ok {
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
return dto.Ctx(ctx).Data(validationErrors).Status(fiber.StatusBadRequest).Send()
|
||||
return response.Ctx(ctx).Data(validationErrors).Status(fiber.StatusBadRequest).Send()
|
||||
}
|
||||
|
||||
doc, err := c.documentService.Update(ctx.Context(), params.ID, req.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
docDTO, err := c.documentService.ToDTO(ctx.Context(), doc)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(docDTO).Send()
|
||||
return response.Ctx(ctx).Success(docDTO).Send()
|
||||
}
|
||||
|
||||
// DeleteDocument 删除文档
|
||||
@ -293,21 +295,21 @@ func (c *DocumentController) UpdateDocument(ctx *fiber.Ctx) error {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "文档ID"
|
||||
// @Success 200 {object} dto.Response
|
||||
// @Success 200
|
||||
// @Failure 404 {object} dto.Response "文档不存在"
|
||||
// @Router /documents/{id} [delete]
|
||||
func (c *DocumentController) DeleteDocument(ctx *fiber.Ctx) error {
|
||||
var params dto.DocumentIDParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
err := c.documentService.Delete(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(nil).Send()
|
||||
return response.Ctx(ctx).Success(nil).Send()
|
||||
}
|
||||
|
||||
// CreateBlock 创建文档块
|
||||
@ -318,59 +320,59 @@ func (c *DocumentController) DeleteDocument(ctx *fiber.Ctx) error {
|
||||
// @Produce json
|
||||
// @Param document_id path int true "文档ID"
|
||||
// @Param request body dto.CreateBlockRequest true "创建文档块请求"
|
||||
// @Success 200 {object} dto.Response{data=entity.DocumentBlock}
|
||||
// @Failure 400 {object} dto.Response{data=[]dto.ValidateError} "参数验证失败"
|
||||
// @Success 200 {object} entity.DocumentBlock
|
||||
// @Failure 400 {object} []dto.ValidateError "参数验证失败"
|
||||
// @Failure 404 {object} dto.Response "文档不存在"
|
||||
// @Router /documents/{document_id}/blocks [post]
|
||||
func (c *DocumentController) CreateBlock(ctx *fiber.Ctx) error {
|
||||
var params dto.ListBlocksRequest
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
var req dto.CreateBlockRequest
|
||||
if err := ctx.BodyParser(&req); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
if validationErrors, ok, err := validator.Struct(req); !ok {
|
||||
return dto.Ctx(ctx).Data(validationErrors).Error(err).Status(fiber.StatusBadRequest).Send()
|
||||
return response.Ctx(ctx).Data(validationErrors).Error(err).Status(fiber.StatusBadRequest).Send()
|
||||
}
|
||||
|
||||
// 检查文档是否存在
|
||||
doc, err := c.documentService.Get(ctx.Context(), params.DocumentID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if doc == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查用户是否有权限访问该文档
|
||||
user := c.authService.GetUser(ctx)
|
||||
collection, err := c.collectionService.Get(ctx.Context(), doc.CollectionId)
|
||||
collectionEntity, err := c.collectionService.Get(ctx.Context(), doc.CollectionId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), collection.WorkspaceId)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), collectionEntity.WorkspaceId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspace)
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspaceEntity)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !isMember {
|
||||
return dto.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
}
|
||||
|
||||
block, err := c.documentService.CreateBlock(ctx.Context(), params.DocumentID, req.Type, req.Content, req.AfterBlockID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(block).Send()
|
||||
return response.Ctx(ctx).Success(block).Send()
|
||||
}
|
||||
|
||||
// UpdateBlock 更新文档块
|
||||
@ -381,71 +383,71 @@ func (c *DocumentController) CreateBlock(ctx *fiber.Ctx) error {
|
||||
// @Produce json
|
||||
// @Param block_id path int true "文档块ID"
|
||||
// @Param request body dto.UpdateBlockRequest true "更新文档块请求"
|
||||
// @Success 200 {object} dto.Response{data=entity.DocumentBlock}
|
||||
// @Failure 400 {object} dto.Response{data=[]dto.ValidateError} "参数验证失败"
|
||||
// @Success 200 {object} entity.DocumentBlock
|
||||
// @Failure 400 {object} []dto.ValidateError "参数验证失败"
|
||||
// @Failure 404 {object} dto.Response "文档块不存在"
|
||||
// @Router /blocks/{block_id} [put]
|
||||
func (c *DocumentController) UpdateBlock(ctx *fiber.Ctx) error {
|
||||
var params dto.BlockIDParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
var req dto.UpdateBlockRequest
|
||||
if err := ctx.BodyParser(&req); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
if validationErrors, ok, err := validator.Struct(req); !ok {
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
return dto.Ctx(ctx).Data(validationErrors).Status(fiber.StatusBadRequest).Send()
|
||||
return response.Ctx(ctx).Data(validationErrors).Status(fiber.StatusBadRequest).Send()
|
||||
}
|
||||
|
||||
// 获取块信息
|
||||
block, err := c.documentService.GetBlock(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if block == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrBlockNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrBlockNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查文档是否存在
|
||||
doc, err := c.documentService.Get(ctx.Context(), block.DocumentId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if doc == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查用户是否有权限访问该文档
|
||||
user := c.authService.GetUser(ctx)
|
||||
collection, err := c.collectionService.Get(ctx.Context(), doc.CollectionId)
|
||||
collectionEntity, err := c.collectionService.Get(ctx.Context(), doc.CollectionId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), collection.WorkspaceId)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), collectionEntity.WorkspaceId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspace)
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspaceEntity)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !isMember {
|
||||
return dto.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
}
|
||||
|
||||
block, err = c.documentService.UpdateBlock(ctx.Context(), params.ID, req.Content)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(block).Send()
|
||||
return response.Ctx(ctx).Success(block).Send()
|
||||
}
|
||||
|
||||
// DeleteBlock <20><><EFBFBD>除文档块
|
||||
@ -455,58 +457,58 @@ func (c *DocumentController) UpdateBlock(ctx *fiber.Ctx) error {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param block_id path int true "文档块ID"
|
||||
// @Success 200 {object} dto.Response
|
||||
// @Success 200
|
||||
// @Failure 404 {object} dto.Response "文档块不存在"
|
||||
// @Router /blocks/{block_id} [delete]
|
||||
func (c *DocumentController) DeleteBlock(ctx *fiber.Ctx) error {
|
||||
var params dto.BlockIDParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
// 获取块信息
|
||||
block, err := c.documentService.GetBlock(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if block == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrBlockNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrBlockNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查文档是否存在
|
||||
doc, err := c.documentService.Get(ctx.Context(), block.DocumentId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if doc == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查用户是否有权限访问该文档
|
||||
user := c.authService.GetUser(ctx)
|
||||
collection, err := c.collectionService.Get(ctx.Context(), doc.CollectionId)
|
||||
collectionEntity, err := c.collectionService.Get(ctx.Context(), doc.CollectionId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), collection.WorkspaceId)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), collectionEntity.WorkspaceId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspace)
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspaceEntity)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !isMember {
|
||||
return dto.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
}
|
||||
|
||||
err = c.documentService.DeleteBlock(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(nil).Send()
|
||||
return response.Ctx(ctx).Success(nil).Send()
|
||||
}
|
||||
|
||||
// ListBlocks 列出文档下的所有块
|
||||
@ -516,49 +518,49 @@ func (c *DocumentController) DeleteBlock(ctx *fiber.Ctx) error {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param document_id path int true "文档ID"
|
||||
// @Success 200 {object} dto.Response{data=[]entity.DocumentBlock}
|
||||
// @Success 200 {object} []entity.DocumentBlock
|
||||
// @Failure 404 {object} dto.Response "文档不存在"
|
||||
// @Router /documents/{document_id}/blocks [get]
|
||||
func (c *DocumentController) ListBlocks(ctx *fiber.Ctx) error {
|
||||
var params dto.ListBlocksRequest
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
// 检查文档是否存在
|
||||
doc, err := c.documentService.Get(ctx.Context(), params.DocumentID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if doc == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查用户是否有权限访问该文档
|
||||
user := c.authService.GetUser(ctx)
|
||||
collection, err := c.collectionService.Get(ctx.Context(), doc.CollectionId)
|
||||
collectionEntity, err := c.collectionService.Get(ctx.Context(), doc.CollectionId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), collection.WorkspaceId)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), collectionEntity.WorkspaceId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspace)
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspaceEntity)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !isMember {
|
||||
return dto.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
}
|
||||
|
||||
blocks, err := c.documentService.ListBlocks(ctx.Context(), params.DocumentID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(blocks).Send()
|
||||
return response.Ctx(ctx).Success(blocks).Send()
|
||||
}
|
||||
|
||||
// MoveBlock 移动文档块
|
||||
@ -569,62 +571,62 @@ func (c *DocumentController) ListBlocks(ctx *fiber.Ctx) error {
|
||||
// @Produce json
|
||||
// @Param block_id path int true "文档块ID"
|
||||
// @Param request body dto.MoveBlockRequest true "移动文档块请求"
|
||||
// @Success 200 {object} dto.Response
|
||||
// @Failure 400 {object} dto.Response{data=[]dto.ValidateError} "参数验证失败"
|
||||
// @Success 200
|
||||
// @Failure 400 {object} []dto.ValidateError "参数验证失败"
|
||||
// @Failure 404 {object} dto.Response "文档块不存在"
|
||||
// @Router /blocks/{block_id}/move [post]
|
||||
func (c *DocumentController) MoveBlock(ctx *fiber.Ctx) error {
|
||||
var params dto.BlockIDParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
var req dto.MoveBlockRequest
|
||||
if err := ctx.BodyParser(&req); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
// 获取块信息
|
||||
block, err := c.documentService.GetBlock(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if block == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrBlockNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrBlockNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查文档是否存在
|
||||
doc, err := c.documentService.Get(ctx.Context(), block.DocumentId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if doc == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrDocumentNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
// 检查用户是否有权限访问该文档
|
||||
user := c.authService.GetUser(ctx)
|
||||
collection, err := c.collectionService.Get(ctx.Context(), doc.CollectionId)
|
||||
collectionEntity, err := c.collectionService.Get(ctx.Context(), doc.CollectionId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), collection.WorkspaceId)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), collectionEntity.WorkspaceId)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspace)
|
||||
isMember, err := c.workspaceService.IsMember(ctx.Context(), user.ID, workspaceEntity)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !isMember {
|
||||
return dto.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrNoPermission).Status(fiber.StatusForbidden).Send()
|
||||
}
|
||||
|
||||
err = c.documentService.MoveBlock(ctx.Context(), params.ID, req.AfterBlockID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(nil).Send()
|
||||
return response.Ctx(ctx).Success(nil).Send()
|
||||
}
|
||||
|
@ -1,14 +1,18 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/pkg/response"
|
||||
"net/http"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto/user"
|
||||
_ "leafdev.top/Leaf/leaf-library-3/internal/entity"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/errs"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/pkg/validator"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/services/auth"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/services/workspace"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/errs"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/user"
|
||||
)
|
||||
|
||||
type WorkspaceController struct {
|
||||
@ -30,32 +34,32 @@ func NewWorkspaceController(workspaceService *workspace.Service, authService *au
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body dto.CreateWorkspaceRequest true "创建工作空间请求"
|
||||
// @Success 200 {object} dto.Response{data=entity.Workspace}
|
||||
// @Failure 400 {object} dto.Response{data=[]dto.ValidateError} "参数验证失败"
|
||||
// @Success 200 {object} entity.Workspace
|
||||
// @Failure 400 {object} []dto.ValidateError "参数验证失败"
|
||||
// @Router /workspaces [post]
|
||||
func (c *WorkspaceController) CreateWorkspace(ctx *fiber.Ctx) error {
|
||||
var req dto.CreateWorkspaceRequest
|
||||
if err := ctx.BodyParser(&req); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
if validationErrors, ok, err := validator.Struct(req); !ok {
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
return dto.Ctx(ctx).Data(validationErrors).Status(fiber.StatusBadRequest).Send()
|
||||
return response.Ctx(ctx).Data(validationErrors).Status(fiber.StatusBadRequest).Send()
|
||||
}
|
||||
|
||||
// 从上下文获取用户ID
|
||||
user := c.authService.GetUser(ctx)
|
||||
userId := user.ID
|
||||
authUser := c.authService.GetUser(ctx)
|
||||
userId := authUser.ID
|
||||
|
||||
workspace, err := c.workspaceService.Create(ctx.Context(), userId, req.Name)
|
||||
workspaceEntity, err := c.workspaceService.Create(ctx.Context(), userId, req.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(workspace).Send()
|
||||
return response.Ctx(ctx).Success(workspaceEntity).Send()
|
||||
}
|
||||
|
||||
// GetWorkspace 获取工作空间
|
||||
@ -65,29 +69,29 @@ func (c *WorkspaceController) CreateWorkspace(ctx *fiber.Ctx) error {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "工作空间ID"
|
||||
// @Success 200 {object} dto.Response{data=entity.Workspace}
|
||||
// @Success 200 {object} entity.Workspace
|
||||
// @Failure 404 {object} dto.Response "工作空间不存在"
|
||||
// @Router /workspaces/{id} [get]
|
||||
func (c *WorkspaceController) GetWorkspace(ctx *fiber.Ctx) error {
|
||||
var params dto.WorkspaceIDParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
exists, err := c.workspaceService.Exists(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !exists {
|
||||
return dto.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), params.ID)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(workspace).Send()
|
||||
return response.Ctx(ctx).Success(workspaceEntity).Send()
|
||||
}
|
||||
|
||||
// ListWorkspaces 列出用户的所有工作空间
|
||||
@ -96,19 +100,18 @@ func (c *WorkspaceController) GetWorkspace(ctx *fiber.Ctx) error {
|
||||
// @Tags Workspace
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} dto.Response{data=[]entity.Workspace}
|
||||
// @Success 200 {object} []entity.Workspace
|
||||
// @Router /workspaces [get]
|
||||
func (c *WorkspaceController) ListWorkspaces(ctx *fiber.Ctx) error {
|
||||
// 从上下文获取用户ID
|
||||
user := c.authService.GetUser(ctx)
|
||||
userId := user.ID
|
||||
authUser := c.authService.GetUser(ctx)
|
||||
|
||||
workspaces, err := c.workspaceService.List(ctx.Context(), userId)
|
||||
workspaces, err := c.workspaceService.List(ctx.Context(), authUser.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(workspaces).Send()
|
||||
return response.Ctx(ctx).Success(workspaces).Send()
|
||||
}
|
||||
|
||||
// DeleteWorkspace 删除工作空间
|
||||
@ -118,29 +121,66 @@ func (c *WorkspaceController) ListWorkspaces(ctx *fiber.Ctx) error {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "工作空间ID"
|
||||
// @Success 200 {object} dto.Response
|
||||
// @Success 200
|
||||
// @Failure 404 {object} dto.Response "工作空间不存在"
|
||||
// @Router /workspaces/{id} [delete]
|
||||
func (c *WorkspaceController) DeleteWorkspace(ctx *fiber.Ctx) error {
|
||||
var params dto.WorkspaceIDParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
exists, err := c.workspaceService.Exists(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !exists {
|
||||
return dto.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
err = c.workspaceService.DeleteWorkspace(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(nil).Send()
|
||||
return response.Ctx(ctx).Success(nil).Send()
|
||||
}
|
||||
|
||||
// GetWorkspaceMembers 获取工作空间的成员
|
||||
// @Summary 获取工作空间的成员
|
||||
// @Description 根据工作空间ID获取工作空间的成员
|
||||
// @Tags Workspace
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "工作空间ID"
|
||||
// @Success 200 {object} entity.Workspace
|
||||
// @Failure 404 {object} dto.Response "工作空间不存在"
|
||||
// @Router /workspaces/{id}/members [get]
|
||||
func (c *WorkspaceController) GetWorkspaceMembers(ctx *fiber.Ctx) error {
|
||||
var params dto.WorkspaceIDParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return response.Ctx(ctx).Status(http.StatusBadRequest).Send()
|
||||
}
|
||||
|
||||
exists, err := c.workspaceService.Exists(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !exists {
|
||||
return response.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
workspaceMembers, err := c.workspaceService.ListMembers(ctx.Context(), workspaceEntity)
|
||||
if err != nil {
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return response.Ctx(ctx).Success(workspaceMembers).Send()
|
||||
}
|
||||
|
||||
// AddMember 添加工作空间成员
|
||||
@ -151,51 +191,51 @@ func (c *WorkspaceController) DeleteWorkspace(ctx *fiber.Ctx) error {
|
||||
// @Produce json
|
||||
// @Param id path int true "工作空间ID"
|
||||
// @Param request body dto.AddWorkspaceMemberRequest true "添加成员请求"
|
||||
// @Success 200 {object} dto.Response{data=entity.WorkspaceMember}
|
||||
// @Failure 400 {object} dto.Response{data=[]dto.ValidateError} "参数验证失败"
|
||||
// @Success 200 {object} entity.WorkspaceMember
|
||||
// @Failure 400 {object} []dto.ValidateError "参数验证失败"
|
||||
// @Failure 404 {object} dto.Response "工作空间不存在"
|
||||
// @Failure 409 {object} dto.Response "成员已存在"
|
||||
// @Router /workspaces/{id}/members [post]
|
||||
func (c *WorkspaceController) AddMember(ctx *fiber.Ctx) error {
|
||||
var params dto.WorkspaceIDParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
exists, err := c.workspaceService.Exists(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !exists {
|
||||
return dto.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
var req dto.AddWorkspaceMemberRequest
|
||||
if err := ctx.BodyParser(&req); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
if validationErrors, ok, err := validator.Struct(req); !ok {
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
return dto.Ctx(ctx).Data(validationErrors).Status(fiber.StatusBadRequest).Send()
|
||||
return response.Ctx(ctx).Data(validationErrors).Status(fiber.StatusBadRequest).Send()
|
||||
}
|
||||
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), params.ID)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), params.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
member, err := c.workspaceService.AddMember(ctx.Context(), req.UserID, workspace)
|
||||
member, err := c.workspaceService.AddMember(ctx.Context(), req.UserID, workspaceEntity)
|
||||
if err != nil {
|
||||
if err == errs.ErrMemberAlreadyExists {
|
||||
return dto.Ctx(ctx).Error(err).Status(fiber.StatusConflict).Send()
|
||||
if errors.Is(err, errs.ErrMemberAlreadyExists) {
|
||||
return response.Ctx(ctx).Error(err).Status(fiber.StatusConflict).Send()
|
||||
}
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(member).Send()
|
||||
return response.Ctx(ctx).Success(member).Send()
|
||||
}
|
||||
|
||||
// RemoveMember 移除工作空间成员
|
||||
@ -212,29 +252,29 @@ func (c *WorkspaceController) AddMember(ctx *fiber.Ctx) error {
|
||||
func (c *WorkspaceController) RemoveMember(ctx *fiber.Ctx) error {
|
||||
var params dto.WorkspaceMemberParam
|
||||
if err := ctx.ParamsParser(¶ms); err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
exists, err := c.workspaceService.Exists(ctx.Context(), params.WorkspaceID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
if !exists {
|
||||
return dto.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
return response.Ctx(ctx).Error(errs.ErrWorkspaceNotExists).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
|
||||
workspace, err := c.workspaceService.Get(ctx.Context(), params.WorkspaceID)
|
||||
workspaceEntity, err := c.workspaceService.Get(ctx.Context(), params.WorkspaceID)
|
||||
if err != nil {
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
err = c.workspaceService.RemoveMember(ctx.Context(), user.ID(params.UserID), workspace)
|
||||
err = c.workspaceService.RemoveMember(ctx.Context(), user.ID(params.UserID), workspaceEntity)
|
||||
if err != nil {
|
||||
if err == errs.ErrMemberNotExists {
|
||||
return dto.Ctx(ctx).Error(err).Status(fiber.StatusNotFound).Send()
|
||||
if errors.Is(err, errs.ErrMemberNotExists) {
|
||||
return response.Ctx(ctx).Error(err).Status(fiber.StatusNotFound).Send()
|
||||
}
|
||||
return err
|
||||
return response.Ctx(ctx).Status(http.StatusInternalServerError).Send()
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Success(nil).Send()
|
||||
return response.Ctx(ctx).Success(nil).Send()
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/pkg/response"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/base/conf"
|
||||
authService "leafdev.top/Leaf/leaf-library-3/internal/services/auth"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/constants"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/errs"
|
||||
authType "leafdev.top/Leaf/leaf-library-3/internal/types/user"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/constants"
|
||||
authType "leafdev.top/Leaf/leaf-library-3/internal/dto/user"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/errs"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/base/conf"
|
||||
authService "leafdev.top/Leaf/leaf-library-3/internal/services/auth"
|
||||
)
|
||||
|
||||
type Auth struct {
|
||||
@ -33,7 +33,7 @@ func NewAuth(config *conf.Config, authService *authService.Service) *Auth {
|
||||
|
||||
func (a *Auth) Handler() fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
var r = dto.Ctx(c)
|
||||
var r = response.Ctx(c)
|
||||
var err error
|
||||
var token = new(authType.User)
|
||||
|
||||
|
@ -2,14 +2,15 @@ package middleware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/pkg/response"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
userPkg "leafdev.top/Leaf/leaf-library-3/internal/dto/user"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/base/conf"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/services/auth"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
userPkg "leafdev.top/Leaf/leaf-library-3/internal/types/user"
|
||||
)
|
||||
|
||||
type RBAC struct {
|
||||
@ -21,11 +22,11 @@ func (m *RBAC) RoutePermission() fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
user, ok := m.authService.GetUserSafe(c)
|
||||
if !ok {
|
||||
return dto.Ctx(c).Error(nil).Status(http.StatusUnauthorized).Send()
|
||||
return response.Ctx(c).Error(nil).Status(http.StatusUnauthorized).Send()
|
||||
}
|
||||
|
||||
if !user.Valid {
|
||||
return dto.Ctx(c).Error(nil).Status(http.StatusUnauthorized).Send()
|
||||
return response.Ctx(c).Error(nil).Status(http.StatusUnauthorized).Send()
|
||||
}
|
||||
|
||||
var path = cleanPath(c.Path())
|
||||
@ -35,7 +36,7 @@ func (m *RBAC) RoutePermission() fiber.Handler {
|
||||
pass := user.HasPermissions(permissionName)
|
||||
|
||||
if !pass {
|
||||
return dto.Ctx(c).
|
||||
return response.Ctx(c).
|
||||
Message(fmt.Sprintf("permission denied, permission name: %s", permissionName)).
|
||||
Error(nil).
|
||||
Status(http.StatusForbidden).
|
||||
@ -50,11 +51,11 @@ func (m *RBAC) RequirePermissions(permissions ...string) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
user, ok := m.authService.GetUserSafe(c)
|
||||
if !ok {
|
||||
return dto.Ctx(c).Error(nil).Status(http.StatusUnauthorized).Send()
|
||||
return response.Ctx(c).Error(nil).Status(http.StatusUnauthorized).Send()
|
||||
}
|
||||
|
||||
if !user.Valid {
|
||||
return dto.Ctx(c).Error(nil).Status(http.StatusUnauthorized).Send()
|
||||
return response.Ctx(c).Error(nil).Status(http.StatusUnauthorized).Send()
|
||||
}
|
||||
|
||||
var pass = true
|
||||
@ -72,7 +73,7 @@ func (m *RBAC) RequirePermissions(permissions ...string) fiber.Handler {
|
||||
}
|
||||
|
||||
if !pass {
|
||||
return dto.Ctx(c).
|
||||
return response.Ctx(c).
|
||||
Message(fmt.Sprintf("permission denied, required permissions: %s, failed permission: %s",
|
||||
permissions, failedPermissionName)).
|
||||
Error(nil).
|
||||
@ -88,11 +89,11 @@ func (m *RBAC) RequireRoles(roles ...string) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
user, ok := m.authService.GetUserSafe(c)
|
||||
if !ok {
|
||||
return dto.Ctx(c).Error(nil).Status(http.StatusUnauthorized).Send()
|
||||
return response.Ctx(c).Error(nil).Status(http.StatusUnauthorized).Send()
|
||||
}
|
||||
|
||||
if !user.Valid {
|
||||
return dto.Ctx(c).Error(nil).Status(http.StatusUnauthorized).Send()
|
||||
return response.Ctx(c).Error(nil).Status(http.StatusUnauthorized).Send()
|
||||
}
|
||||
|
||||
var pass = true
|
||||
@ -110,7 +111,7 @@ func (m *RBAC) RequireRoles(roles ...string) fiber.Handler {
|
||||
}
|
||||
|
||||
if !pass {
|
||||
return dto.Ctx(c).
|
||||
return response.Ctx(c).
|
||||
Message(fmt.Sprintf("permission denied, required roles: %s, failed role %s", roles, failedRoleName)).
|
||||
Error(nil).
|
||||
Status(http.StatusForbidden).
|
||||
|
@ -2,24 +2,25 @@ package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/pkg/response"
|
||||
"net/http"
|
||||
|
||||
errs2 "leafdev.top/Leaf/leaf-library-3/internal/errs"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"gorm.io/gorm"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/base/logger"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/pkg/validator"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/errs"
|
||||
)
|
||||
|
||||
func errorConverter(logger *logger.Logger, ctx *fiber.Ctx, err error) error {
|
||||
status := http.StatusInternalServerError
|
||||
|
||||
if err == nil {
|
||||
return dto.Ctx(ctx).Error(errs.ErrInternalServerError).Status(status).Send()
|
||||
return response.Ctx(ctx).Error(errs2.ErrInternalServerError).Status(status).Send()
|
||||
}
|
||||
|
||||
var errorMsg dto.IError
|
||||
var errorMsg response.IError
|
||||
|
||||
switch {
|
||||
// 404
|
||||
@ -31,20 +32,20 @@ func errorConverter(logger *logger.Logger, ctx *fiber.Ctx, err error) error {
|
||||
status = http.StatusUnprocessableEntity
|
||||
errorMsg = err
|
||||
|
||||
case errors.Is(err, errs.ErrPermissionDenied):
|
||||
case errors.Is(err, errs2.ErrPermissionDenied):
|
||||
status = http.StatusForbidden
|
||||
|
||||
case errors.Is(err, validator.ErrValidationFailed):
|
||||
status = http.StatusBadRequest
|
||||
|
||||
case errors.Is(err, gorm.ErrRecordNotFound):
|
||||
errorMsg = errs.ErrNotFound
|
||||
errorMsg = errs2.ErrNotFound
|
||||
status = http.StatusNotFound
|
||||
|
||||
default:
|
||||
logger.Sugar.Errorf("fiber error: %s", err)
|
||||
errorMsg = errs.UnknownError
|
||||
errorMsg = errs2.UnknownError
|
||||
}
|
||||
|
||||
return dto.Ctx(ctx).Status(status).Error(errorMsg).Send()
|
||||
return response.Ctx(ctx).Status(status).Error(errorMsg).Send()
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/pkg/response"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/errs"
|
||||
|
||||
"github.com/ansrivas/fiberprometheus/v2"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
@ -14,8 +17,6 @@ import (
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/base/logger"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/router"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/services/auth"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/errs"
|
||||
)
|
||||
|
||||
type HttpServer struct {
|
||||
@ -83,7 +84,7 @@ func (hs *HttpServer) BizRouter() *fiber.App {
|
||||
|
||||
// 404 Route
|
||||
hs.Fiber.Use(func(ctx *fiber.Ctx) error {
|
||||
return dto.Ctx(ctx).Status(fiber.StatusNotFound).Error(errs.RouteNotFound).Send()
|
||||
return response.Ctx(ctx).Status(fiber.StatusNotFound).Error(errs.RouteNotFound).Send()
|
||||
})
|
||||
|
||||
return hs.Fiber
|
||||
|
@ -1,7 +1,7 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/user"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto/user"
|
||||
)
|
||||
|
||||
const (
|
@ -1,7 +1,7 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/user"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto/user"
|
||||
)
|
||||
|
||||
type CurrentUserResponse struct {
|
@ -1,6 +1,8 @@
|
||||
package dto
|
||||
|
||||
import "leafdev.top/Leaf/leaf-library-3/internal/types/user"
|
||||
import (
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto/user"
|
||||
)
|
||||
|
||||
// CreateWorkspaceRequest 创建工作空间请求
|
||||
type CreateWorkspaceRequest struct {
|
@ -2,7 +2,7 @@ package entity
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto"
|
||||
)
|
||||
|
||||
type Collection struct {
|
||||
|
@ -2,7 +2,7 @@ package entity
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto"
|
||||
)
|
||||
|
||||
type Document struct {
|
||||
|
@ -3,7 +3,7 @@ package entity
|
||||
import (
|
||||
"time"
|
||||
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto"
|
||||
)
|
||||
|
||||
// Model 是所有 entity 的基类,后期要将所有的 Base 改成这种形式
|
||||
|
@ -2,8 +2,8 @@ package entity
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/user"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto/user"
|
||||
)
|
||||
|
||||
type Workspace struct {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package dto
|
||||
package response
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@ -18,7 +18,6 @@ type ValidateError struct {
|
||||
type Body struct {
|
||||
Message string `json:"message"`
|
||||
Error string `json:"error"`
|
||||
//ValidationErrors *[]ValidateError `json:"validation_error,omitempty"`
|
||||
Success bool `json:"success"`
|
||||
Data any `json:"data,omitempty"`
|
||||
Wrap bool `json:"-"`
|
||||
@ -33,7 +32,7 @@ type Response struct {
|
||||
func Ctx(c *fiber.Ctx) *Response {
|
||||
return &Response{
|
||||
body: &Body{
|
||||
Wrap: true,
|
||||
Wrap: false,
|
||||
},
|
||||
ctx: c,
|
||||
httpStatus: 0,
|
||||
@ -50,13 +49,7 @@ func (r *Response) Message(message string) *Response {
|
||||
return r
|
||||
}
|
||||
|
||||
// WithoutWrap 将不在 body 中包裹 data
|
||||
func (r *Response) WithoutWrap() *Response {
|
||||
r.body.Wrap = false
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// Wrap 将在响应中包裹 data
|
||||
func (r *Response) Wrap() *Response {
|
||||
r.body.Wrap = true
|
||||
return r
|
||||
@ -108,11 +101,27 @@ func (r *Response) Send() error {
|
||||
}
|
||||
}
|
||||
|
||||
if r.body.Wrap {
|
||||
return r.ctx.Status(r.httpStatus).JSON(r.body)
|
||||
// if 400 bad request but not have message
|
||||
if r.httpStatus == http.StatusBadRequest {
|
||||
if r.body.Message == "" {
|
||||
r.Message("Bad request")
|
||||
}
|
||||
}
|
||||
|
||||
return r.ctx.Status(r.httpStatus).JSON(r.body.Data)
|
||||
var rspCtx = r.ctx.Status(r.httpStatus)
|
||||
var rspErr error
|
||||
|
||||
if r.body.Data == nil {
|
||||
return rspCtx.Send([]byte{})
|
||||
}
|
||||
|
||||
if r.body.Wrap {
|
||||
rspErr = rspCtx.JSON(r.body)
|
||||
}
|
||||
|
||||
rspErr = rspCtx.JSON(r.body.Data)
|
||||
|
||||
return rspErr
|
||||
}
|
||||
|
||||
func (r *Response) Success(data any) *Response {
|
@ -2,9 +2,9 @@ package validator
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/pkg/response"
|
||||
|
||||
"github.com/gookit/validate"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -27,11 +27,11 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func Struct(data interface{}) (validationErrors *[]dto.ValidateError, ok bool, err error) {
|
||||
func Struct(data interface{}) (validationErrors *[]response.ValidateError, ok bool, err error) {
|
||||
v := validate.Struct(data)
|
||||
|
||||
var e error
|
||||
var ves []dto.ValidateError
|
||||
var ves []response.ValidateError
|
||||
|
||||
if v.Validate() {
|
||||
return &ves, true, nil // 返回指针
|
||||
@ -39,7 +39,7 @@ func Struct(data interface{}) (validationErrors *[]dto.ValidateError, ok bool, e
|
||||
e = ErrValidationFailed
|
||||
|
||||
for _, err := range v.Errors {
|
||||
ves = append(ves, dto.ValidateError{
|
||||
ves = append(ves, response.ValidateError{
|
||||
Message: err.String(),
|
||||
})
|
||||
}
|
||||
|
@ -2,10 +2,9 @@ package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/constants"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/errs"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/user"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/constants"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto/user"
|
||||
errs2 "leafdev.top/Leaf/leaf-library-3/internal/errs"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
@ -82,24 +81,24 @@ func (a *Service) parseUserJWT(tokenType constants.JwtTokenTypes, jwtToken strin
|
||||
} else {
|
||||
token, err := a.jwks.ParseJWT(jwtToken)
|
||||
if err != nil {
|
||||
return nil, errs.NotValidToken
|
||||
return nil, errs2.NotValidToken
|
||||
}
|
||||
|
||||
subStr, err := token.Claims.GetSubject()
|
||||
if err != nil {
|
||||
return nil, errs.NotValidToken
|
||||
return nil, errs2.NotValidToken
|
||||
}
|
||||
|
||||
sub = user.ID(subStr)
|
||||
|
||||
// 如果 token.Header 中没有 typ
|
||||
if token.Header["typ"] == "" {
|
||||
return nil, errs.EmptyResponse
|
||||
return nil, errs2.EmptyResponse
|
||||
}
|
||||
|
||||
// 验证 token 类型
|
||||
if tokenType != "" && tokenType.String() != token.Header["typ"] {
|
||||
return nil, errs.TokenError
|
||||
return nil, errs2.TokenError
|
||||
}
|
||||
|
||||
jwtIdToken.Valid = true
|
||||
|
@ -3,9 +3,10 @@ package collection
|
||||
import (
|
||||
"context"
|
||||
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/errs"
|
||||
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/entity"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/errs"
|
||||
)
|
||||
|
||||
func (s *Service) Get(ctx context.Context, collectionId dto.EntityId) (*entity.Collection, error) {
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/entity"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
)
|
||||
|
||||
// Get 获取文档
|
||||
|
@ -2,10 +2,10 @@ package stream
|
||||
|
||||
import (
|
||||
"context"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/events"
|
||||
"time"
|
||||
|
||||
"github.com/segmentio/kafka-go"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/events"
|
||||
)
|
||||
|
||||
//var connections = map[string]*kafka.Conn{}
|
||||
|
@ -3,10 +3,11 @@ package workspace
|
||||
import (
|
||||
"context"
|
||||
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto/user"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/errs"
|
||||
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/entity"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/dto"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/errs"
|
||||
"leafdev.top/Leaf/leaf-library-3/internal/types/user"
|
||||
)
|
||||
|
||||
func (s *Service) Get(ctx context.Context, workspaceId dto.EntityId) (*entity.Workspace, error) {
|
||||
@ -54,6 +55,10 @@ func (s *Service) Create(ctx context.Context, userId user.ID, name string) (*ent
|
||||
return workspace, nil
|
||||
}
|
||||
|
||||
func (s *Service) ListMembers(ctx context.Context, workspaceEntity *entity.Workspace) ([]*entity.WorkspaceMember, error) {
|
||||
return s.dao.WithContext(ctx).WorkspaceMember.Where(s.dao.WorkspaceMember.WorkspaceId.Eq(workspaceEntity.ID.Uint())).Find()
|
||||
}
|
||||
|
||||
func (s *Service) AddMember(ctx context.Context, userId user.ID, workspaceEntity *entity.Workspace) (*entity.WorkspaceMember, error) {
|
||||
memberExists, err := s.MemberExists(ctx, userId, workspaceEntity)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user