diff --git a/controllers/BlogController.go b/controllers/BlogController.go index ab4b113..658541f 100644 --- a/controllers/BlogController.go +++ b/controllers/BlogController.go @@ -41,7 +41,7 @@ func (this *BlogController) Get() { id, _ := strconv.ParseInt(idStr, 10, 64) blog, err := service.GetBlog(id) if err != nil { - this.Redirect("/500",302) + this.Redirect("/500", 302) return } this.Data["Blog"] = blog @@ -53,6 +53,39 @@ func (this *BlogController) Get() { return } +func (this *BlogController) Del() { + uid := this.GetSession("userid") + if uid == nil { + this.Data["json"] = models.ReurnError(401, "") + this.ServeJSON() + return + } + idStr := this.Ctx.Input.Param(":id") + id, _ := strconv.ParseInt(idStr, 10, 64) + blog, err := service.GetBlog(id) + if err != nil { + this.Data["json"] = models.ReurnError(500, "") + this.ServeJSON() + return + } + if blog.UserId != uid.(int64) { + this.Data["json"] = models.ReurnError(503, "") + this.ServeJSON() + return + } + blog.Delflag = 1 + err = service.DelBlog(blog) + if err!=nil { + this.Data["json"] = models.ReurnError(500, "") + this.ServeJSON() + return + } + this.Data["json"] = models.ReurnSuccess("") + this.ServeJSON() + service.CountBlog(uid.(int64)) + return +} + func (this *BlogController) New() { uid := this.GetSession("userid") if uid == nil { diff --git a/controllers/NoteController.go b/controllers/NoteController.go index bb89916..1e52f17 100644 --- a/controllers/NoteController.go +++ b/controllers/NoteController.go @@ -16,7 +16,7 @@ func (this *NoteController) Save() { title := this.GetString("title") uid := this.GetSession("userid") if uid == nil { - this.Data["json"] = models.ReurnError(401,"保存失败") + this.Data["json"] = models.ReurnError(401, "保存失败") this.ServeJSON() return } @@ -25,7 +25,7 @@ func (this *NoteController) Save() { if err == nil { this.Data["json"] = note } else { - this.Data["json"] = models.ReurnError(500,"保存失败") + this.Data["json"] = models.ReurnError(500, "保存失败") } this.ServeJSON() return @@ -35,20 +35,20 @@ func (this *NoteController) Edit() { noteHtml := this.GetString("noteHtml") id, _ := strconv.ParseInt(idStr, 10, 64) uid := this.GetSession("userid") - if uid == nil{ + if uid == nil { this.Data["json"] = models.ReurnError(401, "") this.ServeJSON() return } - note := &models.Note{Id:id} + note := &models.Note{Id: id} err1 := service.GetNote(note) if err1 != nil { - this.Data["json"] = models.ReurnError(500,"保存失败") + this.Data["json"] = models.ReurnError(500, "保存失败") this.ServeJSON() return } if uid != note.UserId { - this.Data["json"] = models.ReurnError(403,"") + this.Data["json"] = models.ReurnError(403, "") this.ServeJSON() return } @@ -57,7 +57,7 @@ func (this *NoteController) Edit() { if err == nil { this.Data["json"] = models.ReurnSuccess("") } else { - this.Data["json"] = models.ReurnError(500,"保存失败") + this.Data["json"] = models.ReurnError(500, "保存失败") } this.ServeJSON() return @@ -66,7 +66,7 @@ func (this *NoteController) Edit() { func (this *NoteController) SaveNoteColl() { title := this.GetString("title") uid := this.GetSession("userid") - if uid == nil{ + if uid == nil { this.Data["json"] = models.ReurnError(401, "") this.ServeJSON() return @@ -74,9 +74,28 @@ func (this *NoteController) SaveNoteColl() { note := &models.NoteColl{Title: title, UserId: uid.(int64)} err := service.SaveNoteColl(note) if err == nil { - this.Data["json"] = note + this.Data["json"] = models.ReurnSuccess("") } else { - this.Data["json"] = models.ReurnError(500,"保存失败") + this.Data["json"] = models.ReurnError(500, "保存失败") + } + this.ServeJSON() + return +} + +func (this *NoteController) EditNoteColl() { + title := this.GetString("title") + id, _ := this.GetInt64("id") + uid := this.GetSession("userid") + if uid == nil { + this.Data["json"] = models.ReurnError(401, "") + this.ServeJSON() + return + } + err := service.EditNoteColl(title, id, uid.(int64)) + if err == nil { + this.Data["json"] = models.ReurnSuccess("") + } else { + this.Data["json"] = models.ReurnError(500, "保存失败") } this.ServeJSON() return @@ -84,7 +103,7 @@ func (this *NoteController) SaveNoteColl() { func (this *NoteController) Get() { uid := this.GetSession("userid") - if uid == nil{ + if uid == nil { this.Data["json"] = models.ReurnError(401, "") this.ServeJSON() return @@ -104,9 +123,28 @@ func (this *NoteController) Get() { this.ServeJSON() return } +func (this *NoteController) DelNoteColl() { + uid := this.GetSession("userid") + if uid == nil { + this.Data["json"] = models.ReurnError(401, "") + this.ServeJSON() + return + } + idStr := this.Ctx.Input.Param(":id") + id, _ := strconv.ParseInt(idStr, 10, 64) + err := service.DelNoteColl(id, uid.(int64)) + if err != nil { + this.Data["json"] = models.ReurnError(500, "") + } else { + this.Data["json"] = models.ReurnSuccess("") + } + this.ServeJSON() + return +} + func (this *NoteController) Delete() { uid := this.GetSession("userid") - if uid == nil{ + if uid == nil { this.Data["json"] = models.ReurnError(401, "") this.ServeJSON() return @@ -116,7 +154,7 @@ func (this *NoteController) Delete() { note := &models.Note{Id: id} err := service.GetNote(note) if err != nil { - this.Data["json"] = models.ReurnError(500,"") + this.Data["json"] = models.ReurnError(500, "") this.ServeJSON() return } @@ -127,7 +165,7 @@ func (this *NoteController) Delete() { } err = service.DelNote(note) if err != nil { - this.Data["json"] = models.ReurnError(500,"") + this.Data["json"] = models.ReurnError(500, "") this.ServeJSON() return } diff --git a/controllers/UserController.go b/controllers/UserController.go index d4ed0c2..0eda188 100644 --- a/controllers/UserController.go +++ b/controllers/UserController.go @@ -48,6 +48,8 @@ func (this *UserController) PersonBlog() { return } } + this.Data["NickName"] = this.GetSession("nickname") + this.Data["IsLogin"] = this.GetSession("nickname") != nil this.Data["Page"] = page this.Data["IsMeBlog"] = true this.Data["Flag"] = 0 @@ -85,6 +87,8 @@ func (this *UserController) PersonNote() { return } } + this.Data["NickName"] = this.GetSession("nickname") + this.Data["IsLogin"] = this.GetSession("nickname") != nil this.Data["Note"] = notColl this.Data["IsMeNote"] = true this.Data["User"] = user diff --git a/data/beeblog.db b/data/beeblog.db index 18c5617..3068f8f 100644 Binary files a/data/beeblog.db and b/data/beeblog.db differ diff --git a/routers/BlogRouter.go b/routers/BlogRouter.go index e53878b..4d1b206 100644 --- a/routers/BlogRouter.go +++ b/routers/BlogRouter.go @@ -8,6 +8,7 @@ import ( func init() { beego.Router("/blog/new", &controllers.BlogController{}, "post:Save") beego.Router("/blog/:id([0-9]+)", &controllers.BlogController{}, "get:Get") + beego.Router("/blog/del/:id([0-9]+)", &controllers.BlogController{}, "post:Del") beego.Router("/blogs", &controllers.BlogController{}, "get:BlogsPage") beego.Router("/blog/new", &controllers.BlogController{}, "get:New") beego.Router("/blog1", &controllers.BlogController{}, "get:Blog1") diff --git a/routers/NoteRouter.go b/routers/NoteRouter.go index aea4e35..41646ab 100644 --- a/routers/NoteRouter.go +++ b/routers/NoteRouter.go @@ -9,7 +9,9 @@ func init() { beego.Router("/note/:id([0-9]+)", &controllers.NoteController{}, "get:Get") beego.Router("/note", &controllers.NoteController{}, "get:Note") beego.Router("/notecoll/save", &controllers.NoteController{}, "post:SaveNoteColl") + beego.Router("/notecoll/edit", &controllers.NoteController{}, "post:EditNoteColl") beego.Router("/note/save", &controllers.NoteController{}, "post:Save") beego.Router("/note/edit/:id([0-9]+)", &controllers.NoteController{}, "post:Edit") beego.Router("/note/del/:id([0-9]+)", &controllers.NoteController{}, "post:Delete") + beego.Router("/notecol/del/:id([0-9]+)", &controllers.NoteController{}, "post:DelNoteColl") } diff --git a/service/BlogService.go b/service/BlogService.go index 2abb20b..37b2f9a 100644 --- a/service/BlogService.go +++ b/service/BlogService.go @@ -64,6 +64,12 @@ func GetBlog(id int64) (*models.Blog, error) { return blog, nil } +func DelBlog(blog *models.Blog) error { + o := orm.NewOrm() + _, err := o.Update(blog, "Delflag") + return err +} + func FindBlogs(num int, size int, cat int64, flag int) (*utils.Page, error) { page, err := count(num, size, cat) if err != nil { diff --git a/service/NoteService.go b/service/NoteService.go index 736f293..7235758 100644 --- a/service/NoteService.go +++ b/service/NoteService.go @@ -3,6 +3,8 @@ package service import ( "beeblog/models" "github.com/astaxie/beego/orm" + "errors" + "fmt" ) type NoteService struct { @@ -49,7 +51,7 @@ func CountNote(pid int64) (int64, error) { o := orm.NewOrm() totalCount, err := o.QueryTable(&models.Note{}).Filter("Pid", pid).Count() if err != nil { - return 0,err + return 0, err } return totalCount, nil } @@ -63,6 +65,21 @@ func SaveNoteColl(note *models.NoteColl) error { return err } +func EditNoteColl(title string, id int64, uid int64) error { + o := orm.NewOrm() + noteColl := &models.NoteColl{Id: id} + + if err := o.Read(noteColl); err != nil { + return err + } + if noteColl.UserId != uid { + return errors.New("403") + } + noteColl.Title = title + _, err := o.Update(noteColl, "Title") + return err +} + func GetNoteColl(uid int64) ([]*models.NoteColl, error) { var notes []*models.NoteColl o := orm.NewOrm() @@ -70,3 +87,22 @@ func GetNoteColl(uid int64) ([]*models.NoteColl, error) { _, err := qs.Filter("UserId", uid).All(¬es) return notes, err } + +func DelNoteColl(id int64, uid int64) error { + o := orm.NewOrm() + noteColl := &models.NoteColl{Id: id} + + if err := o.Read(noteColl); err != nil { + fmt.Println(err) + return err + } + if uid != noteColl.UserId { + return errors.New("403") + } + _, err := o.QueryTable(models.Note{}).Filter("Pid", id).Delete() + fmt.Println(err) + if err == nil { + _, err = o.Delete(noteColl) + } + return err +} diff --git a/static/css/me.css b/static/css/me.css index e7746db..7078d7b 100644 --- a/static/css/me.css +++ b/static/css/me.css @@ -9,7 +9,7 @@ .me-menu p { cursor: pointer; - font-size: 18px; + font-size: 15px; color: #555; margin: 0; height: 32px; diff --git a/views/T.me.tpl b/views/T.me.tpl index d20ef6c..c5b39e8 100644 --- a/views/T.me.tpl +++ b/views/T.me.tpl @@ -27,7 +27,7 @@

我的博客

-

我的笔记

+

笔记文件夹

我的收藏

我的资料

diff --git a/views/note.html b/views/note.html index 741eea2..be66fab 100644 --- a/views/note.html +++ b/views/note.html @@ -48,7 +48,7 @@ @@ -216,31 +216,6 @@ }); }) - - $("#newNoteColl").click(function () { - layer.prompt({title: '请输入文件夹名称'}, function (val, index) { - if (val.trim().length < 3) { - layer.msg('文件夹名称最低三个字哦', function () { - }); - layer.close(index); - return - } - $.post('/notecoll/save', { - title: val.trim() - }, - function (data) { - if (!data.Status) { - parent.layer.msg("保存成功", {icon: 6}); - var child = '
  • \n' + - ' ' + data.Titled + '\n' + - ' \n' + - '
  • ' - $(".cd-navigation").append(child) - layer.close(index); - } - }, 'json') - }); - }) }) \ No newline at end of file diff --git a/views/ublogs.html b/views/ublogs.html index 33af7ab..443ca59 100644 --- a/views/ublogs.html +++ b/views/ublogs.html @@ -15,12 +15,15 @@
  • 管理博客
  • {{range .Page.List}} -

    {{.Title}}

    - 发布时间:{{.Ctime.Format "2006/01/02"}} - 浏览量:{{.Browses}} - 删除 - 编辑 +

    {{.Title}}

    +
    + 发布时间:{{.Ctime.Format "2006/01/02"}} + 浏览量:{{.Browses}} + 删除 + 编辑 +

    {{end}} @@ -51,4 +54,27 @@ + \ No newline at end of file diff --git a/views/unote.html b/views/unote.html index 4a3a3d6..ba62b9c 100644 --- a/views/unote.html +++ b/views/unote.html @@ -13,6 +13,7 @@
  • 个人中心
  • 笔记文件夹
  • 管理文件夹
  • + @@ -20,8 +21,10 @@

    {{.Title}}{{.Count}}

    - 删除 - 编辑 + 删除 + 重命名

    @@ -34,4 +37,78 @@ + \ No newline at end of file