API, Tag
This commit is contained in:
app
controllers
db
info
init.golea
service
AttachService.goAuthService.goBlogService.goConfigService.goFileService.goNoteImageService.goNoteService.goNotebookService.goSessionService.goShareService.goTagService.goTrashService.goUpgradeService.goUserService.go
views
public
blog
css
js
themes
README.html
backup
default
archive.htmlcate.htmlcomment.htmlfooter.htmlheader.htmlhighlight.html
images
index.htmlnoise.pngpage.htmlpaging.htmlsearch.htmlsingle.htmlstyle.csstag_posts.htmltags.htmltheme.jsonview.htmlview.jselegant
archive.htmlcate.htmlcomment.htmlfooter.htmlheader.htmlhighlight.html
images
index.htmlpage.htmlpaging.htmlsearch.htmlsingle.htmlstyle.csstag_posts.htmltags.htmltheme.jsonview.htmlview.jsnav_fixed
default
archive.htmlcate.htmlfooter.htmlheader.htmlindex.htmlpaging.htmlpost.htmlpost_abstract.htmlsearch.htmlshare_comment.htmlsingle.htmlstyle.csstag_posts.htmltags.htmltheme.json
elegant
archive.htmlcate.htmlfooter.htmlheader.htmlindex.htmlpaging.htmlpost.htmlpost_abstract.htmlsearch.htmlshare_comment.htmlsingle.htmltag_posts.htmltags.htmltheme.json
nav_fixed
css
blog
bootstrap.csscss
font-awesome-4.0.3
css
fonts
FontAwesome.otffontawesome-webfont.eotfontawesome-webfont.svgfontawesome-webfont.ttffontawesome-webfont.woff
less
bordered-pulled.lesscore.lessfixed-width.lessfont-awesome.lessicons.lesslarger.lesslist.lessmixins.lesspath.lessrotated-flipped.lessspinning.lessstacked.lessvariables.less
scss
theme
dist
themes
js
libs
ace
ace-modify.txtace.js
ck
ext-beautify-min.jsext-chromevox-min.jsext-elastic_tabstops_lite-min.jsext-emmet-min.jsext-error_marker-min.jsext-keybinding_menu-min.jsext-language_tools-min.jsext-linking-min.jsext-modelist-min.jsext-old_ie-min.jsext-settings_menu-min.jsext-spellcheck-min.jsext-split-min.jsext-static_highlight-min.jsext-statusbar-min.jsext-textarea-min.jsext-themelist-min.jsext-whitespace-min.jskeybinding-emacs-min.jsmode-abap-min.jsmode-actionscript-min.jsmode-ada-min.jsmode-apache_conf-min.jsmode-asciidoc-min.jsmode-assembly_x86-min.jsmode-autohotkey-min.jsmode-batchfile-min.jsmode-c9search-min.jsmode-cirru-min.jsmode-clojure-min.jsmode-cobol-min.jsmode-coffee-min.jsmode-coldfusion-min.jsmode-csharp-min.jsmode-css-min.jsmode-d-min.jsmode-dart-min.jsmode-diff-min.jsmode-django-min.jsmode-dot-min.jsmode-eiffel-min.jsmode-ejs-min.jsmode-erlang-min.jsmode-ftl-min.jsmode-gcode-min.jsmode-gherkin-min.jsmode-gitignore-min.jsmode-glsl-min.jsmode-golang-min.jsmode-groovy-min.jsmode-haml-min.jsmode-handlebars-min.js
ext-beautify.jsext-chromevox.jsext-elastic_tabstops_lite.jsext-emmet.jsext-error_marker.jsext-keybinding_menu.jsext-language_tools.jsext-linking.jsext-modelist.jsext-old_ie.jsext-searchbox.jsext-settings_menu.jsext-spellcheck.jsext-split.jsext-static_highlight.jsext-statusbar.jsext-textarea.jsext-themelist.jsext-whitespace.jskeybinding-emacs.jskeybinding-vim.jsmode-abap.jsmode-abc.jsmode-actionscript.jsmode-ada.jsmode-apache_conf.jsmode-applescript.jsmode-asciidoc.jsmode-assembly_x86.jsmode-autohotkey.jsmode-batchfile.jsmode-c9search.jsmode-c_cpp.jsmode-cirru.jsmode-clojure.jsmode-cobol.jsmode-coffee.jsmode-coldfusion.jsmode-csharp.jsmode-css.jsmode-curly.jsmode-d.jsmode-dart.jsmode-diff.jsmode-django.jsmode-dockerfile.jsmode-dot.jsmode-eiffel.jsmode-ejs.jsmode-elixir.jsmode-elm.jsmode-erlang.jsmode-forth.jsmode-ftl.jsmode-gcode.jsmode-gherkin.jsmode-gitignore.jsmode-glsl.jsmode-golang.jsmode-groovy.jsmode-haml.jsmode-handlebars.jsmode-haskell.jsmode-haxe.jsmode-html.jsmode-html_ruby.jsmode-ini.jsmode-io.jsmode-jack.jsmode-jade.jsmode-java.jsmode-javascript.jsmode-json.jsmode-jsoniq.jsmode-jsp.jsmode-jsx.jsmode-julia.jsmode-latex.jsmode-lean.jsmode-less.jsmode-liquid.jsmode-lisp.jsmode-livescript.jsmode-logiql.jsmode-lsl.jsmode-lua.jsmode-luapage.jsmode-lucene.jsmode-makefile.jsmode-markdown.jsmode-mask.jsmode-matlab.jsmode-mel.jsmode-mushcode.jsmode-mysql.jsmode-nix.jsmode-objectivec.jsmode-ocaml.jsmode-pascal.jsmode-perl.jsmode-pgsql.jsmode-php.jsmode-plain_text.jsmode-powershell.jsmode-praat.jsmode-prolog.jsmode-properties.jsmode-protobuf.jsmode-python.jsmode-r.jsmode-rdoc.jsmode-rhtml.jsmode-ruby.jsmode-rust.jsmode-sass.jsmode-scad.jsmode-scala.jsmode-scheme.jsmode-scss.jsmode-sh.jsmode-sjs.jsmode-smarty.jsmode-snippets.jsmode-soy_template.jsmode-space.jsmode-sql.jsmode-stylus.jsmode-svg.jsmode-tcl.jsmode-tex.jsmode-text.jsmode-textile.jsmode-toml.jsmode-twig.jsmode-typescript.jsmode-vala.jsmode-vbscript.jsmode-velocity.jsmode-verilog.jsmode-vhdl.jsmode-xml.jsmode-xquery.jsmode-yaml.jssnippets
abap.jsabc.jsactionscript.jsada.jsapache_conf.jsapplescript.jsasciidoc.jsassembly_x86.jsautohotkey.jsbatchfile.jsc9search.jsc_cpp.jscirru.jsclojure.jscobol.jscoffee.jscoldfusion.jscsharp.jscss.jscurly.jsd.jsdart.jsdiff.jsdjango.jsdockerfile.jsdot.jseiffel.jsejs.jselixir.jselm.jserlang.jsforth.jsftl.jsgcode.jsgherkin.jsgitignore.jsglsl.jsgolang.jsgroovy.jshaml.jshandlebars.jshaskell.jshaxe.jshtml.jshtml_ruby.jsini.jsio.jsjack.jsjade.jsjava.jsjavascript.jsjson.jsjsoniq.jsjsp.jsjsx.jsjulia.jslatex.jslean.jsless.jsliquid.jslisp.jslivescript.jslogiql.jslsl.jslua.jsluapage.jslucene.jsmakefile.jsmarkdown.jsmask.jsmatlab.jsmel.jsmushcode.jsmysql.jsnix.jsobjectivec.jsocaml.jspascal.jsperl.jspgsql.jsphp.jsplain_text.jspowershell.jspraat.jsprolog.jsproperties.jsprotobuf.jspython.jsr.jsrdoc.jsrhtml.jsruby.jsrust.jssass.jsscad.jsscala.jsscheme.jsscss.jssh.jssjs.jssmarty.jssnippets.jssoy_template.jsspace.jssql.jsstylus.jssvg.jstcl.jstex.jstext.jstextile.jstoml.jstwig.jstypescript.jsvala.jsvbscript.jsvelocity.jsverilog.jsvhdl.jsxml.jsxquery.jsyaml.js
theme-ambiance.jstheme-chaos.jstheme-chrome.jstheme-clouds.jstheme-clouds_midnight.jstheme-cobalt.jstheme-crimson_editor.jstheme-dawn.jstheme-dreamweaver.jstheme-eclipse.jstheme-github.jstheme-idle_fingers.jstheme-katzenmilch.jstheme-kr_theme.jstheme-kuroir.jstheme-merbivore.jstheme-merbivore_soft.jstheme-mono_industrial.jstheme-monokai.jstheme-pastel_on_dark.jstheme-solarized_dark.jstheme-solarized_light.jstheme-terminal.jstheme-textmate.jstheme-tomorrow.jstheme-tomorrow_night.jstheme-tomorrow_night_blue.jstheme-tomorrow_night_bright.jstheme-tomorrow_night_eighties.jstheme-twilight.jstheme-vibrant_ink.jstheme-xcode.jsworker-coffee.jsworker-css.jsworker-html.jsworker-javascript.jsworker-json.jsworker-lua.jsworker-php.jsworker-xml.jsworker-xquery.jstinymce
plugins
leaui_image
public
paste
spellchecker
table
@ -111,12 +111,24 @@ func (this *NotebookService) GetNotebookByUserIdAndUrlTitle(userId, notebookIdOr
|
||||
return notebook
|
||||
}
|
||||
|
||||
// 同步的方法
|
||||
func (this *NotebookService) GeSyncNotebooks(userId string, afterUsn, maxEntry int) ([]info.Notebook) {
|
||||
notebooks := []info.Notebook{}
|
||||
q := db.Notebooks.Find(bson.M{"UserId": bson.ObjectIdHex(userId), "Usn": bson.M{"$gt": afterUsn}});
|
||||
q.Sort("Usn").Limit(maxEntry).All(¬ebooks)
|
||||
return notebooks
|
||||
}
|
||||
|
||||
// 得到用户下所有的notebook
|
||||
// 排序好之后返回
|
||||
// [ok]
|
||||
func (this *NotebookService) GetNotebooks(userId string) info.SubNotebooks {
|
||||
userNotebooks := []info.Notebook{}
|
||||
db.Notebooks.Find(bson.M{"UserId": bson.ObjectIdHex(userId)}).All(&userNotebooks)
|
||||
orQ := []bson.M{
|
||||
bson.M{"IsDeleted": false},
|
||||
bson.M{"IsDeleted": bson.M{"$exists": false}},
|
||||
}
|
||||
db.Notebooks.Find(bson.M{"UserId": bson.ObjectIdHex(userId), "$or": orQ}).All(&userNotebooks)
|
||||
|
||||
if len(userNotebooks) == 0 {
|
||||
return nil
|
||||
@ -141,14 +153,46 @@ func (this *NotebookService) GetNotebooksByNotebookIds(notebookIds []bson.Object
|
||||
|
||||
// 添加
|
||||
// [ok]
|
||||
func (this *NotebookService) AddNotebook(notebook info.Notebook) bool {
|
||||
func (this *NotebookService) AddNotebook(notebook info.Notebook) (bool, info.Notebook) {
|
||||
notebook.UrlTitle = GetUrTitle(notebook.UserId.Hex(), notebook.Title, "notebook")
|
||||
notebook.Usn = userService.IncrUsn(notebook.UserId.Hex())
|
||||
now := time.Now()
|
||||
notebook.CreatedTime = now
|
||||
notebook.UpdatedTime = now
|
||||
err := db.Notebooks.Insert(notebook)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return false, notebook
|
||||
}
|
||||
return true
|
||||
return true, notebook
|
||||
}
|
||||
// 更新笔记, api
|
||||
func (this *NotebookService) UpdateNotebookApi(userId, notebookId, title, parentNotebookId string, seq, usn int) (bool, string, info.Notebook) {
|
||||
if notebookId == "" {
|
||||
return false, "notebookIdNotExists", info.Notebook{}
|
||||
}
|
||||
|
||||
// 先判断usn是否和数据库的一样, 如果不一样, 则冲突, 不保存
|
||||
notebook := this.GetNotebookById(notebookId)
|
||||
// 不存在
|
||||
if notebook.NotebookId == "" {
|
||||
return false, "notExists", notebook
|
||||
} else if notebook.Usn != usn {
|
||||
return false, "conflict", notebook
|
||||
}
|
||||
notebook.Usn = userService.IncrUsn(userId);
|
||||
notebook.Title = title;
|
||||
|
||||
updates := bson.M{"Title": title, "Usn": notebook.Usn, "Seq": seq, "UpdatedTime": time.Now()};
|
||||
if(parentNotebookId != "" && bson.IsObjectIdHex(parentNotebookId)) {
|
||||
updates["ParentNotebookId"] = bson.ObjectIdHex(parentNotebookId);
|
||||
} else {
|
||||
updates["ParentNotebookId"] = "";
|
||||
}
|
||||
ok := db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, updates);
|
||||
if ok {
|
||||
return ok, "", this.GetNotebookById(notebookId)
|
||||
}
|
||||
return false, "", notebook
|
||||
}
|
||||
|
||||
// 判断是否是blog
|
||||
@ -174,19 +218,22 @@ func (this *NotebookService) UpdateNotebook(notebook info.Notebook) bool {
|
||||
// 更新笔记本标题
|
||||
// [ok]
|
||||
func (this *NotebookService) UpdateNotebookTitle(notebookId, userId, title string) bool {
|
||||
return db.UpdateByIdAndUserIdField(db.Notebooks, notebookId, userId, "Title", title)
|
||||
usn := userService.IncrUsn(userId)
|
||||
return db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, bson.M{"Title": title, "Usn": usn})
|
||||
}
|
||||
|
||||
// 更新notebook
|
||||
func (this *NotebookService) UpdateNotebook(userId, notebookId string, needUpdate bson.M) bool {
|
||||
needUpdate["UpdatedTime"] = time.Now();
|
||||
needUpdate["Usn"] = userService.IncrUsn(userId)
|
||||
return db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, needUpdate)
|
||||
}
|
||||
|
||||
// ToBlog or Not
|
||||
func (this *NotebookService) ToBlog(userId, notebookId string, isBlog bool) (bool) {
|
||||
updates := bson.M{"IsBlog": isBlog, "Usn": userService.IncrUsn(userId)}
|
||||
// 笔记本
|
||||
db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, bson.M{"IsBlog": isBlog})
|
||||
db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, updates)
|
||||
|
||||
// 更新笔记
|
||||
q := bson.M{"UserId": bson.ObjectIdHex(userId),
|
||||
@ -197,6 +244,8 @@ func (this *NotebookService) ToBlog(userId, notebookId string, isBlog bool) (boo
|
||||
} else {
|
||||
data["HasSelfDefined"] = false
|
||||
}
|
||||
// usn
|
||||
data["Usn"] = userService.IncrUsn(userId)
|
||||
db.UpdateByQMap(db.Notes, q, data)
|
||||
|
||||
// noteContents也更新, 这个就麻烦了, noteContents表没有NotebookId
|
||||
@ -227,7 +276,10 @@ func (this *NotebookService) DeleteNotebook(userId, notebookId string) (bool, st
|
||||
if db.Count(db.Notes, bson.M{"NotebookId": bson.ObjectIdHex(notebookId),
|
||||
"UserId": bson.ObjectIdHex(userId),
|
||||
"IsTrash": false}) == 0 { // 不包含trash
|
||||
return db.DeleteByIdAndUserId(db.Notebooks, notebookId, userId), ""
|
||||
// 不是真删除 1/20, 为了同步笔记本
|
||||
ok := db.UpdateByQMap(db.Notebooks, bson.M{"_id": bson.ObjectIdHex(notebookId)}, bson.M{"IsDeleted": true, "Usn": userService.IncrUsn(userId)})
|
||||
return ok, ""
|
||||
// return db.DeleteByIdAndUserId(db.Notebooks, notebookId, userId), ""
|
||||
}
|
||||
return false, "笔记本下有笔记"
|
||||
} else {
|
||||
@ -235,6 +287,18 @@ func (this *NotebookService) DeleteNotebook(userId, notebookId string) (bool, st
|
||||
}
|
||||
}
|
||||
|
||||
// API调用, 删除笔记本, 不作笔记控制
|
||||
func (this *NotebookService) DeleteNotebookForce(userId, notebookId string, usn int) (bool, string) {
|
||||
notebook := this.GetNotebookById(notebookId)
|
||||
// 不存在
|
||||
if notebook.NotebookId == "" {
|
||||
return false, "notExists"
|
||||
} else if notebook.Usn != usn {
|
||||
return false, "conflict"
|
||||
}
|
||||
return db.DeleteByIdAndUserId(db.Notebooks, notebookId, userId), ""
|
||||
}
|
||||
|
||||
// 排序
|
||||
// 传入 notebookId => Seq
|
||||
// 为什么要传入userId, 防止修改其它用户的信息 (恶意)
|
||||
@ -245,7 +309,7 @@ func (this *NotebookService) SortNotebooks(userId string, notebookId2Seqs map[st
|
||||
}
|
||||
|
||||
for notebookId, seq := range notebookId2Seqs {
|
||||
if !db.UpdateByIdAndUserIdField2(db.Notebooks, bson.ObjectIdHex(notebookId), bson.ObjectIdHex(userId), "Seq", seq) {
|
||||
if !db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, bson.M{"Seq": seq, "Usn": userService.IncrUsn(userId)}) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -253,15 +317,14 @@ func (this *NotebookService) SortNotebooks(userId string, notebookId2Seqs map[st
|
||||
return true
|
||||
}
|
||||
|
||||
// 排序和设置父
|
||||
func (this *NotebookService) DragNotebooks(userId string, curNotebookId string, parentNotebookId string, siblings []string) bool {
|
||||
userIdO := bson.ObjectIdHex(userId)
|
||||
|
||||
ok := false
|
||||
// 如果没parentNotebookId, 则parentNotebookId设空
|
||||
if(parentNotebookId == "") {
|
||||
ok = db.UpdateByIdAndUserIdField2(db.Notebooks, bson.ObjectIdHex(curNotebookId), userIdO, "ParentNotebookId", "");
|
||||
ok = db.UpdateByIdAndUserIdMap(db.Notebooks, curNotebookId, userId, bson.M{"ParentNotebookId": "", "Usn": userService.IncrUsn(userId)});
|
||||
} else {
|
||||
ok = db.UpdateByIdAndUserIdField2(db.Notebooks, bson.ObjectIdHex(curNotebookId), userIdO, "ParentNotebookId", bson.ObjectIdHex(parentNotebookId));
|
||||
ok = db.UpdateByIdAndUserIdMap(db.Notebooks, curNotebookId, userId, bson.M{"ParentNotebookId": bson.ObjectIdHex(parentNotebookId), "Usn": userService.IncrUsn(userId)});
|
||||
}
|
||||
|
||||
if !ok {
|
||||
@ -270,7 +333,7 @@ func (this *NotebookService) DragNotebooks(userId string, curNotebookId string,
|
||||
|
||||
// 排序
|
||||
for seq, notebookId := range siblings {
|
||||
if !db.UpdateByIdAndUserIdField2(db.Notebooks, bson.ObjectIdHex(notebookId), userIdO, "Seq", seq) {
|
||||
if !db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, bson.M{"Seq": seq, "Usn": userService.IncrUsn(userId)}) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -283,7 +346,7 @@ func (this *NotebookService) DragNotebooks(userId string, curNotebookId string,
|
||||
// trashService: DeleteNote (recove不用, 都统一在MoveNote里了)
|
||||
func (this *NotebookService) ReCountNotebookNumberNotes(notebookId string) bool {
|
||||
notebookIdO := bson.ObjectIdHex(notebookId)
|
||||
count := db.Count(db.Notes, bson.M{"NotebookId": notebookIdO, "IsTrash": false})
|
||||
count := db.Count(db.Notes, bson.M{"NotebookId": notebookIdO, "IsTrash": false, "IsDeleted": false})
|
||||
Log(count)
|
||||
Log(notebookId)
|
||||
return db.UpdateByQField(db.Notebooks, bson.M{"_id": notebookIdO}, "NumberNotes", count)
|
||||
|
Reference in New Issue
Block a user