SaveBook 保存书籍信息
()
| 208 | |
| 209 | // SaveBook 保存书籍信息 |
| 210 | func (this *BookController) SaveBook() { |
| 211 | bookResult, err := this.IsPermission() |
| 212 | if err != nil { |
| 213 | this.JsonResult(6001, err.Error()) |
| 214 | } |
| 215 | |
| 216 | book, err := models.NewBook().Find(bookResult.BookId) |
| 217 | if err != nil { |
| 218 | logs.Error("SaveBook => ", err) |
| 219 | this.JsonResult(6002, err.Error()) |
| 220 | } |
| 221 | |
| 222 | bookName := strings.TrimSpace(this.GetString("book_name")) |
| 223 | description := strings.TrimSpace(this.GetString("description", "")) |
| 224 | commentStatus := this.GetString("comment_status") |
| 225 | tag := strings.TrimSpace(this.GetString("label")) |
| 226 | editor := strings.TrimSpace(this.GetString("editor")) |
| 227 | |
| 228 | if strings.Count(description, "") > 500 { |
| 229 | this.JsonResult(6004, "书籍描述不能大于500字") |
| 230 | } |
| 231 | if commentStatus != "open" && commentStatus != "closed" && commentStatus != "group_only" && commentStatus != "registered_only" { |
| 232 | commentStatus = "closed" |
| 233 | } |
| 234 | if tag != "" { |
| 235 | tags := strings.Split(tag, ",") |
| 236 | if len(tags) > 10 { |
| 237 | this.JsonResult(6005, "最多允许添加10个标签") |
| 238 | } |
| 239 | } |
| 240 | if editor != "markdown" && editor != "html" { |
| 241 | editor = "markdown" |
| 242 | } |
| 243 | |
| 244 | book.BookName = bookName |
| 245 | book.Description = description |
| 246 | book.CommentStatus = commentStatus |
| 247 | book.Label = tag |
| 248 | book.Editor = editor |
| 249 | book.Author = this.GetString("author") |
| 250 | book.AuthorURL = this.GetString("author_url") |
| 251 | book.Lang = this.GetString("lang") |
| 252 | book.AdTitle = this.GetString("ad_title") |
| 253 | book.AdLink = this.GetString("ad_link") |
| 254 | _, book.NavJSON = this.parseBookNav() |
| 255 | |
| 256 | if err := book.Update(); err != nil { |
| 257 | this.JsonResult(6006, "保存失败") |
| 258 | } |
| 259 | bookResult.BookName = bookName |
| 260 | bookResult.Description = description |
| 261 | bookResult.CommentStatus = commentStatus |
| 262 | bookResult.Label = tag |
| 263 | |
| 264 | //更新书籍分类 |
| 265 | if cids, ok := this.Ctx.Request.Form["cid"]; ok { |
| 266 | new(models.BookCategory).SetBookCates(book.BookId, cids) |
| 267 | } |
nothing calls this directly
no test coverage detected