wallet

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateItemID

func GenerateItemID(userID string, kind ItemKind) string

GenerateItemID ... お財布のアイテムIDを作成する

func ItemHistoryRef

func ItemHistoryRef(fCli *firestore.Client) *firestore.CollectionRef

ItemHistoryRef ... コレクションの参照を取得

func ItemRef

func ItemRef(fCli *firestore.Client) *firestore.CollectionRef

ItemRef ... コレクションの参照を取得

Types

type Client

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

Client ... ウォレットのクライアント

func NewClient

func NewClient(cFirestore *firestore.Client) *Client

NewClient ... リポジトリを作成する

func (*Client) Exchange

func (c *Client) Exchange(
	ctx context.Context,
	userID string,
	fromKind ItemKind,
	toKind ItemKind,
	amount float64,
	data map[string]interface{},
	comment string) (map[ItemKind]*Item, error)

Exchange ... アイテムを両替する

func (*Client) Get

func (c *Client) Get(ctx context.Context, userID string, kind ItemKind) (*Item, error)

Get ... 指定のアイテムが入ったウォレットを取得する

func (*Client) GetAmount

func (c *Client) GetAmount(ctx context.Context, userID string, kind ItemKind) (float64, error)

GetAmount ... 指定のアイテムが入ったウォレット(金額のみ)を取得する

func (*Client) GetMulti

func (c *Client) GetMulti(ctx context.Context, userID string, kinds []ItemKind) (map[ItemKind]*Item, error)

GetMulti ... 指定のアイテムが入ったウォレットを複数取得する

func (*Client) GetMultiAmount

func (c *Client) GetMultiAmount(ctx context.Context, userID string, kinds []ItemKind) (map[ItemKind]float64, error)

GetMultiAmount ... 指定のアイテムが入ったウォレット(金額のみ)を複数取得する

func (*Client) Give

func (c *Client) Give(
	ctx context.Context,
	userID string,
	amounts map[ItemKind]float64,
	data map[string]interface{},
	comment string) (map[ItemKind]*Item, error)

Give ... アイテムを配布する

func (*Client) HistoriesByCursor

func (c *Client) HistoriesByCursor(
	ctx context.Context,
	userID string,
	kinds []ItemKind,
	limit int,
	cursor string) ([]*ItemHistory, string, error)

HistoriesByCursor ... 履歴リストを取得する

func (*Client) HistoriesByPeriod

func (c *Client) HistoriesByPeriod(
	ctx context.Context,
	userID string,
	kinds []ItemKind,
	startAt int64,
	endAt int64) ([]*ItemHistory, error)

HistoriesByPeriod ... 履歴リストを期間指定で取得する

func (*Client) Use

func (c *Client) Use(
	ctx context.Context,
	userID string,
	amounts map[ItemKind]float64,
	data map[string]interface{},
	comment string) (map[ItemKind]*Item, error)

Use ... アイテムを消費する

type Item

type Item struct {
	ID        string                 `firestore:"-"          json:"id" cloudfirestore:"id"`
	Ref       *firestore.DocumentRef `firestore:"-"          json:"-"  cloudfirestore:"ref"`
	UserID    string                 `firestore:"user_id"    json:"user_id"`
	Kind      ItemKind               `firestore:"kind"       json:"kind"`
	Amount    float64                `firestore:"amount"     json:"amount"`
	TotalGive float64                `firestore:"total_give" json:"total_give"`
	TotalUse  float64                `firestore:"total_use"  json:"total_use"`
	CreatedAt int64                  `firestore:"created_at" json:"created_at"`
	UpdatedAt int64                  `firestore:"updated_at" json:"updated_at"`
}

Item ... お財布のアイテム

type ItemHistory

type ItemHistory struct {
	ID        string                 `firestore:"-"          json:"id" cloudfirestore:"id"`
	Ref       *firestore.DocumentRef `firestore:"-"          json:"-"  cloudfirestore:"ref"`
	UserID    string                 `firestore:"user_id"    json:"user_id"`
	Kind      ItemKind               `firestore:"kind"       json:"kind"`
	Amount    float64                `firestore:"amount"     json:"amount"`
	Data      map[string]interface{} `firestore:"data"       json:"data"`
	Comment   string                 `firestore:"comment"    json:"comment"`
	CreatedAt int64                  `firestore:"created_at" json:"created_at"`
}

