model

package
v0.0.0-...-dcedfe7 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	SignedStringToken string `json:"id_token"`
}

AccessToken stores token properties that are accessed in multiple application layers

type AccessTokenCustomClaims

type AccessTokenCustomClaims struct {
	User *User `json:"user"`
	jwt.StandardClaims
}

AccessTokenCustomClaims holds structure of jwt claims of idToken

type AccessTokenInfo

type AccessTokenInfo struct {
	PublicKey  *rsa.PublicKey
	PrivateKey *rsa.PrivateKey
	Expires    int64
}

AccessTokenInfo stores access token's initialize information

type ImageRepository

type ImageRepository interface {
	UpdateProfile(ctx context.Context, objName string, imageFile multipart.File) (string, error)
	DeleteProfile(ctx context.Context, objName string) error
}

ImageRepository defines methods it expects a repository it interacts with to implement

type RefreshToken

type RefreshToken struct {
	ID                uuid.UUID `json:"-"`
	UID               uuid.UUID `json:"-"`
	SignedStringToken string    `json:"refresh_token"`
}

RefreshToken stores token properties that are accessed in multiple application layers

type RefreshTokenCustomClaims

type RefreshTokenCustomClaims struct {
	UID uuid.UUID `json:"uid"`
	jwt.StandardClaims
}

RefreshTokenCustomClaims holds the payload of a refresh token This can be used to extract user id for subsequent application operations (IE, fetch user in Redis)

type RefreshTokenData

type RefreshTokenData struct {
	SignedStringToken string
	ID                uuid.UUID
	ExpiresIn         time.Duration
}

RefreshTokenData holds the actual signed jwt string along with the ID We return the id, so it can be used without re-parsing the JWT from signed string

type RefreshTokenInfo

type RefreshTokenInfo struct {
	Secret  string
	Expires int64
}

RefreshTokenInfo stores refresh token's initialize information

type Token

type Token struct {
	AccessToken
	RefreshToken
}

Token used for returning pairs of id and refresh tokens

type TokenRepository

type TokenRepository interface {
	SetRefreshToken(ctx context.Context, userID string, tokenID string, expiresIn time.Duration) error
	DeleteRefreshToken(ctx context.Context, userID string, prevTokenID string) error
	DeleteUserRefreshToken(ctx context.Context, userID string) error
}

TokenRepository defines methods it expects a repository it interacts with to implement

type TokenService

type TokenService interface {
	NewPairFromUser(ctx context.Context, user *User, prevRefreshTokenID string) (*Token, error)
	Signout(ctx context.Context, uid uuid.UUID) error
	ValidateIDToken(idTokenString string) (*User, error)                   // jwt not require context, and we not do anything in repository or db that cancel or modify context
	ValidateRefreshToken(refreshTokenString string) (*RefreshToken, error) // not need context because not reach DB or other layer.
}

TokenService defines methods the handler layer expects to interact with in regards to producing JWTs as string

type User

type User struct {
	UID      uuid.UUID `db:"uid" json:"uid"`
	Email    string    `db:"email" json:"email"`
	Password string    `db:"password" json:"-"` // "-" to ensure password can not be sent to user via that struct
	Name     string    `db:"name" json:"name"`
	ImageURL string    `db:"image_url" json:"image_url"`
	Website  string    `db:"website" json:"website"`
}

User defines domain model and its json and db representations

type UserRepository

type UserRepository interface {
	FindByID(ctx context.Context, uid uuid.UUID) (*User, error)
	FindByEmail(ctx context.Context, email string) (*User, error)
	Create(ctx context.Context, user *User) error
	Update(ctx context.Context, user *User) error
	UpdateImage(ctx context.Context, uid uuid.UUID, imageURL string) (*User, error)
}

UserRepository defines methods the service layer expects any repository it interacts with to implement

type UserService

type UserService interface {
	Get(ctx context.Context, uid uuid.UUID) (*User, error)
	Signup(ctx context.Context, user *User) error
	Signin(ctx context.Context, user *User) error
	UpdateDetails(ctx context.Context, user *User) error
	SetProfileImage(ctx context.Context, uid uuid.UUID, imageFileHeader *multipart.FileHeader) (*User, error)
	DeleteProfileImage(ctx context.Context, uid uuid.UUID) error
}

UserService defines methods the handler layer expects any service it interacts with to implement

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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