domain

package
v0.1.0-2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUserIdFromContext

func GetUserIdFromContext(ctx context.Context) uuid.UUID

Get user from context

func SetUserInContext

func SetUserInContext(ctx context.Context, userId uuid.UUID) context.Context

SetUserInContext sets the user in the context

Types

type AccessToken

type AccessToken struct {
	Id             uuid.UUID `json:"id"`
	UserId         uuid.UUID `json:"user_id"`
	RefreshTokenId uuid.UUID `json:"refresh_token_id"`
	CreateTime     time.Time `json:"create_time"`
	UpdateTime     time.Time `json:"update_time"`
}

func NewAccessToken

func NewAccessToken(userId uuid.UUID, refreshTokenId uuid.UUID) *AccessToken

NewAccessToken creates a new AccessToken instance

type AccessTokenCacheDs

type AccessTokenCacheDs interface {
	GetAccessTokenById(ctx context.Context, id uuid.UUID) (*AccessToken, error)
	CreateAccessToken(ctx context.Context, accessToken *AccessToken) error
	DeleteAccessToken(ctx context.Context, id uuid.UUID) error
}

type AccessTokenDatabaseDs

type AccessTokenDatabaseDs interface {
	GetAccessTokenById(ctx context.Context, id uuid.UUID) (*AccessToken, error)
	CreateAccessToken(ctx context.Context, accessToken *AccessToken) (*AccessToken, error)
	DeleteAccessTokenByUserId(ctx context.Context, userId uuid.UUID) (*uuid.UUID, error)
}

type AccessTokenRepository

type AccessTokenRepository interface {
	GetAccessToken(ctx context.Context, id uuid.UUID) (*AccessToken, error)
	CreateAccessToken(ctx context.Context, userId uuid.UUID, refreshTokenId uuid.UUID) (*AccessToken, error)
	DeleteAccessTokenByUserId(ctx context.Context, userId uuid.UUID) error
}

func NewAccessTokenRepository

func NewAccessTokenRepository(accessTokenCacheDs AccessTokenCacheDs, accessTokenDatabaseDs AccessTokenDatabaseDs) AccessTokenRepository

type CustomClaims

type CustomClaims struct {
	UserID string `json:"user_id"`
	jwt.StandardClaims
}

CustomClaims defines the structure of the JWT claims

type HashDatasource

type HashDatasource interface {
	// Hash takes a string value and returns its hash representation.
	// It returns an error if the hashing operation fails.
	Hash(value string) (string, error)
	// CheckHash verifies if the given hash matches the hash of the provided value.
	// It returns true if the hash matches, false otherwise.
	CheckHash(value, hash string) (bool, error)
}

HashDatasource defines the methods for hashing values and checking hashes. Implementations of this interface should provide mechanisms to hash values and verify if a given hash matches a hashed value.

type JWTMetadata

type JWTMetadata struct {
	TokenId uuid.UUID
	UserId  uuid.UUID
	Token   string
}

type JwtDatasource

type JwtDatasource interface {
	CreateJWT(tokenMetadata *JWTMetadata, expirationTime time.Time) (*string, error)
	ParseJWT(tokenMetadata *JWTMetadata) error
}

func NewJWTDatasource

func NewJWTDatasource(cfg *config.Configuration) JwtDatasource

type Note

type Note struct {
	Id         uuid.UUID `json:"id"`
	UserId     uuid.UUID `json:"user_id"`
	Title      string    `json:"title"`
	Content    string    `json:"content"`
	CreateTime time.Time `json:"create_time"`
	UpdateTime time.Time `json:"update_time"`
	DeleteTime time.Time `json:"delete_time"`
}

type NoteCacheDs

type NoteCacheDs interface {
	// ListNote(ctx context.Context) (*[]Note, error)
	// GetNote(ctx context.Context, id uuid.UUID) (*Note, error)
	CreateNote(ctx context.Context, note *Note) error
}

type NoteDatabaseDs

