post

package
v0.0.0-...-b7dcdf6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TableName = "post"
	TypeText  = "text"
	TypeLink  = "link"

	CategoryMusic       = "music"
	CategoryFunny       = "funny"
	CategoryVideos      = "videos"
	CategoryProgramming = "programming"
	CategoryNews        = "news"
	CategoryFashion     = "fashion"
)
View Source
const MaxLIstLimit = 1000

Variables

View Source
var Types []interface{} = []interface{}{
	TypeText,
	TypeLink,
}

Functions

This section is empty.

Types

type IRepository

type IRepository interface {
	// Get returns the album with the specified album ID.
	Get(ctx context.Context, id uint) (*Post, error)
	First(ctx context.Context, user *Post) (*Post, error)
	// Count returns the number of albums.
	//Count(ctx context.Context) (uint, error)
	// Query returns the list of albums with the given offset and limit.
	Query(ctx context.Context, offset, limit uint) ([]Post, error)
	SetDefaultConditions(conditions map[string]interface{})
	// Create saves a new album in the storage.
	Create(ctx context.Context, entity *Post) error
	// Update updates the album with given ID in the storage.
	Update(ctx context.Context, entity *Post) error
	// Delete removes the album with given ID from the storage.
	Delete(ctx context.Context, id uint) error
}

IRepository encapsulates the logic to access albums from the data source.

type IService

type IService interface {
	NewEntity() *Post
	Get(ctx context.Context, id uint) (*Post, error)
	First(ctx context.Context, user *Post) (*Post, error)
	Query(ctx context.Context, offset, limit uint) ([]Post, error)
	List(ctx context.Context) ([]Post, error)
	//Count(ctx context.Context) (uint, error)
	Create(ctx context.Context, entity *Post) error
	ViewsIncr(ctx context.Context, entity *Post) error
	//Update(ctx context.Context, entity *Post) error
	Delete(ctx context.Context, id uint) error
}

IService encapsulates usecase logic for user.

func NewService

func NewService(repo IRepository, logger log.ILogger) IService

NewService creates a new service.

type Post

type Post struct {
	ID       uint   `gorm:"PRIMARY_KEY" json:"id"`
	Score    int    `json:"score"`
	Views    uint   `json:"views"`
	Title    string `gorm:"type:varchar(100)" json:"title"`
	Type     string `gorm:"type:varchar(100)" json:"type"`
	Category string `gorm:"type:varchar(100)" json:"category"`
	Text     string `json:"text,omitempty"`
	Link     string `gorm:"type:varchar(100)" json:"link,omitempty"`

	UserID uint      `sql:"type:int REFERENCES \"user\"(id)" json:"userId"`
	User   user.User `gorm:"FOREIGNKEY:UserID;association_autoupdate:false" json:"author"`

	Votes    []vote.Vote       `gorm:"FOREIGNKEY:PostID" json:"votes"`
	Comments []comment.Comment `gorm:"FOREIGNKEY:PostID" json:"comments"`

	CreatedAt time.Time  `json:"created"`
	UpdatedAt time.Time  `json:"updated"`
	DeletedAt *time.Time `gorm:"INDEX" json:"deleted"`
}

Post is the user entity

func New

func New() *Post

New func is a constructor for the Post

func (Post) TableName

func (e Post) TableName() string

func (Post) Validate

func (e Post) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL