models

package
v0.0.0-...-9f5c386 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDB

func GetDB() *gorm.DB

func NewLog

func NewLog(log *Log) error

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 Comment

type Comment struct {
	ID        int       `gorm:"primaryKey" json:"id"`
	ArticleID int       `json:"article_id"`
	UserID    int       `json:"user_id"`
	Text      string    `gorm:"type:text" json:"text"`
	UpdatedAt time.Time `json:"updated_at"`
	CreatedAt time.Time `json:"created_at"`
}

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

func GetAllLogFromUserID(userId int) []Log

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 NewUserModel(db *gorm.DB) *UserModel

func (*UserModel) CreateUser

func (u *UserModel) CreateUser(user *User) error

func (*UserModel) GetUserByID

func (u *UserModel) GetUserByID(id int) (User, error)

func (*UserModel) GetUserEmail

func (u *UserModel) GetUserEmail(email string) (User, error)

func (*UserModel) GetUserUsername

func (u *UserModel) GetUserUsername(username string) (User, error)

Jump to

Keyboard shortcuts

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