/
video_interactor.go
45 lines (37 loc) · 1.12 KB
/
video_interactor.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
42
43
44
45
package interactor
import (
"fmt"
"github.com/kafugen/ocwcentral/domain/repository"
"github.com/kafugen/ocwcentral/domain/usecase/dto"
"github.com/kafugen/ocwcentral/model"
)
type VideoInteractor struct {
sR repository.VideoRepository
}
func NewVideoInteractor(sR repository.VideoRepository) *VideoInteractor {
return &VideoInteractor{sR}
}
// GetByIds returns a slice of `dto.VideoDTO` by specified `videoIds`.
// This function requires `ids` only contains `videoIds` of one subject.
func (sI *VideoInteractor) GetByIds(ids []string) ([]*dto.VideoDTO, error) {
if len(ids) == 0 {
return nil, nil
}
videoIds := make([]model.VideoId, len(ids))
for i, id := range ids {
videoId, err := model.NewVideoId(id)
videoIds[i] = *videoId
if err != nil {
return nil, fmt.Errorf("failed on create `VideoId` struct: %w", err)
}
}
videos, err := sI.sR.GetByIds(videoIds)
if err != nil {
return nil, fmt.Errorf("failed on executing `GetByIds` of VideoRepository: %w", err)
}
videoDTOs := make([]*dto.VideoDTO, len(videos))
for i, video := range videos {
videoDTOs[i] = dto.NewVideoDTO(video)
}
return videoDTOs, nil
}