domain

package
v0.16.6 Latest Latest
Warning

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

Go to latest
Published: May 28, 2022 License: AGPL-3.0, AGPL-3.0-only Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("can't find item")

ErrNotFound should be returned when a repo or service can't find an authorization.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	RegTime    time.Time
	ID         model.UIDType // user id
	GroupID    model.GroupID
	Permission Permission `json:"-"` // disable cache for this field.
}

Auth is the basic authorization represent a user.

func (Auth) AllowNSFW

func (u Auth) AllowNSFW() bool

AllowNSFW return if current user is allowed to see NSFW resource.

type AuthRepo

type AuthRepo interface {
	// GetByToken return an authorized user by a valid access token.
	GetByToken(ctx context.Context, token string) (Auth, error)
	GetPermission(ctx context.Context, groupID uint8) (Permission, error)

	// GetByEmail return (Auth, HashedPassword, error)
	GetByEmail(ctx context.Context, email string) (Auth, []byte, error)
}

AuthRepo presents an authorization.

type AuthService

type AuthService interface {
	GetByID(ctx context.Context, userID model.UIDType) (Auth, error)
	GetByToken(ctx context.Context, token string) (Auth, error)

	GetByTokenWithCache(ctx context.Context, token string) (Auth, error)
	GetByIDWithCache(ctx context.Context, userID model.UIDType) (Auth, error)

	ComparePassword(hashed []byte, password string) (bool, error)

	Login(ctx context.Context, email, password string) (Auth, bool, error)

	GetPermission(ctx context.Context, id model.GroupID) (Permission, error)
}

type CharacterRepo

type CharacterRepo interface {
	Get(ctx context.Context, id model.CharacterIDType) (model.Character, error)
	GetByIDs(ctx context.Context, ids ...model.CharacterIDType) (map[model.CharacterIDType]model.Character, error)

	GetPersonRelated(ctx context.Context, personID model.PersonIDType) ([]PersonCharacterRelation, error)
	GetSubjectRelated(ctx context.Context, subjectID model.SubjectIDType) ([]SubjectCharacterRelation, error)
}

type CharacterService

type CharacterService interface {
	Get(ctx context.Context, id uint32) (model.Character, error)

	GetPersonRelated(ctx context.Context, personID model.PersonIDType) ([]model.PersonCharacterRelation, error)
	GetSubjectRelated(ctx context.Context, subjectID model.SubjectIDType) ([]model.SubjectCharacterRelation, error)
}

type EpisodeRepo

type EpisodeRepo interface {
	Get(ctx context.Context, episodeID uint32) (model.Episode, error)

	// Count all episode for a subject.
	Count(ctx context.Context, subjectID uint32) (int64, error)

	// CountByType count episode for a subject and filter by type.
	// This is because 0 means episode type normal.
	CountByType(ctx context.Context, subjectID uint32, epType model.EpTypeType) (int64, error)

	// List return all episode.
	List(ctx context.Context, subjectID uint32, limit int, offset int) ([]model.Episode, error)

	// ListByType return episodes filtered by episode type.
	ListByType(
		ctx context.Context, subjectID uint32, epType enum.EpType, limit int, offset int,
	) ([]model.Episode, error)
}

type IndexRepo

type IndexRepo interface {
	Get(ctx context.Context, id uint32) (model.Index, error)

	CountSubjects(ctx context.Context, id uint32, subjectType model.SubjectType) (int64, error)
	ListSubjects(
		ctx context.Context, id uint32, subjectType model.SubjectType, limit, offset int,
	) ([]IndexSubject, error)
}

type IndexSubject

type IndexSubject struct {
	Comment string
	AddedAt time.Time
	Subject model.Subject
}

type Permission

type Permission struct {
	UserList           bool
	ManageUserGroup    bool
	ManageUserPhoto    bool
	ManageTopicState   bool
	ManageReport       bool
	UserBan            bool
	ManageUser         bool
	UserGroup          bool
	UserWikiApply      bool `doc:"申请 wiki 人"`
	UserWikiApprove    bool
	DoujinSubjectErase bool
	DoujinSubjectLock  bool
	SubjectEdit        bool
	SubjectLock        bool
	SubjectRefresh     bool
	SubjectRelated     bool
	SubjectMerge       bool
	SubjectErase       bool
	SubjectCoverLock   bool
	SubjectCoverErase  bool
	MonoEdit           bool
	MonoLock           bool
	MonoMerge          bool
	MonoErase          bool
	EpEdit             bool
	EpMove             bool
	EpMerge            bool
	EpLock             bool
	EpErase            bool
	Report             bool
	ManageApp          bool
	AppErase           bool
}

type PersonCharacterRelation

type PersonCharacterRelation struct {
	CharacterID model.CharacterIDType
	PersonID    model.PersonIDType
	SubjectID   model.SubjectIDType
}

type PersonRepo

