models

package
v0.0.0-...-4ae7f04 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init() error

Init function create gocomic database and all tables

func Register

func Register(username, email, password string) error

Register function save user information into table users

func Subscribe

func Subscribe(user *User, comic *Comic) error

Subscribe function insert record into subscriber table

func Subscribed

func Subscribed(user *User, comic *Comic) bool

Subscribed function check the record exists or not

func Unsubscribe

func Unsubscribe(user *User, comic *Comic) error

Unsubscribe function delete record from subscriber table

Types

type Chapter

type Chapter struct {
	ID       int        `gorm:"primary_key" json:"-"`
	URL      string     `gorm:"size:128;not null;unique_index" json:"url"`
	Number   int        `gorm:"not null;unique_index:uix_chapters_number_comic_id" json:"index"`
	Title    string     `gorm:"size:128;not null" json:"title"`
	Cached   bool       `gorm:"not null;default:false" json:"-"`
	Path     string     `gorm:"size:256"`
	ComicID  int        `gorm:"not null;unique_index:uix_chapters_number_comic_id" json:"-"`
	Created  Time       `gorm:"type:timestamp;not null;default:current_timestamp" json:"created"`
	Comic    *Comic     `gorm:"foreignkey:ComicID;association_foreignkey:ID" json:"-"`
	Pictures []string   `gorm:"-" json:"pictures"`
	PictureS []*Picture `gorm:"foreignkey:ChapterID;association_foreignkey:ID" json:"-"`
}

Chapter mapping table chapters

func AllCachedChapters

func AllCachedChapters() []*Chapter

AllCachedChapters function get all cached chapter information

func GetChapter

func GetChapter(id, cid int) *Chapter

GetChapter function get comic record from database

func (*Chapter) Clean

func (c *Chapter) Clean() error

Clean function delete comic files and update cached column to false

func (*Chapter) Save

func (c *Chapter) Save(response *rpc.Chapter)

Save insert path of the resources into pictures table

type Comic

type Comic struct {
	ID       int        `gorm:"primary_key" json:"id"`
	URL      string     `gorm:"size:128;not null;unique_index" json:"url"`
	Title    string     `gorm:"size:128;not null;unique_index:uix_comics_title_source" json:"title"`
	Source   string     `gorm:"size:32;not null;unique_index:uix_comics_title_source" json:"source"`
	Cover    string     `gorm:"size:128;not null" json:"cover"`
	Summary  string     `gorm:"type:text" json:"summary"`
	Latest   string     `json:"latest"`
	Created  Time       `gorm:"type:timestamp;not null;default:current_timestamp" json:"created"`
	Chapters []*Chapter `gorm:"foreignkey:ComicID;association_foreignkey:ID" json:"chapters"`
	Users    []*User    `gorm:"many2many:subscribers" json:"users,omitempty"`
}

Comic mapping table comics

func AddComic

func AddComic(response *rpc.Comic, user *User) *Comic

AddComic function insert comic record and all chapter records

func AllComics

func AllComics() []*Comic

AllComics function get all comics information

func GetComic

func GetComic(id int, limit, page int) *Comic

GetComic function get comic record from database

func QueryComic

func QueryComic(source, title string, limit, page int) *Comic

QueryComic function query comic record from database

func (*Comic) Update

func (c *Comic) Update(response *rpc.Update) bool

Update insert new chapter information into chapters table and update latest column

type Picture

type Picture struct {
	ID        int64  `gorm:"primary_key"`
	Number    int    `gorm:"not null" json:"number"`
	Filename  string `gorm:"size:256"`
	ChapterID int    `gorm:"not null;index"`
	Created   Time   `gorm:"type:timestamp;not null;default:current_timestamp"`
}

Picture mapping table pictures

type Subscriber

type Subscriber struct {
	UserID  int  `gorm:"primary_key;index;auto_increment:false"`
	ComicID int  `gorm:"primary_key;index;auto_increment:false"`
	Created Time `gorm:"type:timestamp;not null;default:current_timestamp"`
	User    *User
	Comic   *Comic
}

Subscriber mapping table subscribers

type Time

type Time struct {
	time.Time
}

Time struct custom time formatter

func SubscribeDate

func SubscribeDate(user *User, comic *Comic) Time

SubscribeDate function return the Time field

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON function override

func (*Time) Scan

func (t *Time) Scan(v interface{}) error

Scan function override

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value function override

type User

type User struct {
	ID       int      `gorm:"primary_key"`
	Email    string   `gorm:"size:64;not null;unique_index"`
	Username string   `gorm:"size:64;not null;unique_index"`
	Password string   `gorm:"size:128;not null"`
	Avatar   string   `gorm:"size:128"`
	Admin    bool     `gorm:"not null;default:false"`
	Blocked  bool     `gorm:"not null;default:false"`
	Created  Time     `gorm:"type:timestamp;not null;default:current_timestamp"`
	Comics   []*Comic `gorm:"many2many:subscribers"`
}

User mapping table users

func Login

func Login(email, password string) (*User, error)

Login function return user information

func (*User) ComicSlice

func (u *User) ComicSlice() []*Comic

ComicSlice function get all comics subscribed by this user

Jump to

Keyboard shortcuts

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