model

package
v0.0.0-...-cde1d0f Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromIDMap

func FromIDMap[T hasID](m map[int]T) []T

func Keys

func Keys[T comparable, U any](m map[T]U) []T

func ToIDMap

func ToIDMap[T hasID](objs []T) map[int]T

func ToIDs

func ToIDs[T hasID](objs []T) []int

func ToKeyMap

func ToKeyMap[T hasKey](objs []T) map[string]T

func Values

func Values[T comparable, U any](m map[T]U) []U

func ValuesFlatten

func ValuesFlatten[T comparable, U comparable](m map[T][]U) []U

Types

type Casts

type Casts struct {
	SubjectID    int      `gorm:"subject_id"`
	PositionID   int      `gorm:"position_id"`
	PersonID     int      `gorm:"person_id"`
	CharacterIDs IntSlice `gorm:"character_ids"`
}

func (*Casts) Key

func (c *Casts) Key() string

func (*Casts) TTL

func (c *Casts) TTL() time.Duration

type Character

type Character struct {
	ID               int      `gorm:"column:character_id"      json:"id"`
	Name             string   `gorm:"column:character_name"    json:"name"`
	NameCN           string   `gorm:"column:character_name_cn" json:"nameCN,omitempty"`
	Image            string   `gorm:"column:character_image"   json:"image,omitempty"`
	BelongingSubject *Subject `gorm:"-"                        json:"subject"`
}

func (*Character) GetID

func (c *Character) GetID() int

func (*Character) Key

func (c *Character) Key() string

func (*Character) TTL

func (c *Character) TTL() time.Duration

type CharacterSummary

type CharacterSummary struct {
	Characters []*Character `json:"characters"`
	Count      int          `json:"count"`
}

CharacterSummary 包含一个人物的全部角色

type Collection

type Collection struct {
	ID       int
	UserRate float64
}

Collection 为用户的一条收藏

func (Collection) GetID

func (c Collection) GetID() int

type CollectionGroup

type CollectionGroup struct {
	Query       bangumi.CollectionQuery
	Collections []Collection
}

func (*CollectionGroup) Key

func (e *CollectionGroup) Key() string

func (*CollectionGroup) TTL

func (e *CollectionGroup) TTL() time.Duration

type Credits

type Credits struct {
	SubjectID  int `gorm:"subject_id"`
	PositionID int
	PersonIDs  IntSlice `gorm:"person_ids"`
}

func (*Credits) GetID

func (c *Credits) GetID() int

func (*Credits) Key

func (c *Credits) Key() string

func (*Credits) TTL

func (c *Credits) TTL() time.Duration

type IntSlice

type IntSlice []int

func (*IntSlice) Scan

func (s *IntSlice) Scan(value any) error

func (*IntSlice) Value

func (s *IntSlice) Value() (driver.Value, error)

type Object

type Object[T any] interface {
	*T
	comparable

	TTL() time.Duration
	// contains filtered or unexported methods
}

type Person

type Person struct {
	ID     int    `gorm:"column:person_id"      json:"id"`
	Name   string `gorm:"column:person_name"    json:"name"`
	NameCN string `gorm:"column:person_name_cn" json:"nameCN,omitempty"`
}

func (*Person) GetID

func (p *Person) GetID() int

func (*Person) Key

func (p *Person) Key() string

func (*Person) TTL

func (p *Person) TTL() time.Duration

type PersonSummary

type PersonSummary struct {
	Person    *Person
	Subject   *SubjectSummary
	Series    *SubjectSummary
	Character *CharacterSummary
}

PersonSummary 一个人物的完整统计结果,用于暂存在服务端

type PersonSummaryByType

type PersonSummaryByType struct {
	Person            `json:"person"`
	*SubjectSummary   `json:",omitempty"`
	*CharacterSummary `json:",omitempty"`
}

PersonSummaryByType 一个人物的一种统计结果

  1. subject
  2. series
  3. character

subject 和 series 都用 SubjectSummary 类型填充

type Request

