core

package
v0.0.0-...-1344b2c Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Validate *validator.Validate

Validate - バリデータの実体. 外部に公開する.

Functions

func ValidateRecipe

func ValidateRecipe(recipe *Recipe) []string

ValidateRecipe - Recipeのバリデーションの関数

Types

type Gateway

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

Gateway - DBのアダプターの構造体

func (*Gateway) CreateRecipe

func (r *Gateway) CreateRecipe(ctx context.Context, recipe Recipe) (Recipe, error)

CreateRecipe - レシピを作成

func (*Gateway) DeleteRecipe

func (r *Gateway) DeleteRecipe(ctx context.Context, recipe Recipe) (bool, error)

DeleteRecipe - 指定したIDのレシピを削除

func (*Gateway) ReadRecipe

func (r *Gateway) ReadRecipe(ctx context.Context, id uint) (Recipe, error)

ReadRecipe - 指定したIDのレシピを取得

func (*Gateway) ReadRecipes

func (r *Gateway) ReadRecipes(ctx context.Context) ([]Recipe, error)

ReadRecipes - 全てのレシピを取得

func (*Gateway) UpdateRecipe

func (r *Gateway) UpdateRecipe(ctx context.Context, id uint, recipe Recipe) (Recipe, error)

UpdateRecipe - 指定したIDのレシピを更新

type MockDB

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

MockDB - テスト・開発用のDB

func NewMockDB

func NewMockDB() *MockDB

NewMockDB - テスト・開発用のDBのコンストラクタ

type MockGateway

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

MockGateway - MockDBのアダプターの構造体

func (*MockGateway) CreateRecipe

func (r *MockGateway) CreateRecipe(ctx context.Context, recipe Recipe) (Recipe, error)

CreateRecipe - レシピを作成

func (*MockGateway) DeleteRecipe

func (r *MockGateway) DeleteRecipe(ctx context.Context, recipe Recipe) (bool, error)

DeleteRecipe - 指定したIDのレシピを削除

func (*MockGateway) ReadRecipe

func (r *MockGateway) ReadRecipe(ctx context.Context, id uint) (Recipe, error)

ReadRecipe - 指定したIDのレシピを取得

func (*MockGateway) ReadRecipes

func (r *MockGateway) ReadRecipes(ctx context.Context) ([]Recipe, error)

ReadRecipes - 全てのレシピを取得

func (*MockGateway) UpdateRecipe

func (r *MockGateway) UpdateRecipe(ctx context.Context, id uint, recipe Recipe) (Recipe, error)

UpdateRecipe - 指定したIDのレシピを更新

type Provider

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

Provider - アプリケーションコアの構造体

func NewProvider

func NewProvider(r Repository) *Provider

NewProvider - アプリケーションコアの構造体のコンストラクタ

func (*Provider) CreateRecipe

func (p *Provider) CreateRecipe(ctx context.Context, title, makingTime, serves, ingredients string, cost int) (Recipe, error)

CreateRecipe - レシピを作成

func (*Provider) DeleteRecipe

func (p *Provider) DeleteRecipe(ctx context.Context, id uint) (bool, error)

DeleteRecipe - 指定したIDのレシピを削除

func (*Provider) ReadRecipe

func (p *Provider) ReadRecipe(ctx context.Context, id uint) (Recipe, error)

ReadRecipe - 指定したIDのレシピを取得

func (*Provider) ReadRecipes

func (p *Provider) ReadRecipes(ctx context.Context) ([]Recipe, error)

ReadRecipes - 全てのレシピを取得

func (*Provider) UpdateRecipe

func (p *Provider) UpdateRecipe(ctx context.Context, id uint, title, makingTime, serves, ingredients string, cost int) (Recipe, error)

UpdateRecipe - 指定したIDのレシピを更新

type Recipe

type Recipe struct {
	ID          uint       `json:"id,omitempty"`
	Title       string     `json:"title" validate:"required"`
	MakingTime  string     `json:"making_time" validate:"required"`
	Serves      string     `json:"serves" validate:"required"`
	Ingredients string     `json:"ingredients" validate:"required"`
	Cost        int        `json:"cost,string" validate:"required"`
	CreatedAt   *time.Time `json:"created_at,omitempty"`
	UpdatedAt   *time.Time `json:"updated_at,omitempty"`
}

Recipe - Recipeのモデル. 外部に公開する.

type Repository

type Repository interface {
	CreateRecipe(ctx context.Context, recipe Recipe) (Recipe, error)
	ReadRecipes(ctx context.Context) ([]Recipe, error)
	ReadRecipe(ctx context.Context, id uint) (Recipe, error)
	UpdateRecipe(ctx context.Context, id uint, recipe Recipe) (Recipe, error)
	DeleteRecipe(ctx context.Context, recipe Recipe) (bool, error)
}

Repository - アプリケーションコアからDBへのアダプター

func NewGateway

func NewGateway(db *gorm.DB) Repository

NewGateway - DBのアダプターの構造体のコンストラクタ

func NewMockGateway

func NewMockGateway(db *MockDB) Repository

NewMockGateway - MockDBのアダプターの構造体のコンストラクタ

Jump to

Keyboard shortcuts

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