type PersonRepo interface {
	Get(ctx context.Context, id uint32) (model.Person, error)
	GetByIDs(ctx context.Context, ids ...model.PersonIDType) (map[model.PersonIDType]model.Person, error)

	GetSubjectRelated(ctx context.Context, subjectID model.SubjectIDType) ([]SubjectPersonRelation, error)
	GetCharacterRelated(ctx context.Context, subjectID model.CharacterIDType) ([]PersonCharacterRelation, error)
}

type PersonService

type PersonService interface {
	Get(ctx context.Context, id uint32) (model.Person, error)

	GetSubjectRelated(ctx context.Context, subjectID model.SubjectIDType) ([]model.SubjectPersonRelation, error)
	GetCharacterRelated(ctx context.Context, characterID model.CharacterIDType) ([]model.PersonCharacterRelation, error)
}

type RevisionRepo

type RevisionRepo interface {
	CountPersonRelated(ctx context.Context, personID model.PersonIDType) (int64, error)

	ListPersonRelated(
		ctx context.Context, personID model.PersonIDType, limit int, offset int,
	) ([]model.Revision, error)

	GetPersonRelated(ctx context.Context, id model.UIDType) (model.Revision, error)

	CountSubjectRelated(ctx context.Context, id model.SubjectIDType) (int64, error)

	ListSubjectRelated(
		ctx context.Context, id model.SubjectIDType, limit int, offset int,
	) ([]model.Revision, error)

	GetSubjectRelated(ctx context.Context, id model.UIDType) (model.Revision, error)

	CountCharacterRelated(ctx context.Context, characterID model.CharacterIDType) (int64, error)

	ListCharacterRelated(
		ctx context.Context, characterID model.CharacterIDType, limit int, offset int,
	) ([]model.CharacterRevision, error)

	GetCharacterRelated(ctx context.Context, id model.UIDType) (model.CharacterRevision, error)
}

type SubjectCharacterRelation

type SubjectCharacterRelation struct {
	TypeID uint8

	SubjectID   model.SubjectIDType
	CharacterID model.CharacterIDType
}

type SubjectInternalRelation

type SubjectInternalRelation struct {
	TypeID uint16

	SourceID      model.SubjectIDType
	DestinationID model.SubjectIDType
}

type SubjectPersonRelation

type SubjectPersonRelation struct {
	TypeID uint16

	PersonID  model.PersonIDType
	SubjectID model.SubjectIDType
}

type SubjectRepo

type SubjectRepo interface {
	// Get return a repository model.
	Get(ctx context.Context, id uint32) (model.Subject, error)
	GetByIDs(ctx context.Context, ids ...model.SubjectIDType) (map[model.SubjectIDType]model.Subject, error)

	GetPersonRelated(ctx context.Context, personID model.PersonIDType) ([]SubjectPersonRelation, error)
	GetCharacterRelated(ctx context.Context, characterID model.PersonIDType) ([]SubjectCharacterRelation, error)
	GetSubjectRelated(ctx context.Context, subjectID model.SubjectIDType) ([]SubjectInternalRelation, error)

	GetActors(
		ctx context.Context, subjectID model.SubjectIDType, characterIDs ...model.CharacterIDType,
	) (map[model.CharacterIDType][]model.Person, error)
}

type SubjectService

type SubjectService interface {
	// Get return a repository model.
	Get(ctx context.Context, id uint32) (model.Subject, error)

	GetPersonRelated(ctx context.Context, personID model.PersonIDType) ([]model.SubjectPersonRelation, error)
	GetCharacterRelated(ctx context.Context, characterID model.PersonIDType) ([]model.SubjectCharacterRelation, error)
	GetSubjectRelated(ctx context.Context, subjectID model.SubjectIDType) ([]model.SubjectInternalRelation, error)

	GetActors(
		ctx context.Context, subjectID model.SubjectIDType, characterIDs ...model.CharacterIDType,
	) (map[model.CharacterIDType][]model.Person, error)
}

type UserRepo

type UserRepo interface {
	// GetByID find a user by uid.
	GetByID(ctx context.Context, userID model.UIDType) (model.User, error)
	// GetByName find a user by username.
	GetByName(ctx context.Context, username string) (model.User, error)

	GetByIDs(ctx context.Context, ids ...model.UIDType) (map[model.UIDType]model.User, error)

	CountCollections(
		ctx context.Context,
		userID model.UIDType,
		subjectType model.SubjectType,
		collectionType uint8,
		showPrivate bool,
	) (int64, error)

	ListCollections(
		ctx context.Context,
		userID model.UIDType,
		subjectType model.SubjectType,
		collectionType uint8,
		showPrivate bool,
		limit, offset int,
	) ([]model.Collection, error)

	GetCollection(ctx context.Context, userID model.UIDType, subjectID model.SubjectIDType) (model.Collection, error)
}

Jump to

Keyboard shortcuts

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