domain

package
v0.0.0-...-4e6b843 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrObjectAlreadyExists = errors.New("object already exists")
	ErrObjectNotFound      = errors.New("object not found")

	ErrUserNotFound        = errors.New("user not found")
	ErrFriendNotFound      = errors.New("friend not found")
	ErrFriendAlreadyExists = errors.New("friend already exists")
)

Functions

func HashPassword

func HashPassword(password string) string

Types

type BlacklistRepository

type BlacklistRepository interface {
	NewSerial() (string, error)
	AddToBlacklist(serial string, expireDate time.Time) error
	IsBlacklisted(serial string) (bool, error)
}

type EventInvalidateCache

type EventInvalidateCache struct {
	UserID    UserKey   `json:"user_id"`
	EventType EventType `json:"event_type"`
}

EventInvalidateCache представляет структуру события для Kafka.

type EventType

type EventType string

EventType определяет тип события.

const (
	EventPostCreated EventType = "post_created" // Пост создан
	EventPostEdited  EventType = "post_edited"  // Пост отредактирован
	EventPostDeleted EventType = "post_deleted" // Пост удален
	EventFeedRefresh EventType = "feed_refresh" // Лента нуждается в пересчете
)

Возможные значения EventType.

type JWTService

type JWTService interface {
	GenerateToken(userID UserKey, permissions []Permission) (TokenString, error)
	ValidateToken(tokenString TokenString) (*jwt.Token, error)
	RevokeToken(token *jwt.Token) error
	ExtractClaims(token *jwt.Token) (*UserClaims, error)
}

type Permission

type Permission string
const (
	PermissionUserGet Permission = "USER_GET"
)

type Post

type Post struct {
	Id         PostKey
	UserId     UserKey
	Message    PostMessage
	CreatedAt  time.Time
	ModifiedAt *time.Time
}

type PostCache

type PostCache interface {
	GetFeed(userId UserKey, limit int) ([]*Post, error)
	UpdateFeed(userId UserKey, posts []*Post) error
}

type PostKey

type PostKey int64

type PostMessage

type PostMessage string

type PostRepository

type PostRepository interface {
	List(userId UserKey, limit int, lastPostId PostKey) ([]*Post, error)
	Create(userId UserKey, message PostMessage) (PostKey, error)
	Get(postId PostKey) (*Post, error)
	GetPostOwner(postId PostKey) (UserKey, error)
	UpdateMessage(postId PostKey, newMessage PostMessage) error
	Delete(id PostKey) error
	GetFeed(userId UserKey, limit int) ([]*Post, error)
}

type Sex

type Sex byte
const (
	Male Sex = iota
	Female
)

type SocialNetworkService

type SocialNetworkService interface {
	CreateUser(user *User) (UserKey, error)
	GetUser(id UserKey) (*User, error)
	Search(firstName, lastName string) ([]*User, error)
	Login(username, password string) (TokenString, error)
	AddFriend(my_id, friend_id UserKey) error
	RemoveFriend(my_id, friend_id UserKey) error
	Logout(token *jwt.Token) error
	ListPosts(userId UserKey, limit int, lastPostId PostKey) ([]*Post, error)
	CreatePost(userId UserKey, message PostMessage) (PostKey, error)
	GetPost(userId UserKey, postId PostKey) (*Post, error)
	UpdatePost(userId UserKey, postId PostKey, newMessage PostMessage) error
	DeletePost(userId UserKey, postId PostKey) error
	GetFeed(userId UserKey) ([]*Post, error)
	SetLastActivity(userId UserKey) error
}

type TokenString

type TokenString string

type User

type User struct {
	ID           UserKey   `json:"id"`
	FirstName    string    `json:"first_name"`
	LastName     string    `json:"last_name"`
	Sex          Sex       `json:"sex"`
	Birthdate    time.Time `json:"birthdate"`
	Biography    string    `json:"biography"`
	City         string    `json:"city"`
	Username     string    `json:"username"`
	PasswordHash string    `json:"-"` // Не экспортируем пароль через API
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

func (*User) CheckPassword

func (u *User) CheckPassword(password string) bool

func (*User) SetPassword

func (u *User) SetPassword(password string)

type UserClaims

type UserClaims struct {
	Permissions []Permission `json:"permissions"`
	jwt.RegisteredClaims
}

UserClaims - структура для хранения кастомных claims

type UserKey

type UserKey string

type UserLastActivity

type UserLastActivity struct {
	ID           UserKey   `json:"id"`
	LastActivity time.Time `json:"last_activity"`
}

type UserRepository

type UserRepository interface {
	RegisterUser(user *User) (UserKey, error)
	GetByID(id UserKey) (*User, error)
	GetByUsername(username string) (*User, error)
	Search(firstName, lastName string) ([]*User, error)
	AddFriend(my_id, friend_id UserKey) error
	RemoveFriend(my_id, friend_id UserKey) error
	GetFriendsIds(id UserKey) ([]UserKey, error)
	SetLastActivity(id UserKey) error
	GetUsersActiveSince(period time.Duration) ([]UserKey, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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