domain

package
v0.0.0-...-19c4467 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessTokenDuration  = 15
	RefreshTokenDuration = 30
)

Variables

View Source
var HMAC_SAMPLE_SECRET = os.Getenv("HMAC_SAMPLE_SECRET")

Functions

This section is empty.

Types

type AccessTokenClaims

type AccessTokenClaims struct {
	UserId string `json:"user_id"`
	Role   string `json:"role"`
	Email  string `json:"email"`
	jwt.StandardClaims
}

func (AccessTokenClaims) IsAdminRole

func (c AccessTokenClaims) IsAdminRole() bool

func (AccessTokenClaims) IsOwner

func (c AccessTokenClaims) IsOwner(userId string) bool

func (AccessTokenClaims) IsRequestVerifiedWithTokenClaims

func (c AccessTokenClaims) IsRequestVerifiedWithTokenClaims(urlParams map[string]string) bool

func (AccessTokenClaims) IsRequestVerifiedWithTokenClaimsAndRole

func (c AccessTokenClaims) IsRequestVerifiedWithTokenClaimsAndRole(urlParams map[string]string) bool

func (AccessTokenClaims) IsUserRole

func (c AccessTokenClaims) IsUserRole() bool

func (AccessTokenClaims) RefreshTokenClaims

func (c AccessTokenClaims) RefreshTokenClaims() RefreshTokenClaims

type Article

type Article struct {
	ID          string `json:"article_id"db:"article_id"`
	Title       string `json:"title"db:"title""`
	Content     string `json:"content"db:"content"`
	PublishedAt string `json:"published_at"db:"published_at"`
	Author      int    `json:"author"db:"author_id"`
}

func (Article) ToDto

func (a Article) ToDto() dto.ArticleResponse

type ArticleRepository

type ArticleRepository interface {
	GetAll() ([]Article, *errs.AppError)
	GetByID(id int) (*Article, *errs.AppError)
	GetByUserID(id int) ([]Article, *errs.AppError)
	CreateArticle(article ArticleRequest) *errs.AppError
}

type ArticleRepositoryDB

type ArticleRepositoryDB struct {
	// contains filtered or unexported fields
}

func NewArticleRepositoryDB

func NewArticleRepositoryDB(dbClient *sqlx.DB) ArticleRepositoryDB

func (ArticleRepositoryDB) CreateArticle

func (r ArticleRepositoryDB) CreateArticle(article Article) (*Article, *errs.AppError)

func (ArticleRepositoryDB) GetAll

func (r ArticleRepositoryDB) GetAll() ([]Article, *errs.AppError)

func (ArticleRepositoryDB) GetByID

func (ArticleRepositoryDB) GetByUserID

func (r ArticleRepositoryDB) GetByUserID(id int) ([]Article, *errs.AppError)

type ArticleRequest

type ArticleRequest struct {
	Title   string `json:"title"db:"title""`
	Content string `json:"content"db:"content"`
	Author  int    `json:"author"db:"author_id"`
}

type AuthRepository

type AuthRepository interface {
	FindById(email string, password string) (*Login, *errs.AppError)
	GenerateAndSaveRefreshTokenToStore(token AuthToken) (string, *errs.AppError)
	RefreshTokenExists(refreshToken string) *errs.AppError
	IsAuthorized(token string, routeName string, vars map[string]string) bool
}

type AuthRepositoryDB

type AuthRepositoryDB struct {
	// contains filtered or unexported fields
}

func NewAuthRepositoryDB

func NewAuthRepositoryDB(client *sqlx.DB) AuthRepositoryDB

func (AuthRepositoryDB) FindById

func (a AuthRepositoryDB) FindById(email string, password string) (*Login, *errs.AppError)

func (AuthRepositoryDB) GenerateAndSaveRefreshTokenToStore

func (a AuthRepositoryDB) GenerateAndSaveRefreshTokenToStore(authToken AuthToken) (string, *errs.AppError)

func (AuthRepositoryDB) IsAuthorized

func (r AuthRepositoryDB) IsAuthorized(token string, routeName string, vars map[string]string) bool

func (AuthRepositoryDB) RefreshTokenExists

func (a AuthRepositoryDB) RefreshTokenExists(refreshToken string) *errs.AppError

type AuthToken

type AuthToken struct {
	// contains filtered or unexported fields
}

func NewAuthToken

func NewAuthToken(claims AccessTokenClaims) AuthToken

func (AuthToken) NewAccessToken

func (a AuthToken) NewAccessToken() (string, *errs.AppError)

func (AuthToken) NewRefreshToken

func (a AuthToken) NewRefreshToken() (string, *errs.AppError)

type Email

type Email struct {
	To       string
	From     string
	Subject  string
	Body     string
	Template string
}

type EmailRepository

type EmailRepository interface {
	SendEmail(email Email, wg *sync.WaitGroup) *errs.AppError
}

type EmailRepositoryDB

type EmailRepositoryDB struct {
}

func NewEmailRepositoryDB

func NewEmailRepositoryDB() EmailRepositoryDB

func (EmailRepositoryDB) SendEmail

func (r EmailRepositoryDB) SendEmail(email Email, wg *sync.WaitGroup) *errs.AppError

type Login

type Login struct {
	Email  string `json:"email"db:"email"`
	UserId string `json:"user_id"db:"id"`
	Role   string `json:"role"db:"role"`
}

func (Login) ClaimsForAccessToken

func (l Login) ClaimsForAccessToken() AccessTokenClaims

func (Login) ClaimsForAdmin

func (l Login) ClaimsForAdmin() AccessTokenClaims

func (Login) ClaimsForUser

func (l Login) ClaimsForUser() AccessTokenClaims

type LoginDb

type LoginDb struct {
	Email    string `json:"email"db:"email"`
	UserId   string `json:"user_id"db:"id"`
	Role     string `json:"role"db:"role"`
	Password string `json:"password"db:"password"`
}

type RefreshTokenClaims

type RefreshTokenClaims struct {
	UserId    string `json:"user_id"`
	TokenType string `json:"token_type"`
	jwt.StandardClaims
}

type RolePermissions

type RolePermissions struct {
	// contains filtered or unexported fields
}

func GetRolePermissions

func GetRolePermissions() RolePermissions

func (RolePermissions) IsAuthorizedFor

func (p RolePermissions) IsAuthorizedFor(role string, routeName string) bool

type User

type User struct {
	ID       int    `json:"id"db:"id"csv:"id"`
	FullName string `json:"full_name"db:"full_name"csv:"full_name"`
	Email    string `json:"email"db:"email"csv:"email"`
	Password string `json:"password"db:"password"csv:"password"`
	//Articles []userArticle `json:"articles"db:"articles"csv:"articles"`
	Gender string `json:"gender"db:"gender"csv:"gender"`
}

User represents a user in the system

type UserRepository

type UserRepository interface {
	Populate() *errs.AppError
	GetAll() ([]dto.UserResponse, *errs.AppError)
}

UserRepository defines the methods that any user repository should implement

type UserRepositoryDB

type UserRepositoryDB struct {
	// contains filtered or unexported fields
}

func NewUserRepositoryDB

func NewUserRepositoryDB(dbClient *sqlx.DB) UserRepositoryDB

func (UserRepositoryDB) GetAll

func (r UserRepositoryDB) GetAll() ([]dto.UserResponse, *errs.AppError)

func (UserRepositoryDB) GetByID

func (r UserRepositoryDB) GetByID(id int) (*dto.UserResponse, *errs.AppError)

func (UserRepositoryDB) Populate

func (r UserRepositoryDB) Populate() *errs.AppError

Jump to

Keyboard shortcuts

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