avg

package
v0.1.0-alpha.6 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterController

func RegisterController(v0 *server.V0, c Controller)

Types

type BackgroundModel

type BackgroundModel struct {
	bun.BaseModel `bun:"table:backgrounds"`
	ID            int64  `bun:"id,pk,autoincrement"`
	StoryID       string `bun:""`
	Background    string `bun:""`
}

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

func NewController

func NewController(service *Service) Controller

func (*Controller) GetGroupByID

func (c *Controller) GetGroupByID(ctx *fiber.Ctx) error

func (*Controller) GetGroups

func (c *Controller) GetGroups(ctx *fiber.Ctx) error

func (*Controller) GetStories

func (c *Controller) GetStories(ctx *fiber.Ctx) error

func (*Controller) GetStoryByID

func (c *Controller) GetStoryByID(ctx *fiber.Ctx) error

type Group

type Group struct {
	ID      string  `json:"id"`
	Name    string  `json:"name"`
	ActType string  `json:"actType"`
	Stories []Story `json:"stories"`
}

type GroupModel

type GroupModel struct {
	bun.BaseModel `bun:"table:groups,alias:g"`

	// ID is the unique id of the AvgGroup.
	// e.g.: "1stact" (骑兵与猎人), "act15side" (将进酒).
	ID string `bun:"id,pk"`

	// Name is the name of the AvgGroup, can be the mainline chapter name, the activity name or the operator record name.
	// e.g.: "骑兵与猎人", "怒号光明", "学者之心", "火山".
	Name string

	ActType string

	// Stories is the stories belong to the group.
	Stories []*StoryModel `bun:"rel:has-many,join:id=group_id"`
}

GroupModel is a group of story. e.g., a 活动 such as "将进酒" or a 主线 such as "怒号光明".

type GroupRepo

type GroupRepo struct {
	infra.Repo
}

func NewGroupRepo

func NewGroupRepo(db *bun.DB) (*GroupRepo, error)

func (*GroupRepo) GetGroupByID

func (r *GroupRepo) GetGroupByID(ctx context.Context, id string) (*GroupModel, error)

func (*GroupRepo) GetGroups

func (r *GroupRepo) GetGroups(ctx context.Context) ([]GroupModel, error)

func (*GroupRepo) InsertGroups

func (r *GroupRepo) InsertGroups(ctx context.Context, groups []GroupModel) error

func (*GroupRepo) Truncate

func (r *GroupRepo) Truncate(ctx context.Context) error

type ImageModel

type ImageModel struct {
	bun.BaseModel `bun:"table:images"`
	ID            int64  `bun:"id,pk,autoincrement"`
	StoryID       string `bun:""`
	Image         string `bun:""`
}

type ResVersion

type ResVersion struct {
	bun.BaseModel `bun:"table:version"`

	// ID can only be true, because this table should only have one row.
	ID         bool   `bun:",pk"`
	ResVersion string `bun:""`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(versionRepo *VersionRepo, groupRepo *GroupRepo, storyRepo *StoryRepo) *Service

func (*Service) GetGroupByID

func (s *Service) GetGroupByID(ctx context.Context, id string) (*Group, error)

func (*Service) GetGroups

func (s *Service) GetGroups(ctx context.Context) ([]Group, error)

func (*Service) GetStories

func (s *Service) GetStories(ctx context.Context) ([]Story, error)

func (*Service) GetStoryByID

func (s *Service) GetStoryByID(ctx context.Context, id string) (*Story, error)

func (*Service) GetVersion

func (s *Service) GetVersion(ctx context.Context) (string, error)

func (*Service) SetAvgs

func (s *Service) SetAvgs(version string, groups []Group) (err error)

type Story

type Story struct {
	ID          string   `json:"id"`
	Code        string   `json:"code"`
	Name        string   `json:"name"`
	Tag         string   `json:"tag"`
	GroupID     string   `json:"groupID"`
	Images      []string `json:"images"`
	Backgrounds []string `json:"backgrounds"`
}

type StoryModel

type StoryModel struct {
	bun.BaseModel `bun:"table:stories,alias:s"`

	// ID is the unique ID of the story.
	// e.g., "1stact_level_a001_01_beg".
	ID string `bun:",pk"`

	// Code is the code of the level the story belongs to, could be empty, in this case the story belongs to no level.
	// e.g., "GT-1", "1-7", "".
	Code string

	// Name is the name of the level or the operator record the story belongs to.
	// e.g.: "不要恐慌", "埋藏", "我也要大干一场".
	Name string

	// Tag is the type of the story, which could be only "行动前", "行动后" or "幕间".
	Tag string

	// Images are the images the story uses.
	Images []*ImageModel `bun:"rel:has-many,join:id=story_id"`

	// Backgrounds are the backgrounds the story uses.
	Backgrounds []*BackgroundModel `bun:"rel:has-many,join:id=story_id"`

	// GroupID is the ID of the group the story belongs to.
	GroupID string
	// Group is the group the story belongs to.
	Group *GroupModel `bun:"rel:belongs-to,join:group_id=id"`
}

StoryModel is a part of story of an AVG. e.g., "8-1 行动前" or "IW-9 行动后" (IW stands for activity "将进酒").

type StoryRepo

type StoryRepo struct {
	infra.Repo
}

func NewStoryRepo

func NewStoryRepo(db *bun.DB) (*StoryRepo, error)

func (*StoryRepo) GetStories

func (r *StoryRepo) GetStories(ctx context.Context) ([]StoryModel, error)

func (*StoryRepo) GetStoryByID

func (r *StoryRepo) GetStoryByID(ctx context.Context, id string) (*StoryModel, error)

func (*StoryRepo) InsertStories

func (r *StoryRepo) InsertStories(ctx context.Context, stories []StoryModel) error

func (*StoryRepo) Truncate

func (r *StoryRepo) Truncate(ctx context.Context) (err error)

type VersionRepo

type VersionRepo struct {
	infra.Repo
}

func NewVersionRepo

func NewVersionRepo(db *bun.DB) (*VersionRepo, error)

func (*VersionRepo) GetVersion

func (r *VersionRepo) GetVersion(ctx context.Context) (string, error)

func (*VersionRepo) UpsertVersion

func (r *VersionRepo) UpsertVersion(ctx context.Context, resVersion string) error

Jump to

Keyboard shortcuts

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