users

package
v0.0.0-...-7b55a8f Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparePassword

func ComparePassword(plain, hashed string) error

func HashPassword

func HashPassword(pwd string) (string, error)

Types

type Feed

type Feed struct {
	ID        string    `db:"id"         json:"id"`
	UserID    string    `db:"user_id"    json:"user_id"`
	PostID    string    `db:"post_id"    json:"post_id"`
	CreatedAt time.Time `db:"created_at" json:"created_at"`
}

type FeedPage

type FeedPage struct {
	Page
	Feeds []Feed `json:"feeds"`
}

func (FeedPage) MarshalJSON

func (page FeedPage) MarshalJSON() ([]byte, error)

type FeedRepository

type FeedRepository interface {
	Create(ctx context.Context, feed Feed) error
	RetrieveAll(ctx context.Context, page Page) (FeedPage, error)
}

type Following

type Following struct {
	ID         string    `db:"id"          json:"id"`
	FollowerID string    `db:"follower_id" json:"follower_id"`
	FolloweeID string    `db:"followee_id" json:"followee_id"`
	CreatedAt  time.Time `db:"created_at"  json:"created_at"`
}

type FollowingRepository

type FollowingRepository interface {
	Create(ctx context.Context, following Following) (Following, error)
	RetrieveAll(ctx context.Context, page Page) (FollowingsPage, error)
	Delete(ctx context.Context, following Following) error
}

type FollowingsPage

type FollowingsPage struct {
	Page
	Followings []Following `json:"followings"`
}

type Page

type Page struct {
	Total      uint64 `db:"total"       json:"total"`
	Offset     uint64 `db:"offset"      json:"offset"`
	Limit      uint64 `db:"limit"       json:"limit"`
	FollowerID string `db:"follower_id" json:"follower_id,omitempty"`
	FolloweeID string `db:"followee_id" json:"followee_id,omitempty"`
	UserID     string `db:"user_id"     json:"user_id,omitempty"`
}

type Preference

type Preference struct {
	ID          string    `json:"id"`
	UserID      string    `json:"user_id"`
	EmailEnable bool      `json:"email_enabled"`
	PushEnable  bool      `json:"push_enabled"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

func (Preference) FromKV

func (p Preference) FromKV(key, value string) error

func (Preference) KV

func (p Preference) KV() (string, string, error)

type PreferencesPage

type PreferencesPage struct {
	Page
	Preferences []Preference `json:"preferences"`
}

func (PreferencesPage) MarshalJSON

func (page PreferencesPage) MarshalJSON() ([]byte, error)

type PreferencesRepository

type PreferencesRepository interface {
	Create(ctx context.Context, preference Preference) (Preference, error)
	RetrieveByUserID(ctx context.Context, userID string) (Preference, error)
	RetrieveAll(ctx context.Context, page Page) (PreferencesPage, error)
	Update(ctx context.Context, preference Preference) (Preference, error)
	UpdateEmail(ctx context.Context, preference Preference) (Preference, error)
	UpdatePush(ctx context.Context, preference Preference) (Preference, error)
	Delete(ctx context.Context, userID string) error
}

type Service

type Service interface {
	IssueToken(ctx context.Context, user User) (string, error)
	RefreshToken(ctx context.Context, token string) (string, error)
	IdentifyUser(ctx context.Context, token string) (string, error)

	CreateUser(ctx context.Context, user User) (User, error)
	GetUserByID(ctx context.Context, token string, id string) (User, error)
	GetUsers(ctx context.Context, token string, page Page) (UsersPage, error)
	UpdateUser(ctx context.Context, token string, user User) (User, error)
	UpdateUserUsername(ctx context.Context, token string, user User) (User, error)
	UpdateUserPassword(ctx context.Context, token string, oldPassword, currentPassowrd string) error
	UpdateUserEmail(ctx context.Context, token string, user User) (User, error)
	UpdateUserBio(ctx context.Context, token string, user User) (User, error)
	UpdateUserPictureURL(ctx context.Context, token string, user User) (User, error)
	UpdateUserPreferences(ctx context.Context, token string, user User) (User, error)
	DeleteUser(ctx context.Context, token string, id string) error

	CreatePreferences(ctx context.Context, token string, preference Preference) (Preference, error)
	GetPreferencesByUserID(ctx context.Context, token, id string) (Preference, error)
	GetPreferences(ctx context.Context, token string, page Page) (PreferencesPage, error)
	UpdatePreferences(ctx context.Context, token string, preference Preference) (Preference, error)
	UpdateEmailPreferences(ctx context.Context, token string, preference Preference) (Preference, error)
	UpdatePushPreferences(ctx context.Context, token string, preference Preference) (Preference, error)
	DeletePreferences(ctx context.Context, token string) error

	CreateFollower(ctx context.Context, token string, following Following) (Following, error)
	GetUserFollowings(ctx context.Context, token string, page Page) (FollowingsPage, error)
	DeleteFollower(ctx context.Context, token string, following Following) error

	CreateFeed(ctx context.Context, feed Feed) error
	GetUserFeed(ctx context.Context, token string, page Page) (FeedPage, error)
}

func NewService

func NewService(usersRepo UsersRepository, preferencesRepo PreferencesRepository, followingRepo FollowingRepository, feedRepo FeedRepository, tokenizer Tokenizer, cacher cache.Cacher) Service

type Tokenizer

type Tokenizer interface {
	Issue(userID string) (string, error)
	Validate(token string) (string, error)
}

type User

type User struct {
	ID          string    `json:"id"`
	Username    string    `json:"username"`
	DisplayName string    `json:"display_name"`
	Bio         string    `json:"bio,omitempty"`
	PictureURL  string    `json:"picture_url,omitempty"`
	Email       string    `json:"email"`
	Password    string    `json:"password,omitempty"`
	Preferences []string  `json:"preferences,omitempty"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

func (User) FromKV

func (u User) FromKV(key, value string) error

func (User) KV

func (u User) KV() (string, string, error)

type UsersPage

type UsersPage struct {
	Page
	Users []User `json:"users"`
}

func (UsersPage) MarshalJSON

func (page UsersPage) MarshalJSON() ([]byte, error)

type UsersRepository

type UsersRepository interface {
	Create(ctx context.Context, user User) (User, error)
	RetrieveByID(ctx context.Context, id string) (User, error)
	RetrieveByEmail(ctx context.Context, email string) (User, error)
	RetrieveAll(ctx context.Context, page Page) (UsersPage, error)
	Update(ctx context.Context, user User) (User, error)
	UpdateUsername(ctx context.Context, user User) (User, error)
	UpdatePassword(ctx context.Context, user User) error
	UpdateEmail(ctx context.Context, user User) (User, error)
	UpdateBio(ctx context.Context, user User) (User, error)
	UpdatePictureURL(ctx context.Context, user User) (User, error)
	UpdatePreferences(ctx context.Context, user User) (User, error)
	Delete(ctx context.Context, id string) error
}

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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