From b8f7786f8028afbf4dcafbf1a0955b0f808cb6fd Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 21 May 2025 14:10:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E6=A1=A3=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/file.go | 25 ++++++++++++++++++++++++- service/fileService.go | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/handler/file.go b/handler/file.go index 809f506..6c4e73e 100644 --- a/handler/file.go +++ b/handler/file.go @@ -21,6 +21,7 @@ func SetUpFileGroup(router *gin.Engine) { fileGroup.POST("/file_delete", DeleteUserFile) fileGroup.POST("/file_update", UpdateUserFile) fileGroup.POST("/find_file_content", FindFileContent) + fileGroup.POST("/update_file_content", UpdateFileContent) fileGroup.POST("/create_file_content", CreateFileContent) fileGroup.POST("/get_file_will_convert_content", GetFileWillConvertContent) //需要将文件转为文件内容的文件列表接口 fileGroup.POST("/convert_msg_to_file", ConvertMsgToFile) //将消息转为文件 @@ -375,7 +376,29 @@ func CreateFileContent(c *gin.Context) { fileContentID, err2 := service.CreateFileContent(userId, req.FileID, req.FileContent) if err2 != nil { resp.Code = proto.ParameterError - resp.Message = "find file content failed:" + err2.Error() + resp.Message = "create file content failed:" + err2.Error() + } else { + resp.Code = proto.SuccessCode + resp.Message = "success" + resp.Data = fileContentID + } + } else { + resp.Code = proto.ParameterError + resp.Message = "upload form parameter decode error:" + err.Error() + } + c.JSON(http.StatusOK, resp) +} + +func UpdateFileContent(c *gin.Context) { + id, _ := c.Get("id") + userId := int(id.(float64)) + var req proto.FileContentReq + var resp proto.FileContentResp + if err := c.ShouldBind(&req); err == nil { + fileContentID, err2 := service.UpdateFileContent(userId, req.FileID, req.FileContent) + if err2 != nil { + resp.Code = proto.ParameterError + resp.Message = "update file content failed:" + err2.Error() } else { resp.Code = proto.SuccessCode resp.Message = "success" diff --git a/service/fileService.go b/service/fileService.go index f95654a..68a88be 100644 --- a/service/fileService.go +++ b/service/fileService.go @@ -347,6 +347,28 @@ func CreateFileContent(userID, fileID int, fileContent string) (uint, error) { return dao.CreateFileContent(fileID, fileContent) } +func UpdateFileContent(userID, fileID int, fileContent string) (uint, error) { + fileAuth := dao.FindFileAuthByID(fileID) + user := GetUserByIDWithCache(userID) + if fileAuth.ID == 0 { + return 0, errors.New("file auth not found") + } + if fileAuth.AuthID != userID && user.Role != "admin" { + return 0, errors.New("no permission") + } + //查找文件内容是否存在 + fileContentC, err := dao.FindFileContentByFileIDAndContentID(fileID) + if err != nil { + return 0, err + } + if fileContentC.ID == 0 { + return 0, errors.New("file content not found") + } + id, err := dao.UpdateFileContentByID(fileContentC.ID, fileContent) + return id, err + +} + func GetFileWillConvertContentFileList(userID int) ([]dao.File, error) { user := GetUserByIDWithCache(userID) if user.Role != "admin" {