service

package
v0.0.0-...-e7e8391 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSecretRepository

func NewSecretRepository(config *config.AWS) (port.SecretRepository, error)

func NewTokenService

func NewTokenService(config *config.Token, repository port.SecretRepository) (port.TokenService, error)

NewTokenService creates a new TokenService instance

Types

type AuthService

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

*

  • AuthService implements port.AuthService interface
  • and provides an access to the user repository
  • and token service

func NewAuthService

func NewAuthService(repo port.UserRepository, ts port.TokenService) *AuthService

NewAuthService creates a new auth service instance

func (*AuthService) Login

func (as *AuthService) Login(ctx context.Context, email, password string) (string, error)

Login gives a registered user an access token if the credentials are valid

type SecretRepository

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

func (*SecretRepository) GetTokenSecret

func (*SecretRepository) UpdateTokenSecret

type TokenService

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

*

  • TokenService implements port.TokenService interface
  • Provide an access to the paseto library -> go-paseto
  • TokenService は port.TokenService インターフェースを実装する。
  • paseto ライブラリへのアクセスを提供する -> go-paseto

func (*TokenService) CreateToken

func (pt *TokenService) CreateToken(user *domain.User) (string, error)

CreateToken creates a new paseto token

func (*TokenService) VerifyToken

func (pt *TokenService) VerifyToken(token string) (*domain.TokenPayload, error)

VerifyToken verifies the paseto token

type User

type User struct {
	ID        uint64          `gorm:"primaryKey"`
	Name      string          `gorm:"size:255;not null"`
	Email     string          `gorm:"size:255;unique;not null"`
	Password  string          `gorm:"size:255;not null"`
	Role      domain.UserRole `gorm:"type:user_role;default:'normal'"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

type UserRepository

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

*

  • UserRepository implements port.UserRepository interface
  • and provides an access to the postgres database
  • UserRepository は port.UserRepository インターフェースを実装しています。
  • postgres データベースへのアクセスを提供します。

func NewCustomWayRespository

func NewCustomWayRespository(db *gorm.DB) *UserRepository

The gorm will abstract all the db action. Make this service easy to change db endpoint. gormはすべてのdbアクションを抽象化する。dbのエンドポイントを簡単に変更できるようにする。

func NewUserRepository

func NewUserRepository(config *config.DB) (*UserRepository, error)

func (*UserRepository) CloseDB

func (ur *UserRepository) CloseDB() error

func (*UserRepository) CreateUser

func (ur *UserRepository) CreateUser(ctx context.Context, user *domain.User) (*domain.User, error)

func (*UserRepository) DeleteUser

func (ur *UserRepository) DeleteUser(ctx context.Context, id uint64) error

func (*UserRepository) GetUserByEmail

func (ur *UserRepository) GetUserByEmail(ctx context.Context, email string) (*domain.User, error)

func (*UserRepository) GetUserByID

func (ur *UserRepository) GetUserByID(ctx context.Context, id uint64) (*domain.User, error)

func (*UserRepository) ListUsers

func (ur *UserRepository) ListUsers(ctx context.Context, lastID uint64, limit uint64) ([]domain.User, error)

ListUsers lists all users from the database, paginated by ID

func (*UserRepository) UpdateUser

func (ur *UserRepository) UpdateUser(ctx context.Context, user *domain.User) (*domain.User, error)

type UserService

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

*

  • UserService implements port.UserService interface

func NewUserService

func NewUserService(repo port.UserRepository) *UserService

func (*UserService) DeleteUser

func (us *UserService) DeleteUser(ctx context.Context, id uint64) error

DeleteUser deletes a user by ID

func (*UserService) GetUser

func (us *UserService) GetUser(ctx context.Context, id uint64) (*domain.User, error)

GetUser gets a user by ID

func (*UserService) ListUsers

func (us *UserService) ListUsers(ctx context.Context, skip, limit uint64) ([]domain.User, error)

Get all users

func (*UserService) Register

func (us *UserService) Register(ctx context.Context, user *domain.User) (*domain.User, error)

Register creates a new user !Password will save to db !パスワードがDBに保存される

func (*UserService) UpdateUser

func (us *UserService) UpdateUser(ctx context.Context, user *domain.User) (*domain.User, error)

UpdateUser updates a user's name, email, and password

Jump to

Keyboard shortcuts

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