domain

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2022 License: AGPL-3.0, AGPL-3.0-only Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCharacterNotFound = errgo.MsgNoTrace(ErrNotFound, "character not found")
View Source
var ErrEpisodeNotFound = errgo.MsgNoTrace(ErrNotFound, "episode not found")
View Source
var ErrExists = errors.New("item already exists")
View Source
var ErrInput = errors.New("input not valid")
View Source
var ErrNotFound = errors.New("can't find item")

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

View Source
var ErrPersonNotFound = errgo.MsgNoTrace(ErrNotFound, "person not found")
View Source
var ErrPmDeleted = errors.New("private message deleted")
View Source
var ErrPmInvalidOperation = errors.New("invalid operation")
View Source
var ErrPmNotOwned = errors.New("not sent or received this private message")
View Source
var ErrPmRelatedNotExists = errors.New("related private message not exists")
View Source
var ErrPmUserIrrelevant = errors.New("has user irrelevant message")
View Source
var ErrSubjectNotCollected = errgo.MsgNoTrace(ErrNotFound, "subject is not collected by user")
View Source
var ErrSubjectNotFound = errgo.MsgNoTrace(ErrNotFound, "subject not found")
View Source
var ErrUserNotFound = errgo.MsgNoTrace(ErrNotFound, "user not found")

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.

func (Auth) RegisteredLongerThan added in v0.22.0

func (u Auth) RegisteredLongerThan(t time.Duration) bool

type AuthRepo

type AuthRepo interface {
	// GetByToken return an authorized user by a valid access token.
	GetByToken(ctx context.Context, token string) (AuthUserInfo, 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) (AuthUserInfo, []byte, error)
	GetTokenByID(ctx context.Context, id uint32) (AccessToken, error)
}

AuthRepo presents an authorization.

type AuthService

type AuthService interface {
	GetByToken(ctx context.Context, token string) (Auth, error)
	GetByID(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)
}

type AuthUserInfo added in v0.22.1

type AuthUserInfo struct {
	RegTime time.Time
	ID      model.UserID
	GroupID model.UserGroupID
}

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 CollectionRepo added in v0.20.9

type CollectionRepo interface {
	// WithQuery is used to replace repo's query to txn
	WithQuery(query *query.Query) CollectionRepo
	CountSubjectCollections(
		ctx context.Context,
		userID model.UserID,
		subjectType model.SubjectType,
		collectionType model.SubjectCollection,
		showPrivate bool,
	) (int64, error)

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

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

	GetSubjectEpisodesCollection(
		ctx context.Context, userID model.UserID, subjectID model.SubjectID,
	) (model.UserSubjectEpisodesCollection, error)

	UpdateSubjectCollection(
		ctx context.Context, userID model.UserID, subjectID model.SubjectID, data SubjectCollectionUpdate,
		at time.Time,
	) error

	UpdateEpisodeCollection(
		ctx context.Context,
		userID model.UserID, subjectID model.SubjectID,
		episodeIDs []model.EpisodeID, collection model.EpisodeCollection,
		at time.Time,
	) (model.UserSubjectEpisodesCollection, error)
}

type CommentType added in v0.22.0

type CommentType uint32
const (
	CommentTypeUnknown CommentType = iota
	CommentTypeSubjectTopic
	CommentTypeGroupTopic
	CommentIndex
	CommentCharacter
	CommentPerson
	CommentEpisode
)

type EpisodeFilter added in v0.23.7

type EpisodeFilter struct {
	Type null.Null[model.EpType]
}

type EpisodeRepo

type EpisodeRepo interface {
	// WithQuery is used to replace repo's query to txn
	WithQuery(query *query.Query) EpisodeRepo

	Get(ctx context.Context, episodeID model.EpisodeID) (model.Episode, error)

	// Count all episode for a subject.
	Count(ctx context.Context, subjectID model.SubjectID, filter EpisodeFilter) (int64, error)

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

type FriendItem added in v0.23.0

type FriendItem struct{}

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)
	GetByID(ctx context.Context, id model.GroupID) (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)
	New(ctx context.Context, i *model.Index) error
	Update(ctx context.Context, id model.IndexID, title string, desc string) error
	Delete(ctx context.Context, id model.IndexID) 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)
	AddOrUpdateIndexSubject(
		ctx context.Context, id model.IndexID, subjectID model.SubjectID, sort uint32, comment string,
	) (*IndexSubject, error)
	DeleteIndexSubject(
		ctx context.Context, id model.IndexID, subjectID model.SubjectID,
	) error
}

type IndexSubject

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

type NotificationRepo added in v0.29.0

type NotificationRepo interface {
	Count(ctx context.Context,
		userID model.UserID) (int64, error)
}

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
	BanPost            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 PrivateMessageIDFilter added in v0.29.0

type PrivateMessageIDFilter struct {
	Type null.Null[model.PrivateMessageID]
}

type PrivateMessageRepo added in v0.29.0

