// fillAndValidate tag func (model *Tag) fillAndValidate(payload Tag, isEdit bool) (err error) { if !isEdit { // new } else { model.ID = payload.ID } model.Name = strings.TrimSpace(payload.Name) model.Description = strings.TrimSpace(payload.Description) model.Slug = strings.TrimSpace(payload.Slug) if model.Slug == "" || !slug.IsSlugAscii(model.Slug) { // generate slug model.Slug = slug.Slug(model.Name) } model.Image = strings.TrimSpace(payload.Image) model.IsVisible = payload.IsVisible model.ParentID = payload.ParentID model.MetaTitle = payload.MetaTitle if model.MetaTitle == "" { model.MetaTitle = model.Name } model.MetaDescription = payload.MetaDescription if model.MetaDescription == "" { model.MetaDescription = model.Description } model.UpdatedBy = payload.UpdatedBy return }
func (model *Post) fillAndValidate(payload PostPayload, isEdit bool) (err error) { body := strings.TrimSpace(payload.Body) if !isEdit { // new // uuid model.UUID = uuid.NewV4().String() model.CreatedBy = payload.AuthorID // generate excerpt bodyLength := len(body) // get # of characters to generate excerpt // this is usually taken from settings // but we'll hard code it for now excerptChars := 200 if bodyLength < excerptChars { excerptChars = bodyLength } model.Excerpt = body[:excerptChars] } else { model.ID = payload.ID model.Excerpt = strings.TrimSpace(payload.Excerpt) } model.Title = strings.TrimSpace(payload.Title) model.Slug = strings.TrimSpace(payload.Slug) if model.Slug == "" || !slug.IsSlugAscii(model.Slug) { // generate slug model.Slug = slug.Slug(model.Title) } model.Subtitle = strings.TrimSpace(payload.Subtitle) model.Body = body model.Featured = payload.Featured model.Image = strings.TrimSpace(payload.Image) model.AuthorID = payload.AuthorID model.UpdatedBy = payload.AuthorID model.MetaTitle = strings.TrimSpace(payload.MetaTitle) model.MetaDescription = strings.TrimSpace(payload.MetaDescription) if model.Status == "published" { // parse published_at from format: MM-DD-YYYY hh:mm publishedAt, err2 := utils.ParseDate(LONGFORM, payload.PublishedAt) if err2 != nil { err = err2 return } model.PublishedAt = pq.NullTime{ Time: publishedAt, Valid: true, } } return }