👔 Created resource module use case

This commit is contained in:
Maxim Lebedev 2023-11-18 19:00:37 +06:00
parent 766424cbf0
commit 345c3890bb
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,11 @@
package resource
import (
"context"
"source.toby3d.me/toby3d/home/internal/domain"
)
type UseCase interface {
Do(ctx context.Context, path string) (*domain.Resource, error)
}

View File

@ -0,0 +1,32 @@
package usecase
import (
"context"
"fmt"
"path"
"strings"
"source.toby3d.me/toby3d/home/internal/domain"
"source.toby3d.me/toby3d/home/internal/resource"
)
type resourceUseCase struct {
resources resource.Repository
}
func NewResourceUseCase(resources resource.Repository) resource.UseCase {
return &resourceUseCase{
resources: resources,
}
}
func (ucase *resourceUseCase) Do(ctx context.Context, p string) (*domain.Resource, error) {
p = strings.TrimPrefix(path.Clean(p), "/")
r, err := ucase.resources.Get(ctx, p)
if err != nil {
return nil, fmt.Errorf("cannot get resource file: %w", err)
}
return r, nil
}