domain

package
v0.20.12 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 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 AccessToken added in v0.18.0

type AccessToken struct {
	ExpiredAt time.Time
	CreatedAt time.Time
	Name      string
	ClientID  string
	ID        uint32
	UserID    model.UserID
}

type Auth

type Auth struct {
	RegTime    time.Time
	ID         model.UserID // user id
	GroupID    model.UserGroupID
	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)

	CreateAccessToken(
		ctx context.Context, userID model.UserID, name string, expiration time.Duration,
	) (token string, err error)

	ListAccessToken(ctx context.Context, userID model.UserID) ([]AccessToken, error)
	DeleteAccessToken(ctx context.Context, tokenID uint32) (bool, error)

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

AuthRepo presents an authorization.

type AuthService

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

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

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

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

	GetTokenByID(ctx context.Context, tokenID uint32) (AccessToken, error)
	CreateAccessToken(
		ctx context.Context, userID model.UserID, name string, expiration time.Duration,
	) (token string, err error)
	ListAccessToken(ctx context.Context, userID model.UserID) ([]AccessToken, error)
	DeleteAccessToken(ctx context.Context, tokenID uint32) (bool, error)

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

type CharacterRepo

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

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

type CharacterService

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

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

type CollectionRepo added in v0.20.9

type CollectionRepo interface {
	CountSubjectCollections(
		ctx context.Context,
		userID model.UserID,
		subjectType model.SubjectType,
		collectionType model.CollectionType,
		showPrivate bool,
	) (int64, error)

	ListSubjectCollection(
		ctx context.Context,
		userID model.UserID,
		subjectType model.SubjectType,
		collectionType model.CollectionType,
		showPrivate bool,
		limit, offset int,
	) ([]model.SubjectCollection, error)

	GetSubjectCollection(
		ctx context.Context, userID model.UserID, subjectID model.SubjectID,
	) (model.SubjectCollection, error)
}

type EpisodeRepo

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

	// Count all episode for a subject.
	Count(ctx context.Context, subjectID model.SubjectID) (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 model.SubjectID, epType model.EpType) (int64, error)

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

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

type GroupMemberType added in v0.20.9

type GroupMemberType uint8
const (
	GroupMemberAll GroupMemberType = 1 << iota / 2
	GroupMemberMod
	GroupMemberNormal
)

type GroupRepo added in v0.20.9

type GroupRepo interface {
	GetByName(ctx context.Context, name string) (model.Group, error)

	CountMembersByID(ctx context.Context, id model.GroupID, memberType GroupMemberType) (int64, error)
	ListMembersByID(
		ctx context.Context, id model.GroupID, memberType GroupMemberType, limit, offset int,
	) ([]model.GroupMember, error)
}

type IndexRepo

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

	CountSubjects(ctx context.Context, id model.IndexID, subjectType model.SubjectType) (int64, error)
	ListSubjects(
		ctx context.Context, id model.IndexID, 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.CharacterID
	PersonID    model.PersonID
	SubjectID   model.SubjectID
}

type PersonRepo

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

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

type PersonService

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

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

type RevisionRepo

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

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

	GetPersonRelated(ctx context.Context, id model.RevisionID) (model.PersonRevision, error)

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

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

	GetSubjectRelated(ctx context.Context, id model.RevisionID) (model.SubjectRevision, error)

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

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

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

type SubjectCharacterRelation

type SubjectCharacterRelation struct {
	TypeID uint8

	SubjectID   model.SubjectID
	CharacterID model.CharacterID
}

type SubjectInternalRelation

type SubjectInternalRelation struct {
	TypeID uint16

	SourceID      model.SubjectID
	DestinationID model.SubjectID
}

type SubjectPersonRelation

type SubjectPersonRelation struct {
	TypeID uint16

	PersonID  model.PersonID
	SubjectID model.SubjectID
}

type SubjectRepo

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

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

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

type SubjectService

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

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

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

type UserRepo

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

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

Jump to

Keyboard shortcuts

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