models

package
v0.0.0-...-1b56600 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddUserToCourseInfo

func AddUserToCourseInfo(uid primitive.ObjectID, cid primitive.ObjectID) error

func CalcAvgScore

func CalcAvgScore(cid primitive.ObjectID) (float32, error)

func CountReviewByCourseId

func CountReviewByCourseId(cid primitive.ObjectID) (int64, error)

func CreateCourseTextIndexModels

func CreateCourseTextIndexModels() []mongo.IndexModel

func InitDb

func InitDb(config *ultis.Config) error

func IsBanned

func IsBanned(uid primitive.ObjectID) bool

func IsUserJoined

func IsUserJoined(cid primitive.ObjectID, uid primitive.ObjectID) bool

Types

type Approve

type Approve struct {
	field.DefaultField `json:"-" bson:",inline"`
	LecId              primitive.ObjectID `json:"lid" bson:"lid"`
}

func GetAllApprovingLecturers

func GetAllApprovingLecturers() ([]Approve, error)

func (*Approve) BeforeInsert

func (appr *Approve) BeforeInsert() error

Hooks

func (*Approve) FindById

func (appr *Approve) FindById(oid primitive.ObjectID) error

func (*Approve) FindByLecId

func (appr *Approve) FindByLecId(oid primitive.ObjectID) error

func (*Approve) Remove

func (appr *Approve) Remove() error

func (*Approve) Save

func (a *Approve) Save() error

type Category

type Category struct {
	field.DefaultField `json:",inline" bson:",inline" json:"-"`
	Name               string `json:"name" bson:"name" binding:"required"`
}

func GetAllCategory

func GetAllCategory() ([]Category, error)

func (*Category) BeforeInsert

func (cat *Category) BeforeInsert() error

HOOKS

func (*Category) FindCategoryById

func (cat *Category) FindCategoryById(oid primitive.ObjectID) error

func (*Category) FindCategoryByName

func (cat *Category) FindCategoryByName(name string) error

func (*Category) Remove

func (cat *Category) Remove() error

func (*Category) Save

func (cat *Category) Save() error

func (*Category) UpdateName

func (cat *Category) UpdateName(name string) error

type Course

type Course struct {
	field.DefaultField `bson:",inline"`
	LecId              primitive.ObjectID `json:"lid" bson:"lid" binding:"required"`
	CatId              primitive.ObjectID `json:"cat_id" bson:"cat_id" binding:"required"`
	Ava                string             `json:"ava" bson:"ava"`
	Name               string             `json:"name" bson:"name"  binding:"required"`
	ShortDesc          string             `json:"short_desc" bson:"short_desc"`
	FullDesc           string             `json:"full_desc" bson:"full_desc"`
	Fee                float64            `json:"fee" bson:"fee" binding:"required"`
	Discount           float64            `json:"discount" bson:"discount" binding:"required"`
	ChapterCount       int                `json:"chapter_count" bson:"chapter_count"`
	IsDone             bool               `json:"is_done" bson:"is_done"`
	RegCount           int                `json:"reg_count" bson:"reg_count"`
	WatchCount         int                `json:"watch_count" bson:"watch_count"`
	Disabled           bool               `json:"disabled" bson:"disabled"`
}

func FindAllCourseByCatId

func FindAllCourseByCatId(cid primitive.ObjectID) ([]Course, error)

func FindAllCourseBySubcatId

func FindAllCourseBySubcatId(scid primitive.ObjectID) ([]Course, error)

func FindByCatId

func FindByCatId(cid primitive.ObjectID, limit int64, offset int64) ([]Course, error)

func FindByLecId

func FindByLecId(lid primitive.ObjectID) ([]Course, error)

func FindBySubcatId

func FindBySubcatId(subcatId primitive.ObjectID, limit int64, offset int64) ([]Course, error)

func Get5RandomCourseBySubcat

func Get5RandomCourseBySubcat(cid primitive.ObjectID) ([]Course, error)

func GetAllCourse

func GetAllCourse(excludeDisabled bool) ([]Course, error)

func GetTop10MostRegisterCourse

func GetTop10MostRegisterCourse() ([]Course, error)

func SearchByKeyword

func SearchByKeyword(keyword string, limit int64, offset int64) ([]Course, error)

func (*Course) AfterInsert