ItemHistory ... お財布アイテムの配布/消費履歴

type ItemKind

type ItemKind string

ItemKind ... アイテムの種類

type Repository

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

Repository ... ウォレットのリポジトリ

func NewRepository

func NewRepository(cFirestore *firestore.Client) *Repository

NewRepository ... リポジトリを作成する

func (*Repository) CreateHistory added in v1.0.6

func (r *Repository) CreateHistory(
	ctx context.Context,
	userID string,
	kind ItemKind,
	amount float64,
	data map[string]interface{},
	comment string,
	createdAt int64) (*ItemHistory, error)

CreateHistory ... 履歴を作成する

func (*Repository) GetItem

func (r *Repository) GetItem(
	ctx context.Context,
	userID string,
	kind ItemKind,
) (*Item, error)

GetItem ... アイテムを取得する

func (*Repository) GetMultiItem added in v1.0.6

func (r *Repository) GetMultiItem(
	ctx context.Context,
	userID string,
	kinds []ItemKind,
) (map[ItemKind]*Item, error)

GetMultiItem ... アイテムを複数取得する

func (*Repository) ListHistoryByCursor

func (r *Repository) ListHistoryByCursor(
	ctx context.Context,
	userID string,
	kinds []ItemKind,
	limit int,
	cursor string,
) ([]*ItemHistory, string, error)

ListHistoryByCursor ... 履歴リストを取得する

func (*Repository) ListHistoryByPeriod

func (r *Repository) ListHistoryByPeriod(
	ctx context.Context,
	userID string,
	kinds []ItemKind,
	startAt int64,
	endAt int64,
) ([]*ItemHistory, error)

ListHistoryByPeriod ... 履歴リストを期間指定で取得する

func (*Repository) ListItem

func (r *Repository) ListItem(
	ctx context.Context,
	userID string,
) ([]*Item, error)

ListItem ... アイテムリストを取得する

func (*Repository) SetItem added in v1.0.6

func (r *Repository) SetItem(
	ctx context.Context,
	userID string,
	kind ItemKind,
	src *Item,
) (*Item, error)

SetItem ... アイテムを設定する

type Service

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

Service ... ウォレットのサービス

func NewService

func NewService(repo *Repository) *Service

NewService ... サービスを作成する

func (*Service) Exchange

func (s *Service) Exchange(
	ctx context.Context,
	userID string,
	fromKind ItemKind,
	toKind ItemKind,
	amount float64,
	data map[string]interface{},
	comment string) (map[ItemKind]*Item, error)

Exchange ... 両替する

func (*Service) Get

func (s *Service) Get(ctx context.Context, userID string, kind ItemKind) (*Item, error)

Get ... 取得する

func (*Service) GetAmount

func (s *Service) GetAmount(ctx context.Context, userID string, kind ItemKind) (float64, error)

GetAmount ... 金額のみ取得する

func (*Service) GetMulti

func (s *Service) GetMulti(ctx context.Context, userID string, kinds []ItemKind) (map[ItemKind]*Item, error)

GetMulti ... 複数種類を取得する

func (*Service) GetMultiAmount

func (s *Service) GetMultiAmount(ctx context.Context, userID string, kinds []ItemKind) (map[ItemKind]float64, error)

GetMultiAmount ... 複数種類の金額のみ取得する

func (*Service) Give

func (s *Service) Give(
	ctx context.Context,
	userID string,
	amounts map[ItemKind]float64,
	data map[string]interface{},
	comment string) (map[ItemKind]*Item, error)

Give ... 配布する

func (*Service) HistoriesByCursor

func (s *Service) HistoriesByCursor(ctx context.Context, userID string, kinds []ItemKind, limit int, cursor string) ([]*ItemHistory, string, error)

HistoriesByCursor ... 履歴リストを取得する

func (*Service) HistoriesByPeriod

func (s *Service) HistoriesByPeriod(
	ctx context.Context,
	userID string,
	kinds []ItemKind,
	startAt int64,
	endAt int64) ([]*ItemHistory, error)

HistoriesByPeriod ... 期間を指定して履歴リストを取得する

func (*Service) Use

func (s *Service) Use(
	ctx context.Context,
	userID string,
	amounts map[ItemKind]float64,
	data map[string]interface{},
	comment string) (map[ItemKind]*Item, error)

Use ... 消費する

Jump to

Keyboard shortcuts

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