-
Notifications
You must be signed in to change notification settings - Fork 1
/
memo.go
41 lines (34 loc) · 998 Bytes
/
memo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package usecase
import (
"context"
"memoapi/memo"
"memoapi/model"
"github.com/go-playground/validator/v10"
)
// MemoUsecase implements memo usecase.
type MemoUsecase struct {
repository memo.Repository
validate *validator.Validate
}
// NewMemoUsecase returns new instance of Usecase.
func NewMemoUsecase(repository memo.Repository) *MemoUsecase {
return &MemoUsecase{
repository: repository,
validate: validator.New(),
}
}
// CreateMemo creates a new memo.
func (u *MemoUsecase) CreateMemo(ctx context.Context, m *model.Memo) error {
if err := u.validate.Struct(m); err != nil {
return err
}
return u.repository.CreateMemo(ctx, m)
}
// GetMemoByID gets memo by given id.
func (u *MemoUsecase) GetMemoByID(ctx context.Context, id int) (*model.Memo, error) {
return u.repository.GetMemoByID(ctx, id)
}
// GetAllMemo gets all memos stored in repository.
func (u *MemoUsecase) GetAllMemo(ctx context.Context) ([]*model.Memo, error) {
return u.repository.GetAllMemo(ctx)
}