func (c *Course) AfterInsert() error

func (*Course) BeforeInsert

func (c *Course) BeforeInsert() error

Hooks c

func (*Course) ConvertToFullCourse

func (c *Course) ConvertToFullCourse() (*FullCourse, error)

func (*Course) ConvertToSimpleCourse

func (c *Course) ConvertToSimpleCourse() (*SimpleCourse, error)

func (*Course) FindById

func (c *Course) FindById(oid primitive.ObjectID) error

func (*Course) ForceRemove

func (c *Course) ForceRemove() error

func (*Course) Remove

func (c *Course) Remove() error

func (*Course) Save

func (c *Course) Save() error

func (*Course) UpdateChapterCount

func (c *Course) UpdateChapterCount(count int) error

func (*Course) UpdateCourseDesc

func (c *Course) UpdateCourseDesc(short string, full string) error

func (*Course) UpdateCourseStatus

func (c *Course) UpdateCourseStatus(isDone bool) error

func (*Course) UpdateDisableStatus

func (c *Course) UpdateDisableStatus(disabled bool) error

func (*Course) UpdateDiscount

func (c *Course) UpdateDiscount(discount float64) error

func (*Course) UpdateWatchCount

func (c *Course) UpdateWatchCount() error

type CourseChapter

type CourseChapter struct {
	field.DefaultField `bson:",inline" json:",inline"`
	CourseId           primitive.ObjectID `json:"cid" bson:"cid" binding:"required"`
	Title              string             `json:"title" bson:"title" binding:"required"`
	Previewable        *bool              `json:"previewable" bson:"previewable" binding:"required"`
	Videos             []VideoMetadata    `json:"videos" bson:"-" binding:"-"`
}

func FindAllChapterByCourseId

func FindAllChapterByCourseId(cid primitive.ObjectID) ([]CourseChapter, error)

func (*CourseChapter) AfterRemove

func (cc *CourseChapter) AfterRemove() error

func (*CourseChapter) BeforeInsert

func (cc *CourseChapter) BeforeInsert() error

Hooks cc

func (*CourseChapter) FindById

func (cc *CourseChapter) FindById(ccid primitive.ObjectID) error

func (*CourseChapter) Remove

func (cc *CourseChapter) Remove() error

func (*CourseChapter) Save

func (cc *CourseChapter) Save() error

type DisplayableReview

type DisplayableReview struct {
	Id       primitive.ObjectID `json:"id"`
	Content  string             `json:"content"`
	Score    float32            `json:"score"`
	Username string             `json:"username"`
	Time     time.Time          `json:"time"`
}

type FullCourse

type FullCourse struct {
	Id            string          `json:"id"`
	Title         string          `json:"title"`
	CategoryId    string          `json:"cid"`
	Category      string          `json:"category"`
	LecturerId    string          `json:"lid"`
	Lecturer      string          `json:"lecturer"`
	LecturerEmail string          `json:"lecturer_email"`
	ReviewScore   float32         `json:"review_score"`
	Ava           string          `json:"ava"`
	Fee           float64         `json:"fee" bson:"fee"`
	Discount      float64         `json:"discount" bson:"discount"`
	ShortDesc     string          `json:"short_desc" bson:"short_desc"`
	FullDesc      string          `json:"full_desc" bson:"full_desc"`
	IsDone        bool            `json:"is_done"`
	Chapters      []CourseChapter `json:"chapters"`
	ReviewCount   int64           `json:"review_count"`
	Disabled      bool            `json:"disabled"`
}

func GetAllCourseAsFull

func GetAllCourseAsFull() ([]FullCourse, error)

type Review

type Review struct {
	field.DefaultField `bson:",inline"`
	UserId             primitive.ObjectID `json:"uid" bson:"uid"`
	CourseId           primitive.ObjectID `json:"cid" bson:"cid"`
	Content            string             `json:"content" bson:"content"`
	Score              float32            `json:"score" bson:"score"`
}

func FindByCourseId

func FindByCourseId(cid primitive.ObjectID) ([]Review, error)

func (*Review) ConvertToDisplayableReview

func (rv *Review) ConvertToDisplayableReview() (*DisplayableReview, error)

func (*Review) DeleteReview

func (r *Review) DeleteReview(rid primitive.ObjectID) error

