repository

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

リポジトリ層

  • データストア(データベース)とドメインの橋かけを担う
  • DB操作にまつわる操作(SQL)などは必ずリポジトリに記述する
  • データの永続化と再構築を行う

ファイル

transaction.go

  • トランザクションを扱うコード
// 利用方法
// router.go, auth_router.goでインスタンス化 
appConnection := repository.NewAppConnection(db)
// サービスに渡して利用
sendPointHandler := handler.NewSendPoint(&service.SendPoint{PointRepo: &rep, UserRepo: &rep, Connection: appConnection, DB: db})
error.go
  • エラーを定義する

kvs.go

  • Key/Values
  • Redisにアクセスするための構造体

repository.go

  • DBのインスタンス作成やIFを定義

Documentation

Overview

データベースのエラーコードを定義する場所

Index

Constants

View Source
const (
	// ErrCodeMySQLDuplicateEntry はMySQL系のDUPLICATEエラーコード
	// https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html
	// Error number: 1062; Symbol: ER_DUP_ENTRY; SQLSTATE: 23000
	ErrCodeMySQLDuplicateEntry  = 1062
	ErrCodeMySQLNoReferencedRow = 1452
)

Variables

This section is empty.

Functions

func NewDB

func NewDB(ctx context.Context, cfg *config.Config) (*sqlx.DB, func(), error)

DBへの接続 @params ctx コンテキスト cfg 接続設定の環境変数

@return *sqlx.DB DBインスタンス, func() DBクローズ関数(予備先素でdeferで呼ぶ必要あり)

Types

type Beginner

type Beginner interface {
	BeginTxx(ctx context.Context, opts *sql.TxOptions) (*sqlx.Tx, error)
}

トランザクションメソッド系類

type CacheType

type CacheType int
const (
	JWT               CacheType = 0
	TemporaryRegister CacheType = 1
)

type Execer

type Execer interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
}

書き込み系メソッド類

type GetAllWithCursorParam

type GetAllWithCursorParam struct {
	Size            int          `db:"size"`
	CursorPoint     int          `db:"point"`
	CursorUserID    model.UserID `db:"user_id"`
	CursorCreatedAt time.Time    `db:"created_at"`
}

type GetUsersParam

type GetUsersParam struct {
	Size int
}

type KVS

type KVS struct {
	Cli *redis.Client
}

func NewKVS

func NewKVS(ctx context.Context, cfg *config.Config, t CacheType) (*KVS, error)

func (*KVS) Delete

func (k *KVS) Delete(ctx context.Context, key string) error

値を削除

@params ctx context key key

func (*KVS) Expire

func (k *KVS) Expire(ctx context.Context, key string, minitue time.Duration) error

有効期限を延長

func (*KVS) Load

func (k *KVS) Load(ctx context.Context, key string) (string, error)

値をロードする

@params ctx context key key value

func (*KVS) Publish

func (k *KVS) Publish(ctx context.Context, channel, palyload string) error

チャネルにパブリッシュする @params ctx context channel チャンネル名 payload 送信するデータ

func (*KVS) Save

func (k *KVS) Save(ctx context.Context, key, value string, minute time.Duration) error

値を保存する

@params ctx context key key value value minute 有効期限(分)

func (*KVS) Subscribe

func (k *KVS) Subscribe(ctx *gin.Context, channel string) (<-chan string, error)

チャネルをサブスクライブする @params ctx context channel チャンネル名

@return payload 送信されたら発火し、payloadが送られる

type Preparer

type Preparer interface {
	PreparexContext(ctx context.Context, query string) (*sqlx.Stmt, error)
}

比較系メソッド類

type Queryer

type Queryer interface {
	Preparer
	QueryxContext(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)
	QueryRowxContext(ctx context.Context, query string, args ...any) *sqlx.Row
	GetContext(ctx context.Context, dest interface{}, query string, args ...any) error
	SelectContext(ctx context.Context, dest interface{}, query string, args ...any) error
}

読み取り系メソッド類

type Repository

type Repository struct {
	Clocker clock.Clocker
}

func NewRepository

func NewRepository(clocker clock.Clocker) *Repository

func (*Repository) CheckNotification

func (r *Repository) CheckNotification(ctx context.Context, db Execer, uid model.UserID, nid model.NotificationID) error

お知らせチェックフラグをONにする @params ctx context db dbインスタンス uid ユーザID nie お知らせID

func (*Repository) CreateNotification

お知らせ登録 @params ctx context db dbインスタンス n 登録するお知らせ情報

@returns お知らせ

func (*Repository) DeleteUserByID

func (r *Repository) DeleteUserByID(ctx context.Context, db Execer, ID model.UserID) (int64, error)

削除

func (*Repository) FindUserByEmail

func (r *Repository) FindUserByEmail(ctx context.Context, db Queryer, email string, columns ...string) (entities.User, error)

メールでユーザが存在するか検索する @params ctx context db dbインスタンス email email columns カラム(無指定の場合は全て)

@returns entities.User ユーザ情報

func (*Repository) GetAll

func (r *Repository) GetAll(ctx context.Context, db Queryer, columns ...string) ([]*entities.User, error)

