Exemplo n.º 1
0
func (this *NoteService) AddNoteAndContentApi(note info.Note, noteContent info.Note, myUserId bson.ObjectId) info.Note {
	if note.NoteId.Hex() == "" {
		noteId := bson.NewObjectId()
		note.NoteId = noteId
	}
	noteContent.NoteId = note.NoteId
	if note.UserId != myUserId {
		note = this.AddSharedNote(note, myUserId)
	} else {
		note = this.AddNote(note, true)
	}
	if note.NoteId != "" {
		this.AddNoteContent(noteContent)
	}
	return note
}
Exemplo n.º 2
0
func (this *NoteService) AddNote(note info.Note, fromApi bool) info.Note {
	if note.NoteId.Hex() == "" {
		noteId := bson.NewObjectId()
		note.NoteId = noteId
	}
	note.CreatedTime = time.Now()
	note.UpdatedTime = note.CreatedTime
	note.IsTrash = false
	note.UpdatedUserId = note.UserId
	note.UrlTitle = GetUrTitle(note.UserId.Hex(), note.Title, "note")
	note.Usn = userService.IncrUsn(note.UserId.Hex())

	notebookId := note.NotebookId.Hex()

	// api会传IsBlog, web不会传
	if !fromApi {
		// 设为blog
		note.IsBlog = notebookService.IsBlog(notebookId)
	}
	//	if note.IsBlog {
	note.PublicTime = note.UpdatedTime
	//	}

	db.Insert(db.Notes, note)

	// tag1
	tagService.AddTags(note.UserId.Hex(), note.Tags)

	// recount notebooks' notes number
	notebookService.ReCountNotebookNumberNotes(notebookId)

	return note
}