func (*Review) FindById

func (r *Review) FindById(oid primitive.ObjectID) error

func (*Review) FindByUid

func (r *Review) FindByUid(uid primitive.ObjectID) error

func (*Review) FindByUidAndCid

func (r *Review) FindByUidAndCid(uid primitive.ObjectID, cid primitive.ObjectID) error

func (*Review) Save

func (r *Review) Save() error

func (*Review) UpdateReview

func (r *Review) UpdateReview(newContent string, newScore float32) error

type SimpleCourse

type SimpleCourse struct {
	Id           string  `json:"id"`
	Title        string  `json:"title"`
	CategoryId   string  `json:"cid"`
	Category     string  `json:"category"`
	LecturerId   string  `json:"lid"`
	Lecturer     string  `json:"lecturer"`
	ReviewScore  float32 `json:"review_score"`
	Ava          string  `json:"ava"`
	CurrentPrice float64 `json:"current_price"`
	IsDiscount   bool    `json:"is_discount"`
	IsDone       bool    `json:"is_done"`
	ReviewCount  int64   `json:"review_count"`
}

func GetAllCourseAsSimple

func GetAllCourseAsSimple() ([]SimpleCourse, error)

func GetAllCourseByCatIdAsSimple

func GetAllCourseByCatIdAsSimple(catId primitive.ObjectID) ([]SimpleCourse, error)

func GetAllCourseBySubcatIdAsSimple

func GetAllCourseBySubcatIdAsSimple(subcatId primitive.ObjectID) ([]SimpleCourse, error)

func GetTop10MostWatchCourse

func GetTop10MostWatchCourse() ([]SimpleCourse, error)

func GetTop10NewestCourse

func GetTop10NewestCourse() ([]SimpleCourse, error)

func GetTop4HighlightCourse

func GetTop4HighlightCourse() ([]SimpleCourse, error)

type SubCategory

type SubCategory struct {
	field.DefaultField `bson:",inline" json:",inline"`
	Name               string             `json:"name" bson:"name"`
	ParentCategoryId   primitive.ObjectID `json:"parentCategoryId" bson:"parentCategoryId"`
}

func CreateSubCategory

func CreateSubCategory(name string, catName string) (*SubCategory, error)

func FindByParentCategoryId

func FindByParentCategoryId(ParentCatId primitive.ObjectID) ([]SubCategory, error)

func FindSubcatsByCatName

func FindSubcatsByCatName(name string) ([]SubCategory, error)

func GetAllMostRegisterCategory

func GetAllMostRegisterCategory() ([]SubCategory, error)

func (*SubCategory) BeforeInsert

func (subcat *SubCategory) BeforeInsert() error

Hooks

func (*SubCategory) FindByName

func (subcat *SubCategory) FindByName(name string) error

func (*SubCategory) FindSubCategoryById

func (subcat *SubCategory) FindSubCategoryById(oid primitive.ObjectID) error

func (*SubCategory) Remove

func (subcat *SubCategory) Remove() error

func (*SubCategory) Save

func (subcat *SubCategory) Save() error

func (*SubCategory) UpdateName

func (subcat *SubCategory) UpdateName(name string) error

type TimeMark

type TimeMark struct {
	field.DefaultField `bson:",inline"`
	UserId             primitive.ObjectID `json:"uid" bson:"uid"`
	VideoId            primitive.ObjectID `json:"vid" bson:"vid"`
	CurTime            int64              `json:"cur_time" bson:"cur_time"`
}

func (*TimeMark) FindByVideoId

func (tm *TimeMark) FindByVideoId(vid primitive.ObjectID) error

func (*TimeMark) Save

func (tm *TimeMark) Save() error

func (*TimeMark) UpdateTimeMark

func (tm *TimeMark) UpdateTimeMark(newCurTime int64) error

type User

