github.com/ngocphuongnb/tetua@v0.0.7-alpha/app/entities/page.go (about)

     1  package entities
     2  
     3  import (
     4  	"fmt"
     5  	"net/url"
     6  	"time"
     7  
     8  	"github.com/ngocphuongnb/tetua/app/utils"
     9  )
    10  
    11  // Page is the model entity for the Page schema.
    12  type Page struct {
    13  	ID              int        `json:"id,omitempty"`
    14  	Name            string     `json:"name,omitempty" validate:"max=255"`
    15  	Slug            string     `json:"slug,omitempty" validate:"max=255"`
    16  	Content         string     `json:"content,omitempty" validate:"required"`
    17  	ContentHTML     string     `json:"content_html,omitempty"`
    18  	Draft           bool       `json:"draft,omitempty"`
    19  	FeaturedImageID int        `json:"featured_image_id,omitempty"`
    20  	FeaturedImage   *File      `json:"featured_image,omitempty"`
    21  	CreatedAt       *time.Time `json:"created_at,omitempty"`
    22  	UpdatedAt       *time.Time `json:"updated_at,omitempty"`
    23  	DeletedAt       *time.Time `json:"deleted_at,omitempty"`
    24  }
    25  
    26  type PageFilter struct {
    27  	*Filter
    28  	Publish string `form:"publish_type" json:"publish_type"` // publish_type = all, published, draft
    29  }
    30  
    31  func (p *Page) Url() string {
    32  	return utils.Url(fmt.Sprintf("/%s.html", p.Slug))
    33  }
    34  
    35  func (p *PageFilter) Base() string {
    36  	q := url.Values{}
    37  	if !utils.SliceContains(p.IgnoreUrlParams, "search") && p.Search != "" {
    38  		q.Add("q", p.Search)
    39  	}
    40  	if !utils.SliceContains(p.IgnoreUrlParams, "publish") && p.Publish != "" {
    41  		q.Add("publish", p.Publish)
    42  	}
    43  
    44  	if queryString := q.Encode(); queryString != "" {
    45  		return p.FilterBaseUrl() + "?" + q.Encode()
    46  	}
    47  
    48  	return p.FilterBaseUrl()
    49  }