type NoteDatabaseDs interface {
	ListNotesByUser(ctx context.Context, user_id uuid.UUID, cursor time.Time) (*[]Note, error)
	ListTrashNotesByUser(ctx context.Context, user_id uuid.UUID, cursor time.Time) (*[]Note, error)
	GetNote(ctx context.Context, id uuid.UUID) (*Note, error)
	CreateNote(ctx context.Context, note *Note) (*Note, error)
	UpdateNote(ctx context.Context, note *Note) (*Note, error)
	RestoreNote(ctx context.Context, id uuid.UUID) (*Note, error)
	HardDeleteNote(ctx context.Context, id uuid.UUID) error
	SoftDeleteNote(ctx context.Context, id uuid.UUID) error
}

type NoteRepository

type NoteRepository interface {
	ListNotesByUser(ctx context.Context, user_id uuid.UUID, cursor time.Time) (*[]Note, error)
	ListTrashNotesByUser(ctx context.Context, user_id uuid.UUID, cursor time.Time) (*[]Note, error)
	// GetNote(ctx context.Context, id uuid.UUID) (*Note, error)
	CreateNote(ctx context.Context, note *Note) (*Note, error)
	RestoreNote(ctx context.Context, id uuid.UUID) (*Note, error)
	UpdateNote(ctx context.Context, note *Note) (*Note, error)
	DeleteNote(ctx context.Context, id uuid.UUID, isHard bool) error
}

func NewNoteRepository

func NewNoteRepository(noteCacheDs *NoteCacheDs, noteDatabaseDs *NoteDatabaseDs) NoteRepository

type RefreshToken

type RefreshToken struct {
	Id         uuid.UUID `json:"id"`
	UserId     uuid.UUID `json:"user_id"`
	CreateTime time.Time `json:"create_time"`
	UpdateTime time.Time `json:"update_time"`
}

type RefreshTokenCacheDs

type RefreshTokenCacheDs interface {
	GetRefreshToken(ctx context.Context, id uuid.UUID) (*RefreshToken, error)
	CreateRefreshToken(ctx context.Context, refreshToken *RefreshToken) error
	DeleteRefreshToken(ctx context.Context, id uuid.UUID) error
}

type RefreshTokenDatabaseDs

type RefreshTokenDatabaseDs interface {
	GetRefreshTokenById(ctx context.Context, id uuid.UUID) (*RefreshToken, error)
	CreateRefreshToken(ctx context.Context, refreshToken *RefreshToken) (*RefreshToken, error)
	DeleteRefreshTokenByUserId(ctx context.Context, userId uuid.UUID) (*uuid.UUID, error)
}

type RefreshTokenRepository

type RefreshTokenRepository interface {
	GetRefreshToken(ctx context.Context, id uuid.UUID) (*RefreshToken, error)
	CreateRefreshToken(ctx context.Context, refreshToken *RefreshToken) (*RefreshToken, error)
	DeleteRefreshTokenByUserId(ctx context.Context, userId uuid.UUID) error
}

func NewRefreshTokenRepository

func NewRefreshTokenRepository(refreshTokenCacheDs *RefreshTokenCacheDs, refreshTokenDatabaseDs *RefreshTokenDatabaseDs) RefreshTokenRepository

type User

type User struct {
	Id         uuid.UUID `json:"id"`
	Name       string    `json:"name"`
	Email      string    `json:"email"`
	Password   string    `json:"-"`
	CreateTime time.Time `json:"create_time"`
	UpdateTime time.Time `json:"update_time"`
}

type UserCacheDs

type UserCacheDs interface {
	GetUserByEmail(ctx context.Context, email string) (*User, error)
	GetUserById(ctx context.Context, id uuid.UUID) (*User, error)
	CreateUser(ctx context.Context, user *User) error
	UpdateUser(ctx context.Context, user *User) error
	DeleteUser(ctx context.Context, id uuid.UUID) error
}

type UserDatabaseDs

type UserDatabaseDs interface {
	CreateUser(ctx context.Context, user *User) (*User, error)
	GetUserById(ctx context.Context, id uuid.UUID) (*User, error)
	GetUserByEmail(ctx context.Context, email string) (*User, error)
}

type UserRepository

type UserRepository interface {
	CreateUser(ctx context.Context, user *User) (*User, error)
	GetUserById(ctx context.Context, id uuid.UUID) (*User, error)
	GetUserByEmail(ctx context.Context, email string) (*User, error)
}

func NewUserRepository

func NewUserRepository(userCacheDs *UserCacheDs, userDatabaseDs *UserDatabaseDs) UserRepository

Jump to

Keyboard shortcuts

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