type User struct {
	field.DefaultField     `json:",inline" bson:",inline"`
	Fullname               string    `json:"fullname" bson:"fullname" binding:"required"`
	Username               string    `json:"username" bson:"username" binding:"required"`
	Email                  string    `json:"email" bson:"email" binding:"required"`
	HPassword              string    `json:"pass" bson:"hpass" binding:"required"`
	CurOtp                 string    `json:"-" bson:"otp"`
	LastOtpUpdated         time.Time `json:"-" bson:"last_otp_updated"`
	CurOtpExpiredTime      time.Time `json:"-" bson:"otp_exp"`
	RecoverCode            string    `json:"-" bson:"recover"`
	RecoverCodeExpiredTime time.Time `json:"-" bson:"rec_exp"`
	RefreshToken           string    `json:"-" bson:"rf"`
	IsLec                  bool      `json:"isLec" bson:"is_lec"`
	IsBanned               bool      `json:"is_banned" bson:"is_banned"`
}

func AllUser

func AllUser() ([]User, error)

func NewUser

func NewUser(fullname string, email string, password string) *User

func (*User) AfterInsert

func (u *User) AfterInsert() error

func (*User) Ban

func (u *User) Ban() error

func (*User) BeforeInsert

func (u *User) BeforeInsert() error

Hooks

func (*User) ConfirmOtp

func (u *User) ConfirmOtp(username string, otp string) error

func (*User) ConfirmResetPassword

func (u *User) ConfirmResetPassword(recoverCode string, newPassword string) error

func (*User) FindByEmail

func (u *User) FindByEmail(email string) error

func (*User) FindById

func (u *User) FindById(oid primitive.ObjectID) error

func (*User) FindByIdAndRfToken

func (u *User) FindByIdAndRfToken(oid primitive.ObjectID, rf string) error

func (*User) FindByUsername

func (u *User) FindByUsername(username string) error

func (*User) GenerateOtp

func (u *User) GenerateOtp() error

func (*User) GenerateRecoverCode

func (u *User) GenerateRecoverCode() error

func (*User) GenerateRfToken

func (u *User) GenerateRfToken() error

func (*User) Save

func (u *User) Save() error

func (*User) Unban

func (u *User) Unban() error

func (*User) UpdateLecturerStatus

func (u *User) UpdateLecturerStatus(isLec bool) error

func (*User) UpdateOtp

func (u *User) UpdateOtp(username string) (*string, error)

func (*User) UpdatePassword

func (u *User) UpdatePassword(newPassword string) error

func (*User) UpdateProfile

func (u *User) UpdateProfile(newFullname string, newEmail string) error

func (*User) UpdateTokens

func (u *User) UpdateTokens() (*string, *string, error)

type VideoMetadata

type VideoMetadata struct {
	field.DefaultField `bson:",inline" json:",inline"`
	ChapterId          primitive.ObjectID `json:"chap_id" bson:"chap_id"`
	CourseId           primitive.ObjectID `json:"cid" bson:"cid"`
	Title              string             `json:"title" bson:"title"`
}

func FindAllVideoMetadataByChapterId

func FindAllVideoMetadataByChapterId(ccid primitive.ObjectID) ([]VideoMetadata, error)

func (*VideoMetadata) FindById

func (vm *VideoMetadata) FindById(vmid primitive.ObjectID) error

func (*VideoMetadata) Remove

func (vm *VideoMetadata) Remove() error

func (*VideoMetadata) Save

func (vm *VideoMetadata) Save() error

func (*VideoMetadata) UpdateVideoTitle

func (vm *VideoMetadata) UpdateVideoTitle(title string) error

type WatchList

type WatchList struct {
	field.DefaultField `bson:",inline"`
	UserId             primitive.ObjectID   `json:"uid" bson:"uid"`
	CoursesId          []primitive.ObjectID `json:"cids" bson:"cids"`
}

func (*WatchList) AddCourseToWatchList

func (wl *WatchList) AddCourseToWatchList(cid primitive.ObjectID) error

func (*WatchList) BeforeInsert

func (wl *WatchList) BeforeInsert() error

Hooks

func (*WatchList) FindByUid

func (wl *WatchList) FindByUid(uid primitive.ObjectID) error

func (*WatchList) RemoveCourseFromWatchList

func (wl *WatchList) RemoveCourseFromWatchList(cid primitive.ObjectID) error

func (*WatchList) Save

func (wl *WatchList) Save() error

type XSimpleCourse

type XSimpleCourse struct {
	CourseId   primitive.ObjectID `json:"cid"`
	CourseName string             `json:"course_name"`
}

func GetRegByUid

func GetRegByUid(uid primitive.ObjectID) ([]XSimpleCourse, error)

Jump to

Keyboard shortcuts

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