models

package
v0.0.0-...-2555d15 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: GPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthToken

type AuthToken struct {
	BaseModel
	UserID  uuid.UUID `gorm:"index"`
	User    User      `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;<-:false"`
	Access  string    `gorm:"unique"`
	Refresh string    `gorm:"unique"`
}

type BaseModel

type BaseModel struct {
	ID        uuid.UUID `json:"-" gorm:"type:uuid;primarykey;not null;default:uuid_generate_v4()"`
	CreatedAt time.Time `json:"-" gorm:"not null"`
	UpdatedAt time.Time `json:"-" gorm:"not null"`
}

type Book

type Book struct {
	BaseModel
	AuthorID      uuid.UUID
	Author        User   `gorm:"foreignKey:AuthorID;constraint:OnDelete:SET NULL;<-:false"`
	Title         string `gorm:"type: varchar(1000)"`
	Slug          string `gorm:"unique"`
	Blurb         string `gorm:"type: varchar(10000)"`
	AgeDiscretion choices.AgeType

	GenreID uuid.UUID
	Genre   Genre `gorm:"foreignKey:GenreID;constraint:OnDelete:SET NULL;<-:false"`

	SubSections []SubSection `gorm:"many2many:book_sub_sections;joinForeignKey:BookID;joinReferences:SubSectionID"`

	Tags       []Tag     `gorm:"many2many:book_tags"`
	Chapters   []Chapter `gorm:"constraint:OnDelete:CASCADE"`
	CoverImage string    `gorm:"type:varchar(10000)"`

	Completed bool      `gorm:"default:false"`
	Reviews   []Comment `gorm:"<-:false;constraint:OnDelete:CASCADE"`
	Votes     []Vote    `gorm:"<-:false;constraint:OnDelete:CASCADE"`

	Featured       bool `gorm:"default:false"` //controlled by admin
	WeeklyFeatured time.Time
	Reads          []BookRead `gorm:"<-:false;constraint:OnDelete:CASCADE"`
	AvgRating      float64    // meant for query purposes. do not intentionally populate field
	Bookmark       []Bookmark `gorm:"<-:false;constraint:OnDelete:CASCADE"`

	// BOOK CONTRACT
	FullName             string `gorm:"type: varchar(1000)"`
	Email                string
	PenName              string `gorm:"type: varchar(1000)"`
	Age                  uint
	Country              string `gorm:"type: varchar(1000)"`
	Address              string `gorm:"type: varchar(1000)"`
	City                 string `gorm:"type: varchar(1000)"`
	State                string `gorm:"type: varchar(1000)"`
	PostalCode           string
	TelephoneNumber      string                       `gorm:"type: varchar(20)"`
	IDType               choices.ContractIDTypeChoice `gorm:"type: varchar(100)"`
	IDFrontImage         string
	IDBackImage          string
	BookAvailabilityLink *string
	PlannedLength        uint
	AverageChapter       uint
	UpdateRate           uint
	IntendedContract     choices.ContractTypeChoice
	FullPrice            *int
	ChapterPrice         int
	FullPurchaseMode     bool                         `gorm:"default:false"`
	ContractStatus       choices.ContractStatusChoice `gorm:"default:PENDING"`
}

func (*Book) BeforeCreate

func (b *Book) BeforeCreate(tx *gorm.DB) (err error)

func (Book) ChaptersCount

func (b Book) ChaptersCount() int

func (*Book) GenerateUniqueSlug

func (b *Book) GenerateUniqueSlug(tx *gorm.DB) string

func (Book) GetWordCount

func (b Book) GetWordCount() int

func (Book) LibraryCount

func (b Book) LibraryCount() int

func (Book) ReadsCount

func (b Book) ReadsCount() int

func (Book) VotesCount

func (b Book) VotesCount() int

type BookRead

type BookRead struct {
	BaseModel
	UserID    uuid.UUID
	User      User      `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;<-:false"`
	BookID    uuid.UUID `json:"book_id"`
	Book      Book      `gorm:"foreignKey:BookID;constraint:OnDelete:CASCADE;<-:false"`
	Completed bool      `gorm:"default:false"`
	InLibrary bool      `gorm:"default:false"`
	FirstRead bool      `gorm:"default:false"`
}

type BookReport

