Esempio n. 1
0
func CreateNews(input *duoerlapi.NewsInput) (originInput *duoerlapi.NewsInput, err error) {
	originInput = input

	newsId, err := utils.ToObjectId(input.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brandId, err := utils.ToObjectId(input.BrandId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	authorId, err := utils.ToObjectId(input.AuthorId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	dbNews := &news.News{
		Id:      newsId,
		BrandId: brandId,
		Article: *articles.NewArticle(input.Title, input.Content, authorId),
	}

	if err = dbNews.Save(); err != nil {
		utils.PrintStackAndError(err)
		return
	}

	return
}
Esempio n. 2
0
func CreateNote(input *duoerlapi.NoteInput) (originInput *duoerlapi.NoteInput, err error) {
	originInput = input

	noteId, err := utils.ToObjectId(input.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	authorId, err := utils.ToObjectId(input.AuthorId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	note := &notes.Note{
		Id:      noteId,
		Article: *articles.NewArticle(input.Title, input.Content, authorId),
	}

	if err = note.Save(); err != nil {
		utils.PrintStackAndError(err)
		return
	}

	return
}