type Request struct {
	UserID          string     `json:"userID"          binding:"required_unless=isGlobal true"`
	Position        string     `json:"position"        binding:"required"`
	SubjectType     int        `json:"subjectType"     binding:"required,oneof=1 2 3 4 6"`
	CollectionTypes []int      `json:"collectionTypes" binding:"required_unless=isGlobal true"`
	PositiveTags    []string   `json:"positiveTags"    binding:"omitempty"`
	NegativeTags    []string   `json:"negativeTags"    binding:"omitempty"`
	RateRange       []*float64 `json:"rateRange"       binding:"omitempty,len=2,dive,omitempty,min=0,max=10"`
	FavoriteRange   []*int     `json:"favoriteRange"   binding:"omitempty,len=2,dive,omitempty,min=0"`
	DateRange       []*int     `json:"dateRange"       binding:"omitempty,len=2,dive,omitempty,min=0,max=10"`
	IsGlobal        *bool      `json:"isGlobal"        binding:"omitempty"`
	ShowNSFW        *bool      `json:"showNSFW"        binding:"omitempty"`
	StatisticType   *int       `json:"statisticType"   binding:"omitempty,oneof=1 2 3"`
	Page            *int       `json:"page"            binding:"omitempty,min=1"`
	PageSize        *int       `json:"pageSize"        binding:"omitempty,min=1"`
	SortBy          *int       `json:"sortBy"          binding:"omitempty,oneof=1 2 3"`
	Ascend          *bool      `json:"ascend"          binding:"omitempty"`
}

type Response

type Response struct {
	Summaries   []*PersonSummaryByType `json:"summaries"`
	PersonCount int                    `json:"total"`
	ObjectCount int                    `json:"itemCount"` // 查询到的 条目 / 系列 / 角色 数量
}

type Sequel

type Sequel struct {
	SubjectID int `gorm:"column:subject_id"`
	SeriesID  int `gorm:"column:series_id"`
	Order     int `gorm:"column:sequel_order"`
}

func (Sequel) GetID

func (s Sequel) GetID() int

func (Sequel) Key

func (s Sequel) Key() string

func (Sequel) TTL

func (s Sequel) TTL() time.Duration

type Statistics

type Statistics struct {
	PeopleSummary  []*PersonSummary
	PersonCount    int
	SubjectCount   int
	SeriesCount    int
	CharacterCount int
}

Statistics 包含一次查询的完整结果,用于暂存在服务端

type StatsEntity

type StatsEntity struct {
	Request    *Request
	Statistics *Statistics
}

func (*StatsEntity) Key

func (e *StatsEntity) Key() string

func (*StatsEntity) TTL

func (e *StatsEntity) TTL() time.Duration

type StringSlice

type StringSlice []string

StringSlice 是支持与 []byte 进行序列化和反序列化的 json 列表类型。

func (*StringSlice) Scan

func (s *StringSlice) Scan(value any) error

func (*StringSlice) Value

func (s *StringSlice) Value() (driver.Value, error)

type Subject

type Subject struct {
	ID          int         `gorm:"column:subject_id"       json:"id,omitempty"`
	Name        string      `gorm:"column:subject_name"     json:"name,omitempty"`
	NameCN      string      `gorm:"column:subject_name_cn"  json:"nameCN,omitempty"`
	Rate        float64     `gorm:"column:subject_rate"     json:"rate,omitempty"`
	Image       string      `gorm:"column:subject_image"    json:"image,omitempty"`
	Favorite    int         `gorm:"column:subject_favorite" json:"-"`
	Tags        StringSlice `gorm:"column:subject_tags"     json:"-"`
	Date        time.Time   `gorm:"column:subject_date"     json:"-"`
	NSFW        bool        `gorm:"column:subject_nsfw"     json:"-"`
	SequelOrder int         `gorm:"-"                       json:"-"`
}

func (*Subject) GetID

func (s *Subject) GetID() int

func (*Subject) Key

func (s *Subject) Key() string

func (*Subject) TTL

func (s *Subject) TTL() time.Duration

type SubjectSummary

type SubjectSummary struct {
	Subjects []*Subject `json:"subjects"`
	Count    int        `json:"count"`
	Average  float64    `json:"average"`
	Overall  float64    `json:"overall"`
}

SubjectSummary 包括一个人物的全部条目

Jump to

Keyboard shortcuts

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