type BookReport struct {
	BaseModel
	UserID                uuid.UUID
	User                  User      `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;<-:false"`
	BookID                uuid.UUID `json:"book_id"`
	Book                  Book      `gorm:"foreignKey:BookID;constraint:OnDelete:CASCADE;<-:false"`
	Reason                string    `gorm:"type: varchar(1000)"`
	AdditionalExplanation *string   `gorm:"type: varchar(1000)"`
}

type BookSubSection

type BookSubSection struct {
	BookID         uuid.UUID `gorm:"primaryKey"`
	SubSectionID   uuid.UUID `gorm:"primaryKey"`
	OrderInSection uint
	CreatedAt      time.Time
}

type Bookmark

type Bookmark struct {
	BaseModel
	UserID uuid.UUID
	User   User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;<-:false"`

	BookID uuid.UUID
	Book   Book `gorm:"foreignKey:BookID;constraint:OnDelete:CASCADE;<-:false"`
}

type Chapter

type Chapter struct {
	BaseModel
	BookID     uuid.UUID
	Book       Book        `gorm:"foreignKey:BookID;constraint:OnDelete:CASCADE;<-:false"`
	Title      string      `gorm:"type: varchar(255)"`
	Slug       string      `gorm:"unique"`
	Paragraphs []Paragraph `gorm:"foreignKey:ChapterID;constraint:OnDelete:CASCADE;"`
	IsLast     bool        `gorm:"default:false"`
}

func (*Chapter) BeforeSave

func (c *Chapter) BeforeSave(tx *gorm.DB) (err error)

func (*Chapter) GenerateUniqueSlug

func (c *Chapter) GenerateUniqueSlug(tx *gorm.DB) string

type Coin

type Coin struct {
	BaseModel
	Amount int             `gorm:"default:0" json:"amount"`
	Price  decimal.Decimal `gorm:"default:0" json:"price"`
}

type Comment

type Comment struct {
	BaseModel
	UserID uuid.UUID
	User   User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;<-:false"`

	BookID *uuid.UUID // For reviews
	Book   *Book      `gorm:"foreignKey:BookID;constraint:OnDelete:CASCADE;<-:false"`
	Rating choices.RatingChoice

	ParagraphID *uuid.UUID // For paragraph
	Paragraph   *Paragraph `gorm:"foreignKey:ParagraphID;constraint:OnDelete:CASCADE;<-:false"`
	Likes       []Like     `gorm:"foreignKey:CommentID;constraint:OnDelete:CASCADE"`
	Text        string     `gorm:"type:varchar(10000)"`

	ParentID *uuid.UUID
	Parent   *Comment  `gorm:"foreignKey:ParentID;constraint:OnDelete:CASCADE;<-:false"`
	Replies  []Comment `gorm:"foreignKey:ParentID;constraint:OnDelete:CASCADE"`
}

func (Comment) LikesCount

func (c Comment) LikesCount() int

func (Comment) RepliesCount

func (c Comment) RepliesCount() int

type FeaturedContent

type FeaturedContent struct {
	BaseModel
	Location choices.FeaturedContentLocationChoice
	Desc     string
	BookID   uuid.UUID
	Book     Book    `gorm:"foreignKey:BookID;constraint:OnDelete:CASCADE;<-:false"`
	SeenBy   []*User `gorm:"many2many:featured_content_seen_by;"`
	IsActive bool    `gorm:"default:true;"`
}

type Genre

type Genre struct {
	BaseModel
	Name string `gorm:"unique"`
	Slug string `gorm:"unique"`
	Tags []Tag
}

func (*Genre) BeforeSave

func (genre *Genre) BeforeSave(tx *gorm.DB) (err error)

type Gift

type Gift struct {
	BaseModel
	Name     string `gorm:"unique"`
	Slug     string `gorm:"unique"`
	Price    int
	Image    string
	Lanterns int
}

func (*Gift) BeforeSave

func (g *Gift) BeforeSave(tx *gorm.DB) (err error)

type Like

type Like struct {
	BaseModel
	UserID uuid.UUID
	User   User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;<-:false"`

	CommentID *uuid.UUID
	Comment   *Comment `gorm:"foreignKey:CommentID;constraint:OnDelete:CASCADE;<-:false"`
}

type Log

type Log struct {
	BaseModel
	StatusCode  int
	Method      string
	Path        string
	IP          string
	PathParams  string
	QueryParams string
	Body        string
}

type Notification

