From 05c133a4b5b4a6a240a892e25790ddd673379126 Mon Sep 17 00:00:00 2001
From: neo-f <tmpgfw@gmail.com>
Date: Wed, 22 Mar 2023 22:54:14 +0800
Subject: [PATCH] fix: documents api

---
 internal/router/base.go |  4 ++--
 internal/router/doc.go  | 12 ++++++------
 internal/schema/docs.go |  8 ++++----
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/internal/router/base.go b/internal/router/base.go
index ad6a709..df26b05 100644
--- a/internal/router/base.go
+++ b/internal/router/base.go
@@ -11,12 +11,12 @@ var userClaimsKey = struct{}{}
 func JWTRequired(c *fiber.Ctx) error {
 	jwt := c.Get("Authorization")
 	if jwt == "" {
-		return c.Status(401).JSON(fiber.Map{"msg": "Unauthorized"})
+		return fiber.ErrUnauthorized
 	}
 	claims, err := casdoorsdk.ParseJwtToken(jwt)
 	if err != nil {
 		log.Ctx(c.UserContext()).Error().Err(err).Msg("Unauthorized user")
-		return c.Status(401).JSON(fiber.Map{"msg": "Unauthorized"})
+		return fiber.ErrUnauthorized
 	}
 	c.Locals(userClaimsKey, claims)
 	return nil
diff --git a/internal/router/doc.go b/internal/router/doc.go
index 3086448..e16a493 100644
--- a/internal/router/doc.go
+++ b/internal/router/doc.go
@@ -26,7 +26,7 @@ func RegisterDocRouter(app *soda.Soda) {
 		SetSummary("更新文档").
 		AddJWTSecurity(JWTRequired).
 		SetParameters(schema.DocID{}).
-		SetJSONRequestBody(schema.ListDocQuery{}).
+		SetJSONRequestBody(schema.UpdateDoc{}).
 		AddJSONResponse(200, schema.Doc{}).OK()
 
 	app.Delete("/docs/:id", nil).
@@ -45,27 +45,27 @@ func RegisterDocRouter(app *soda.Soda) {
 
 	app.Post("/docs/batch/update", nil).
 		AddTags("文档管理").
-		SetSummary("批量-文件删除").
+		SetSummary("批量-文件更新").
 		AddJWTSecurity(JWTRequired).
 		SetJSONRequestBody(schema.DocsBatchUpdate{}).
 		AddJSONResponse(200, schema.DocsBatchResults{}).OK()
 
 	app.Get("/doc-folders", nil).
-		AddTags("文档管理").
+		AddTags("文件夹管理").
 		SetSummary("获取文件夹树").
 		AddJWTSecurity(JWTRequired).
 		SetParameters(schema.GetDocFolderTree{}).
 		AddJSONResponse(200, schema.DocFolderWithChildren{}).OK()
 
 	app.Post("/doc-folders", nil).
-		AddTags("文档管理").
+		AddTags("文件夹管理").
 		SetSummary("新建文件夹").
 		AddJWTSecurity(JWTRequired).
 		SetJSONRequestBody(schema.CreateDocFolder{}).
 		AddJSONResponse(200, schema.DocFolder{}).OK()
 
 	app.Put("/doc-folders/:id", nil).
-		AddTags("文档管理").
+		AddTags("文件夹管理").
 		SetSummary("更新文件夹").
 		AddJWTSecurity(JWTRequired).
 		SetParameters(schema.DocFolderID{}).
@@ -73,7 +73,7 @@ func RegisterDocRouter(app *soda.Soda) {
 		AddJSONResponse(200, schema.DocFolder{}).OK()
 
 	app.Delete("/doc-folders/:id", nil).
-		AddTags("文档管理").
+		AddTags("文件夹管理").
 		SetSummary("删除文件夹").
 		AddJWTSecurity(JWTRequired).
 		SetParameters(schema.DocFolderID{}).
diff --git a/internal/schema/docs.go b/internal/schema/docs.go
index f585347..91dc692 100644
--- a/internal/schema/docs.go
+++ b/internal/schema/docs.go
@@ -75,16 +75,16 @@ type UpdateDoc struct {
 type ListDocQuery struct {
 	PageableQuery
 	SortableQuery
-	FolderIDs *[]string `query:"folder_ids" validate:"required" oai:"description=归属文件夹ID"`
+	FolderIDs *[]string `query:"folder_ids" oai:"description=筛选归属文件夹ID"`
 }
 
 type DocsBatchDelete struct {
-	IDs      []string `query:"ids" validate:"required" oai:"description=批量选择文件ID列表"`
-	FolderID string   `            validate:"required" oai:"description=更新归属文件夹ID"   json:"folder_id"`
+	IDs []string `json:"ids" validate:"required" oai:"description=批量选择文件ID列表"`
 }
 
 type DocsBatchUpdate struct {
-	IDs []string `query:"ids" validate:"required" oai:"description=批量选择文件ID列表"`
+	IDs      []string `json:"ids"       validate:"required" oai:"description=批量选择文件ID列表"`
+	FolderID string   `json:"folder_id" validate:"required" oai:"description=更新归属文件夹ID"`
 }
 
 type DocActionResult struct {