service

package
v0.0.0-...-18998a6 Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: MIT Imports: 7 Imported by: 0

README

Service Domain層

レポジトリへのアクセス、ドメインに関するバリデーションの処理を行う。

テンプレート

package service

import (
	"context"

	"golang.org/x/xerrors"

	"github.com/calmato/gran/api/sample/internal/domain/repository"

	"github.com/calmato/gran/api/sample/internal/domain"
	"github.com/calmato/gran/api/sample/internal/domain/validation"
)

// SampleService - SampleServiceインターフェース
type SampleService interface {
	Create(ctx context.Context, u *domain.Sample) error
}

type sampleService struct {
	sampleDomainValidation validation.SampleDomainValidation
	sampleRepository       repository.SampleRepository
}

// NewSampleService - SampleServiceの生成
func NewSampleService(udv validation.SampleDomainValidation, ur repository.SampleRepository) SampleService {
	return &sampleService{
		sampleDomainValidation: udv,
		sampleRepository:       ur,
	}
}

func (us *sampleService) Create(ctx context.Context, u *domain.Sample) error {
	if err := us.sampleDomainValidation.Sample(ctx, u); err != nil {
		err = xerrors.Errorf("Failed to Domain/DomainValidation: %w", err)
		return domain.InvalidDomainValidation.New(err)
	}

	if err := us.sampleRepository.Create(ctx, u); err != nil {
		err = xerrors.Errorf("Failed to Domain/Repository: %w", err)
		return domain.Unknown.New(err)
	}

	return nil
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UserService

type UserService interface {
	Authentication(ctx context.Context) (*domain.User, error)
	Create(ctx context.Context, u *domain.User) (*domain.User, error)
	Update(ctx context.Context, u *domain.User) (*domain.User, error)
	UploadThumbnail(ctx context.Context, data []byte) (string, error)
}

UserService - UserServiceインターフェース

func NewUserService

NewUserService - UserServiceの生成

Jump to

Keyboard shortcuts

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