type Notification struct {
	BaseModel
	SenderID   uuid.UUID
	Sender     User `gorm:"foreignKey:SenderID;constraint:OnDelete:CASCADE;<-:false"`
	ReceiverID uuid.UUID
	Receiver   User `gorm:"foreignKey:ReceiverID;constraint:OnDelete:CASCADE;<-:false"`
	Ntype      choices.NotificationTypeChoice
	Text       string

	BookID *uuid.UUID
	Book   *Book `gorm:"foreignKey:BookID;constraint:OnDelete:CASCADE;<-:false"`

	CommentID *uuid.UUID
	Comment   *Comment `gorm:"foreignKey:CommentID;constraint:OnDelete:SET NULL;<-:false"`

	SentGiftID *uuid.UUID
	SentGift   *SentGift `gorm:"foreignKey:SentGiftID;constraint:OnDelete:CASCADE;<-:false"`

	IsRead bool `gorm:"default:false"`
}

type Paragraph

type Paragraph struct {
	BaseModel
	ChapterID uuid.UUID
	Chapter   Chapter `gorm:"foreignKey:ChapterID;constraint:OnDelete:CASCADE;<-:false"`
	Index     uint
	Text      string    `gorm:"type:text"`
	Comments  []Comment `gorm:"foreignKey:ParagraphID;constraint:OnDelete:CASCADE"`
}

func (Paragraph) CommentsCount

func (p Paragraph) CommentsCount() int

type Section

type Section struct {
	BaseModel
	Name        string `gorm:"unique"`
	Slug        string `gorm:"unique"`
	SubSections []SubSection
}

func (*Section) BeforeSave

func (section *Section) BeforeSave(tx *gorm.DB) (err error)

type SentGift

type SentGift struct {
	BaseModel
	SenderID uuid.UUID
	Sender   User `gorm:"foreignKey:SenderID;constraint:OnDelete:CASCADE;<-:false"`

	ReceiverID uuid.UUID
	Receiver   User `gorm:"foreignKey:ReceiverID;constraint:OnDelete:CASCADE;<-:false"`

	GiftID uuid.UUID
	Gift   Gift `gorm:"foreignKey:GiftID;constraint:OnDelete:CASCADE;<-:false"`

	Claimed bool `gorm:"default:false"`
}

type SiteDetail

type SiteDetail struct {
	BaseModel
	Name    string `json:"name" gorm:"default:LitPad;type:varchar(50);not null"`
	Email   string `json:"email" gorm:"default:litpad@gmail.com;not null" example:"litpad@gmail.com"`
	Phone   string `json:"phone" gorm:"default:+23412344343545;type:varchar(20);not null" example:"+234345434343"`
	Address string `json:"address" gorm:"default:234, Lagos, Nigeria;not null" example:"234, Lagos, Nigeria"`
	Fb      string `json:"fb" gorm:"default:https://facebook.com;not null" example:"https://facebook.com"`
	Tw      string `json:"tw" gorm:"default:https://twitter.com;not null" example:"https://twitter.com"`
	Wh      string `json:"wh" gorm:"default:https://wa.me/2348133831036;not null" example:"https://wa.me/2348133831036"`
	Ig      string `json:"ig" gorm:"default:https://instagram.com;not null" example:"https://instagram.com"`
}

type SubSection

type SubSection struct {
	BaseModel
	Name      string `gorm:"unique"`
	Slug      string `gorm:"unique"`
	Books     []Book `gorm:"many2many:book_sub_sections;joinForeignKey:SubSectionID;joinReferences:BookID"`
	SectionID uuid.UUID
	Section   Section `gorm:"foreignKey:SectionID;constraint:OnDelete:SET NULL;<-:false"`
}

func (*SubSection) BeforeSave

func (subSection *SubSection) BeforeSave(tx *gorm.DB) (err error)

type Subscriber

type Subscriber struct {
	BaseModel
	Email    string `json:"email" gorm:"not null" validate:"required,min=5,email" example:"johndoe@email.com"`
	Exported bool   `json:"-" gorm:"default:false"`
}

type SubscriptionPlan

type SubscriptionPlan struct {
	BaseModel
	Amount  decimal.Decimal                `gorm:"default:0"`
	SubType choices.SubscriptionTypeChoice `gorm:"default:MONTHLY;unique"`
}

type Tag

type Tag struct {
	BaseModel
	Name    string
	Slug    string `gorm:"unique"`
	GenreID uuid.UUID
	Genre   Genre  `gorm:"foreignKey:GenreID;constraint:OnDelete:CASCADE;<-:false"`
	Books   []Book `gorm:"many2many:book_tags;"`
}

func (*Tag) BeforeSave

