models

package
v0.0.0-...-39ee276 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNewClass

func CreateNewClass(class *Class) error

func CreateNewUser

func CreateNewUser(user *User) error

func DB

func DB() *gorm.DB

Types

type Article

type Article struct {
	ID        int              `gorm:"primaryKey" json:"id"`
	UserID    int              `json:"user_id"`
	Title     string           `gorm:"size:50" json:"title"`
	Slug      string           `gorm:"size:60;uniqueIndex" json:"slug"`
	Content   string           `gorm:"type:text" json:"content"`
	Views     int              `gorm:"default:0" json:"views"`
	Status    ArticleStatus    `gorm:"default:DRAFTED" json:"status"`
	UpdatedAt time.Time        `json:"updated_at"`
	CreatedAt time.Time        `json:"created_at"`
	DeletedAt gorm.DeletedAt   `gorm:"index" json:"deleted_at"`
	Comments  []ArticleComment `gorm:"foreignKey:ArticleID" json:"comments"`
}

Article is model to implement fields in database.

type ArticleComment

type ArticleComment 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"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
}

ArticleComment

type ArticleModel

type ArticleModel struct {
	// contains filtered or unexported fields
}

ArticleModel struct to article model.

func NewArticleModel

func NewArticleModel(db *gorm.DB) *ArticleModel

NewArticleModel is function to run article model.

func (*ArticleModel) CreateNewArticle

func (a *ArticleModel) CreateNewArticle(article *Article) error

CreateNewArticle is function to create new article.

func (*ArticleModel) GetAllArticle

func (a *ArticleModel) GetAllArticle(status ArticleStatus, limit, offset int) []Article

GetAllArticle is function to get all article.

func (*ArticleModel) GetArticleBySlug

func (a *ArticleModel) GetArticleBySlug(slug string) (Article, error)

GetArticleBySlug is function to get article by given slug.

type ArticleStatus

type ArticleStatus string
const (
	PUBLISHED ArticleStatus = "PUBLISHED"
	DRAFTED   ArticleStatus = "DRAFTED"
)

type Class

type Class struct {
	ID          int             `gorm:"primaryKey" json:"id"`
	Title       string          `gorm:"size:50;unique" json:"title"`
	Slug        string          `gorm:"size:60;uniqueIndex" json:"slug"`
	Description string          `gorm:"type:text" json:"description"`
	IsActive    bool            `gorm:"default:false" json:"is_active"`
	UpdatedAt   time.Time       `json:"updated_at"`
	CreatedAt   time.Time       `json:"created_at"`
	DeletedAt   gorm.DeletedAt  `gorm:"index" json:"deleted_at"`
	Mentors     []*User         `gorm:"many2many:classes_user_mentor" json:"mentors"`
	Members     []*User         `gorm:"many2many:classes_user_member" json:"members"`
	Images      []*ClassImage   `gorm:"foreignKey:ClassID" json:"images"`
	Meetings    []*ClassMeeting `gorm:"foreignKey:ClassID" json:"meetings"`
}

Class is struct for implement class in kafekoding.

func GetAllClass

func GetAllClass(is_active bool) []Class

func GetClassBySlug

func GetClassBySlug(slug string) (Class, error)

type ClassImage

type ClassImage struct {
	ID        int            `gorm:"primaryKey" json:"id"`
	ClassID   int            `json:"class_id"`
	Image     string         `gorm:"size:255" json:"image"`
	Caption   *string        `gorm:"size:255" json:"caption"`
	UpdatedAt time.Time      `json:"updated_at"`
	CreatedAt time.Time      `json:"created_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
}

type ClassMeeting

type ClassMeeting struct {
	ID          int                      `gorm:"primaryKey" json:"id"`
	ClassID     int                      `json:"class_id"`
	Title       string                   `gorm:"size:50" json:"title"`
	Slug        string                   `gorm:"size:60;uniqueIndex" json:"slug"`
	Content     string                   `gorm:"type:text" json:"content"`
	OpenedAt    time.Time                `json:"opened_at"`
	ClosedAt    time.Time                `json:"closed_at"`
	UpdatedAt   time.Time                `json:"updated_at"`
	CreatedAt   time.Time                `json:"created_at"`
	DeletedAt   gorm.DeletedAt           `gorm:"index" json:"deleted_at"`
	Attendances []ClassMeetingAttendance `gorm:"foreignKey:MeetingID" json:"attendances"`
}

type ClassMeetingAttendance

type ClassMeetingAttendance struct {
	ID        int            `gorm:"primaryKey" json:"id"`
	MeetingID int            `json:"meeting_id"`
	Users     []*User        `gorm:"many2many:classes_meetingattendance_user" json:"users"`
	UpdatedAt time.Time      `json:"updated_at"`
	CreatedAt time.Time      `json:"created_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
}

type ClassPermission

type ClassPermission struct {
	ID        int `gorm:"primaryKey"`
	UserID    int
	ClassID   int
	Type      ClassPermissionType `gorm:"size:4"`
	UpdatedAt time.Time
	CreatedAt time.Time
}

type ClassPermissionType

type ClassPermissionType string
const (
	JOIN ClassPermissionType = "JOIN"
	OUT  ClassPermissionType = "OUT"
)

type User

type User struct {
	ID           int       `gorm:"primaryKey" json:"id,omitempty"`
	FirstName    string    `gorm:"size:50" json:"first_name,omitempty"`
	LastName     string    `gorm:"size:50" json:"last_name,omitempty"`
	Username     string    `gorm:"size:50;uniqueIndex" json:"username,omitempty"`
	Email        string    `gorm:"size:50;uniqueIndex" json:"email,omitempty"`
	Avatar       *string   `gorm:"size:255" json:"avatar,omitempty"`
	Password     string    `gorm:"size:128" json:"-"`
	IsActive     bool      `gorm:"default:false" json:"is_active,omitempty"`
	IsLogined    bool      `gorm:"default:false" json:"is_logined,omitempty"`
	Type         UserType  `gorm:"default:1" json:"type"`
	UpdatedAt    time.Time `json:"updated_at,omitempty"`
	DateJoined   time.Time `gorm:"autoCreateTime" json:"date_joined,omitempty"`
	Articles     []Article `gorm:"foreignKey:UserID" json:"articles,omitempty"`
	ClassMentors []*Class  `gorm:"many2many:classes_user_mentor" json:"class_mentors,omitempty"`
	ClassMembers []*Class  `gorm:"many2many:classes_user_member" json:"class_members,omitempty"`
}

func GetUserByEmail

func GetUserByEmail(email string) (User, error)

func GetUserByID

func GetUserByID(id int) (User, error)

func GetUserByUsername

func GetUserByUsername(username string) (User, error)

type UserType

type UserType int8
const (
	ADMIN UserType = iota
	MEMBER
)

Jump to

Keyboard shortcuts

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