type PrivateMessageRepo interface {
	List(
		ctx context.Context,
		userID model.UserID,
		folder model.PrivateMessageFolderType,
		offset int,
		limit int,
	) ([]model.PrivateMessageListItem, error)

	CountByFolder(
		ctx context.Context,
		userID model.UserID,
		folder model.PrivateMessageFolderType,
	) (int64, error)

	ListRelated(
		ctx context.Context,
		userID model.UserID,
		id model.PrivateMessageID,
	) ([]model.PrivateMessage, error)

	CountTypes(ctx context.Context, userID model.UserID) (model.PrivateMessageTypeCounts, error)

	MarkRead(ctx context.Context, userID model.UserID, relatedID model.PrivateMessageID) error

	ListRecentContact(ctx context.Context, userID model.UserID) ([]model.UserID, error)

	Create(
		ctx context.Context,
		senderID model.UserID,
		receiverIDs []model.UserID,
		relatedIDFilter PrivateMessageIDFilter,
		title string,
		content string,
	) ([]model.PrivateMessage, error)

	Delete(
		ctx context.Context,
		userID model.UserID,
		ids []model.PrivateMessageID,
	) 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)

	CountEpisodeRelated(ctx context.Context, episodeID model.EpisodeID) (int64, error)

	ListEpisodeRelated(
		ctx context.Context, episodeID model.EpisodeID, limit int, offset int,
	) ([]model.EpisodeRevision, error)

	GetEpisodeRelated(ctx context.Context, id model.RevisionID) (model.EpisodeRevision, error)
}

type SubjectCharacterRelation

type SubjectCharacterRelation struct {
	TypeID uint8

	SubjectID   model.SubjectID
	CharacterID model.CharacterID
}

type SubjectCollectionUpdate added in v0.23.8

type SubjectCollectionUpdate struct {
	IP string

	Comment   null.String
	Tags      []string // nil 表示无数据,[]string{} 表示清空tag
	VolStatus null.Uint32
	EpStatus  null.Uint32
	Type      null.Null[model.SubjectCollection]
	Rate      null.Uint8
	Privacy   null.Null[model.CollectPrivacy]
}

type SubjectInternalRelation

type SubjectInternalRelation struct {
	TypeID uint16

	SourceID      model.SubjectID
	DestinationID model.SubjectID
}

func (SubjectInternalRelation) GetSourceID added in v0.22.0

func (s SubjectInternalRelation) GetSourceID() model.SubjectID

type SubjectPersonRelation

type SubjectPersonRelation struct {
	TypeID uint16

	PersonID  model.PersonID
	SubjectID model.SubjectID
}

type TimeLineRepo added in v0.25.7

type TimeLineRepo interface {
	// WithQuery is used to replace repo's query to txn
	WithQuery(query *query.Query) TimeLineRepo
	GetByID(ctx context.Context, id model.TimeLineID) (*model.TimeLine, error)
	ListByUID(ctx context.Context, uid model.UserID, limit int, since model.TimeLineID) ([]*model.TimeLine, error)
	Create(ctx context.Context, tl *model.TimeLine) error
}

type TopicRepo added in v0.22.0

type TopicRepo interface {
	Get(ctx context.Context, topicType TopicType, id model.TopicID) (model.Topic, error)

	// Count all topic for a subject/group.
	Count(ctx context.Context, topicType TopicType, id uint32, displays []model.TopicDisplay) (int64, error)

	// List return paged topic list of a subject/group.
	// userID should not be filtered
	List(
		ctx context.Context,
		topicType TopicType,
		id uint32,
		displays []model.TopicDisplay,
		limit int, offset int,
	) ([]model.Topic, error)

	GetTopicContent(ctx context.Context, topicType TopicType, id model.TopicID) (model.Comment, error)

	// CountReplies top comments for a topic/index/character/person/episode.
	// 一级回复
	// 小组和条目帖子会去除楼主发帖
	CountReplies(ctx context.Context, commentType CommentType, id model.TopicID) (int64, error)

	// ListReplies return paged top comment tree.
	//
	//  []model.Comment{
	//    一级回复
	// 		{
	//  	  一级回复对应的 **全部** 二级回复
	//	 		SubComments: []model.SubComments{}
	// 		}
	// }
	ListReplies(
		ctx context.Context, commentType CommentType, id model.TopicID, limit int, offset int,
	) ([]model.Comment, error)
}

type TopicType added in v0.22.0

type TopicType uint32
const (
	TopicTypeUnknown TopicType = iota
	TopicTypeSubject
	TopicTypeGroup
)

func (TopicType) Zap added in v0.27.1

func (t TopicType) Zap() zap.Field

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)

	GetFriends(ctx context.Context, userID model.UserID) (map[model.UserID]FriendItem, error)

	CheckIsFriendToOthers(ctx context.Context, selfID model.UserID, otherIDs ...model.UserID) (bool, error)

	GetFieldsByIDs(ctx context.Context, ids []model.UserID) (map[model.UserID]model.UserFields, error)
}

Jump to

Keyboard shortcuts

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