func (tag *Tag) BeforeSave(tx *gorm.DB) (err error)

func (Tag) BooksCount

func (t Tag) BooksCount() int

type Transaction

type Transaction struct {
	BaseModel
	Reference string    `gorm:"type: varchar(1000);not null"` // payment id
	UserID    uuid.UUID `json:"user_id"`
	User      User      `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE"`

	// FOR COINS
	CoinID   *uuid.UUID `json:"coin_id"`
	Coin     *Coin      `gorm:"foreignKey:CoinID;constraint:OnDelete:SET NULL"`
	Quantity int        `gorm:"default:1"`

	// FOR SUBSCRIPTION
	SubscriptionPlanID *uuid.UUID        `json:"subscription_plan_id"`
	SubscriptionPlan   *SubscriptionPlan `gorm:"foreignKey:SubscriptionPlanID;constraint:OnDelete:SET NULL"`

	PaymentType    choices.PaymentType    `json:"payment_type"`
	PaymentPurpose choices.PaymentPurpose `json:"payment_purpose"`
	PaymentStatus  choices.PaymentStatus  `json:"payment_status" gorm:"default:PENDING"`
	ClientSecret   string
}

func (Transaction) CoinsTotal

func (t Transaction) CoinsTotal() *int

type User

type User struct {
	BaseModel
	Name            *string `gorm:"type: varchar(255);null"`
	Username        string  `gorm:"type: varchar(1000);not null;unique;"`
	Email           string  `gorm:"not null;unique;"`
	Password        string  `gorm:"not null"`
	IsEmailVerified bool    `gorm:"default:false"`
	IsSuperuser     bool    `gorm:"default:false"`
	IsStaff         bool    `gorm:"default:false"`
	IsActive        bool    `gorm:"default:true"`

	Otp         *uint      `gorm:"null"`
	OtpExpiry   *time.Time `gorm:"null"`
	TokenString *string    `gorm:"null"`
	TokenExpiry *time.Time `gorm:"null"`

	Avatar            string          `gorm:"type:varchar(1000);null;"`
	SocialLogin       bool            `gorm:"default:false"`
	Bio               *string         `gorm:"type:varchar(1000);null;"`
	AccountType       choices.AccType `gorm:"type:varchar(100); default:READER"`
	Followings        []User          `gorm:"many2many:user_followers;foreignKey:ID;joinForeignKey:Follower;References:ID;joinReferences:Following"`
	Followers         []User          `gorm:"many2many:user_followers;foreignKey:ID;joinForeignKey:Following;References:ID;joinReferences:Follower"`
	Coins             int             `gorm:"default:0"`
	Lanterns          int             `gorm:"default:0"`
	LikeNotification  bool            `gorm:"default:false"`
	ReplyNotification bool            `gorm:"default:false"`

	CurrentPlan        *choices.SubscriptionTypeChoice `gorm:"null"`
	SubscriptionExpiry *time.Time                      `gorm:"index,null"`
	ReminderSent       bool                            `gorm:"default:false"`

	// Back referenced
	Books []Book `gorm:"foreignKey:AuthorID"`
}

func (*User) BeforeCreate

func (user *User) BeforeCreate(tx *gorm.DB) (err error)

func (User) BooksCount

func (user User) BooksCount() int

func (User) FollowersCount

func (user User) FollowersCount() int

func (User) FollowingsCount

func (user User) FollowingsCount() int

func (*User) GenerateOTP

func (u *User) GenerateOTP(db *gorm.DB)

func (*User) GenerateToken

func (u *User) GenerateToken(db *gorm.DB)

func (*User) GenerateUsername

func (user *User) GenerateUsername(db *gorm.DB, email string, username *string) string

func (User) IsOtpExpired

func (u User) IsOtpExpired() bool

func (User) IsTokenExpired

func (u User) IsTokenExpired() bool

func (User) SubscriptionExpired

func (user User) SubscriptionExpired() bool

type Vote

type Vote struct {
	BaseModel
	UserID uuid.UUID
	User   User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;<-:false"`

	BookID uuid.UUID
	Book   Book `gorm:"foreignKey:BookID;constraint:OnDelete:CASCADE;<-:false"`
}

type Waitlist

type Waitlist struct {
	BaseModel
	Name    string `gorm:"varchar(1000)"`
	Email   string `gorm:"varchar(10000)"`
	GenreID uuid.UUID
	Genre   Genre `gorm:"foreignKey:GenreID;constraint:OnDelete:CASCADE;<-:false"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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