models

package
v0.0.0-...-a6fb04e Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 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 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(255)"`
	Slug          string `gorm:"unique"`
	Blurb         string `gorm:"type: varchar(255)"`
	AgeDiscretion choices.AgeType

	GenreID    uuid.UUID `json:"genre_id"`
	Genre      Genre     `gorm:"foreignKey:GenreID;constraint:OnDelete:SET NULL;<-:false"`
	Tags       []Tag     `gorm:"many2many:book_tags;<-:false"`
	Chapters   []Chapter `gorm:"<-:false"`
	CoverImage string    `gorm:"type:varchar(10000)"`

	Completed bool     `gorm:"default:false"`
	Views     string   `gorm:"type:varchar(10000000)"`
	Reviews   []Review `gorm:"<-:false"`
	Votes     []Vote   `gorm:"<-:false"`

	// 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           uint
	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
	Synopsis             string
	Outline              string
	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) ViewsCount

func (b Book) ViewsCount() int

func (Book) VotesCount

func (b Book) VotesCount() int

func (Book) WordCount

func (b Book) WordCount() int

type BoughtChapter

type BoughtChapter struct {
	BaseModel
	BuyerID uuid.UUID `gorm:"index:,unique,composite:buyer_id_chapter_id_bought_chapter"`
	Buyer   User      `gorm:"foreignKey:BuyerID;constraint:OnDelete:CASCADE;<-:false"`

	ChapterID uuid.UUID `gorm:"index:,unique,composite:buyer_id_chapter_id_bought_chapter"`
	Chapter   Chapter   `gorm:"foreignKey:ChapterID;constraint:OnDelete:CASCADE;<-:false"`
}

type Chapter

type Chapter struct {
	BaseModel
	BookID        uuid.UUID             `json:"book_id"`
	Book          Book                  `gorm:"foreignKey:BookID;constraint:OnDelete:CASCADE;<-:false"`
	Title         string                `json:"title" gorm:"type: varchar(255)"`
	Slug          string                `gorm:"unique"`
	Text          string                `json:"text" gorm:"type: varchar(100000)"`
	ChapterStatus choices.ChapterStatus `gorm:"type:varchar(100); default:DRAFT" json:"chapter_status"`
}

func (*Chapter) BeforeSave

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

func (*Chapter) GenerateUniqueSlug

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

func (Chapter) WordCount

func (c Chapter) WordCount() int

type Coin

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

type Genre

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

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 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"`

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

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

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

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

type Reply

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

	ReviewID uuid.UUID
	Review   Review `gorm:"foreignKey:ReviewID;constraint:OnDelete:CASCADE;<-:false"`

	Likes []User `gorm:"many2many:review_reply_likes;<-:false"`
	Text  string `gorm:"type:varchar(10000)"`
}

func (Reply) LikesCount

func (r Reply) LikesCount() int

type Review

type Review struct {
	BaseModel
	UserID uuid.UUID `gorm:"index:,unique,composite:user_id_book_id_reviews"`
	User   User      `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE;<-:false"`

	BookID uuid.UUID `gorm:"index:,unique,composite:user_id_book_id_reviews"`
	Book   Book      `gorm:"foreignKey:BookID;constraint:OnDelete:CASCADE;<-:false"`

	Rating  choices.RatingChoice
	Likes   []User  `gorm:"many2many:review_likes;<-:false"`
	Text    string  `gorm:"type:varchar(10000)"`
	Replies []Reply `gorm:"<-:false"`
}

func (Review) LikesCount

func (r Review) LikesCount() int

func (Review) RepliesCount

func (r Review) RepliesCount() int

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 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  `gorm:"unique"`
	Slug   string  `gorm:"unique"`
	Genres []Genre `gorm:"many2many:genre_tags;"`
}

func (*Tag) BeforeSave

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

type Token

type Token struct {
	BaseModel
	UserId      uuid.UUID `gorm:"unique"`
	User        User      `gorm:"foreignKey:UserId;constraint:OnDelete:CASCADE"`
	TokenString string
}

func (*Token) BeforeSave

func (token *Token) BeforeSave(tx *gorm.DB) (err error)

func (Token) CheckExpiration

func (obj Token) CheckExpiration() bool

func (Token) GenerateRandomToken

func (token Token) GenerateRandomToken(db *gorm.DB) string

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
	FirstName          string          `gorm:"type: varchar(255);not null"`
	LastName           string          `gorm:"type: varchar(255);not 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"`
	TermsAgreement     bool            `gorm:"default:false"`
	Avatar             string          `gorm:"type:varchar(1000);null;"`
	Access             *string         `gorm:"type:varchar(1000);null;"`
	Refresh            *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"`
	SubscriptionExpiry *time.Time      `gorm:"null"`

	// 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) FullName

func (user User) FullName() string

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