Documentation
¶
Index ¶
- func GetDB() *gorm.DB
- func NewLog(log *Log) error
- type Article
- type ArticleModel
- func (a *ArticleModel) CreateArticle(article *Article) error
- func (a *ArticleModel) CreateCategory(category *Category) error
- func (a *ArticleModel) GetAllCategory() []Category
- func (a *ArticleModel) GetArticleBySlugAndUsername(slug string, userId int) (Article, error)
- func (a *ArticleModel) GetArticleWithFilter(field Article, offset, limit int, order clause.OrderByColumn, q string) []Article
- func (a *ArticleModel) GetCategoryByID(id int) (Category, error)
- func (a *ArticleModel) GetCategoryBySlug(slug string) (Category, error)
- type Category
- type Comment
- type CommentModel
- type Log
- type StatusArticle
- type User
- type UserModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Article ¶
type Article struct {
ID int `gorm:"primaryKey" json:"id"`
UserID int `json:"user_id"`
CategoryID int `json:"category_id"`
Title string `gorm:"size:255" json:"title"`
Slug string `gorm:"size:255;unique" json:"slug"`
Content string `gorm:"type:text" json:"content"`
Status StatusArticle `gorm:"size:9;default:DRAFTED" json:"status"`
Views int64 `gorm:"default:0" json:"views"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
Comments []Comment `gorm:"foreignKey:ArticleID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"comments"`
}
type ArticleModel ¶
type ArticleModel struct {
// contains filtered or unexported fields
}
func NewArticleModel ¶
func NewArticleModel(db *gorm.DB) ArticleModel
func (*ArticleModel) CreateArticle ¶
func (a *ArticleModel) CreateArticle(article *Article) error
func (*ArticleModel) CreateCategory ¶
func (a *ArticleModel) CreateCategory(category *Category) error
func (*ArticleModel) GetAllCategory ¶
func (a *ArticleModel) GetAllCategory() []Category
func (*ArticleModel) GetArticleBySlugAndUsername ¶
func (a *ArticleModel) GetArticleBySlugAndUsername(slug string, userId int) (Article, error)
func (*ArticleModel) GetArticleWithFilter ¶
func (a *ArticleModel) GetArticleWithFilter(field Article, offset, limit int, order clause.OrderByColumn, q string) []Article
func (*ArticleModel) GetCategoryByID ¶
func (a *ArticleModel) GetCategoryByID(id int) (Category, error)
func (*ArticleModel) GetCategoryBySlug ¶
func (a *ArticleModel) GetCategoryBySlug(slug string) (Category, error)
type Category ¶
type Category struct {
ID int `gorm:"primaryKey" json:"id"`
Title string `gorm:"size:50;unique" json:"title"`
Slug string `gorm:"size:60;unique" json:"slug"`
Description string `gorm:"type:text" json:"description"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
Articles []*Article `gorm:"foreignKey:CategoryID" json:"articles"`
}
type CommentModel ¶
type CommentModel struct {
// contains filtered or unexported fields
}
func NewCommentModel ¶
func NewCommentModel(db *gorm.DB) CommentModel
func (*CommentModel) CreateComment ¶
func (c *CommentModel) CreateComment(comment *Comment) error
func (*CommentModel) GetCommentByArticleID ¶
func (c *CommentModel) GetCommentByArticleID(articleId int) []Comment
func (*CommentModel) GetCommentByID ¶
func (c *CommentModel) GetCommentByID(id int) (Comment, error)
func (*CommentModel) GetCommentByUserID ¶
func (c *CommentModel) GetCommentByUserID(userId int) []Comment
type Log ¶
type Log struct {
ID int `gorm:"primaryKey" json:"id"`
UserID int `json:"user_id,omitempty"`
Title string `json:"title"`
Description string `json:"description"`
Url string `json:"url"`
ViewedAt *time.Time `json:"viewed_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
}
func GetAllLogFromUserID ¶
type StatusArticle ¶
type StatusArticle string
const ( PUBLISHED StatusArticle = "PUBLISHED" DRAFTED StatusArticle = "DRAFTED" )
type User ¶
type User struct {
ID int `gorm:"primaryKey" json:"id"`
FirstName string `gorm:"size:50" json:"first_name"`
LastName string `gorm:"size:50" json:"last_name"`
Username string `gorm:"size:50;unique" json:"username"`
Email string `gorm:"size:50;unique" json:"email"`
Avatar *string `gorm:"size:255" json:"avatar"`
Password string `gorm:"size:128" json:"-"`
IsActive bool `gorm:"default:false" json:"is_active"`
IsAdmin bool `gorm:"default:false" json:"is_admin"`
UpdatedAt time.Time `json:"updated_at"`
DateJoined time.Time `gorm:"autoCreateTime" json:"date_joined"`
Articles []Article `gorm:"foreignKey:UserID" json:"articles"`
Comments []Comment `gorm:"foreignKey:UserID" json:"comments"`
}
type UserModel ¶
type UserModel struct {
// contains filtered or unexported fields
}
func NewUserModel ¶
func (*UserModel) CreateUser ¶
Click to show internal directories.
Click to hide internal directories.