MCPcopy Index your code
hub / github.com/TruthHun/BookStack / EditBook

Method EditBook

controllers/ManagerController.go:403–476  ·  view source on GitHub ↗

编辑书籍.

()

Source from the content-addressed store, hash-verified

401
402// 编辑书籍.
403func (this *ManagerController) EditBook() {
404
405 identify := this.GetString(":key")
406 if identify == "" {
407 this.Abort("404")
408 }
409
410 book, err := models.NewBook().FindByFieldFirst("identify", identify)
411 if err != nil {
412 this.Abort("404")
413 }
414
415 if this.Ctx.Input.IsPost() {
416 bookName := strings.TrimSpace(this.GetString("book_name"))
417 description := strings.TrimSpace(this.GetString("description", ""))
418 commentStatus := this.GetString("comment_status")
419 tag := strings.TrimSpace(this.GetString("label"))
420 orderIndex, _ := this.GetInt("order_index", 0)
421 pin, _ := this.GetInt("pin", 0)
422
423 if strings.Count(description, "") > 500 {
424 this.JsonResult(6004, "书籍描述不能大于500字")
425 }
426 if commentStatus != "open" && commentStatus != "closed" && commentStatus != "group_only" && commentStatus != "registered_only" {
427 commentStatus = "closed"
428 }
429 if tag != "" {
430 tags := strings.Split(tag, ";")
431 if len(tags) > 10 {
432 this.JsonResult(6005, "最多允许添加10个标签")
433 }
434 }
435
436 book.BookName = bookName
437 book.Description = description
438 book.CommentStatus = commentStatus
439 book.Label = tag
440 book.OrderIndex = orderIndex
441 book.Pin = pin
442
443 if err := book.Update(); err != nil {
444 this.JsonResult(6006, "保存失败")
445 }
446
447 go func() {
448 es := models.ElasticSearchData{
449 Id: book.BookId,
450 BookId: 0,
451 Title: book.BookName,
452 Keywords: book.Label,
453 Content: book.Description,
454 Vcnt: book.Vcnt,
455 Private: book.PrivatelyOwned,
456 }
457 client := models.NewElasticSearchClient()
458 if errSearch := client.BuildIndex(es); errSearch != nil && client.On {
459 beego.Error(errSearch.Error())
460 }

Callers

nothing calls this directly

Calls 9

BuildIndexMethod · 0.95
NewBookFunction · 0.92
NewElasticSearchClientFunction · 0.92
JsonResultMethod · 0.80
BaseUrlMethod · 0.80
GetSeoByPageMethod · 0.80
FindByFieldFirstMethod · 0.45
CountMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected