-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_samples_interactor.go
More file actions
38 lines (33 loc) · 979 Bytes
/
get_samples_interactor.go
File metadata and controls
38 lines (33 loc) · 979 Bytes
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
package core
import (
"errors"
"strings"
)
// GetSamplesInteractor is the interface of GetSamplesInteractor.
type GetSamplesInteractor interface {
All() ([]*SampleEntity, error)
AllByName(keyword string) ([]*SampleEntity, error)
}
// GetSamplesInteractorImpl is the implementation of GetSamplesInteractor interface.
type GetSamplesInteractorImpl struct {
Samples []*SampleEntity
}
// All gets all samples.
func (interactor GetSamplesInteractorImpl) All() ([]*SampleEntity, error) {
return interactor.Samples, nil
}
// AllByName gets all samples that have name matched with keyword.
func (interactor GetSamplesInteractorImpl) AllByName(keyword string) ([]*SampleEntity, error) {
keyword = strings.ToLower(keyword)
var list []*SampleEntity
for _, item := range interactor.Samples {
name := item.NameLower()
if strings.Contains(name, keyword) {
list = append(list, item)
}
}
if len(list) == 0 {
return list, errors.New("Not Found")
}
return list, nil
}