添加文档内容更新接口
This commit is contained in:
parent
c0f3ceaa7d
commit
b8f7786f80
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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" {
|
||||
|
|
|
|||
Loading…
Reference in New Issue