ユーザ一覧

@params ctx context db db columns 取得カラム(無指定の場合は全て)

@returns Users ユーザ一覧

func (*Repository) GetAllWithCursor

func (r *Repository) GetAllWithCursor(ctx context.Context, db Queryer, param GetAllWithCursorParam) ([]*entities.User, error)

GetAllWithCursor ポイント順にユーザを取得する カーソルページネーションを使用して取得する ソート順は以下の通り

1. ポイントが多い順 2. ポイントが同じ場合は登録日が古い順 3. ポイントと登録日が同じ場合はユーザIDが大きい順

func (*Repository) GetAquistionPoint

func (r *Repository) GetAquistionPoint(ctx context.Context, db Queryer, userIDs []model.UserID) (map[model.UserID]int, error)

GetAquistionPoint は、指定ユーザーの取得ポイントを取得する

func (*Repository) GetByToUserByStartIdOrderByLatest

func (r *Repository) GetByToUserByStartIdOrderByLatest(ctx context.Context, db Queryer, uid model.UserID, startID model.NotificationID, size int, columns ...string) ([]*customentities.Notification, error)

お知らせ一覧取得 @params ctx context db dbインスタンス uid 受信者ユーザID startID 開始するお知らせID size 取得件数

@returns お知らせ一覧

func (*Repository) GetByToUserOrderByLatest

func (r *Repository) GetByToUserOrderByLatest(ctx context.Context, db Queryer, uid model.UserID, size int, columns ...string) ([]*customentities.Notification, error)

指定した受信者ユーザーIDを元にお知らせ一覧を取得

func (*Repository) GetNotificationByID

func (r *Repository) GetNotificationByID(ctx context.Context, db Queryer, uid model.UserID, nid model.NotificationID) (customentities.Notification, error)

お知らせ詳細取得 @params ctx context db dbインスタンス uid ユーザID nid お知らせID

@returns entities.Notification お知らせ

func (*Repository) GetUncheckedNotificationCount

func (r *Repository) GetUncheckedNotificationCount(ctx context.Context, db Queryer, uid model.UserID) (int, error)

チェックしていないお知らせ総数 @params ctx context db dbインスタンス ID ユーザID

@returns お知らせ数

func (*Repository) GetUserByID

func (r *Repository) GetUserByID(ctx context.Context, db Queryer, ID model.UserID) (entities.User, error)

ユーザIDでユーザが存在するか検索する @params ctx context db dbインスタンス ID ユーザID

@returns entities.User ユーザ情報

func (*Repository) GetUsers

func (r *Repository) GetUsers(ctx context.Context, db Queryer, param GetUsersParam) ([]*entities.User, error)

GetUsers ポイント順にユーザを取得する

ソート順は以下の通り

1. ポイントが多い順 2. ポイントが同じ場合は登録日が古い順 3. ポイントと登録日が同じ場合はユーザIDが大きい順

func (*Repository) RegisterPointTransaction

func (r *Repository) RegisterPointTransaction(ctx context.Context, db Execer, fromUserID, toUserId model.UserID, sendPoint int) error

ポイントの取引履歴の保存

@params ctx コンテキスト db dbの値(インスタンス) fromUserID 送信元ユーザ toUserId 送信先ユーザ sendPoint 送付ポイント

func (*Repository) RegisterUser

func (r *Repository) RegisterUser(ctx context.Context, db Execer, u *entities.User) error

ユーザ情報永続化

@params ctx コンテキスト db dbの値(インスタンス) u ユーザエンティティ

func (*Repository) UpdateAccount

func (r *Repository) UpdateAccount(ctx context.Context, db Execer, email, familyName, familyNameKana, firstName, firstNameKana *string) error

アカウント情報を上書きする @params ctx context db dbインスタンス email email familyName familyName familyNameKana familyNameKana firstName firstName firstNameKana firstNameKana

@returns error

func (*Repository) UpdateAllSendablePoint

func (r *Repository) UpdateAllSendablePoint(ctx context.Context, db Execer, point int) error

UpdateAllSendablePoint は、全ユーザの送付可能ポイントを更新する

func (*Repository) UpdateEmail

func (r *Repository) UpdateEmail(ctx context.Context, db Execer, userID model.UserID, newEmail string) error

メールアドレスを上書きする @params ctx context db dbインスタンス userID 更新するユーザーID newEmail 上書きするメールアドレス

@returns error

func (*Repository) UpdatePassword

func (r *Repository) UpdatePassword(ctx context.Context, db Execer, email, pass *string) error

パスワードを上書き @params ctx context db dbインスタンス email email pass password

@returns error

func (*Repository) UpdateSendablePoint

func (r *Repository) UpdateSendablePoint(ctx context.Context, db Execer, fromUserID model.UserID, point int) error

ポイント可能額の更新

@params ctx コンテキスト db db_instanc fromUserID 送付者ユーザのID point ポイント残高

Directories

Path Synopsis
Package mock_repository is a generated GoMock package.
Package mock_repository is a generated GoMock package.
Package entities contains generated code for schema 'point_app'.
Package entities contains generated code for schema 'point_app'.

Jump to

Keyboard shortcuts

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