♻️ Refactored resources repositories

This commit is contained in:
Maxim Lebedev 2024-02-03 20:36:26 +06:00
parent 4026fb9192
commit 542348f635
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
5 changed files with 34 additions and 42 deletions

View File

@ -15,15 +15,14 @@ import (
)
type Resource struct {
File Path
modTime time.Time
params map[string]any // TODO(toby3d): set from Page configuration
params map[string]any
File Path
mediaType MediaType
key string
name string // TODO(toby3d): set from Page configuration
title string // TODO(toby3d): set from Page configuration
name string
resourceType ResourceType
title string
image image.Config
}
@ -69,13 +68,13 @@ func (r Resource) MediaType() MediaType {
}
// Width returns width if current r is an image.
func (r Resource) Width() int {
return r.image.Width
func (r Resource) Width() uint {
return uint(r.image.Width)
}
// Height returns height if current r is an image.
func (r Resource) Height() int {
return r.image.Height
func (r Resource) Height() uint {
return uint(r.image.Height)
}
func (r Resource) ResourceType() ResourceType {

View File

@ -6,26 +6,10 @@ import (
"source.toby3d.me/toby3d/home/internal/domain"
)
type (
Repository interface {
// Get returns Resource on path if exists.
Get(ctx context.Context, path string) (*domain.Resource, error)
type Repository interface {
// Get returns Resource on path if exists.
Get(ctx context.Context, path string) (*domain.Resource, error)
// Fetch returns all resources from dir recursevly.
Fetch(ctx context.Context, pattern string) (domain.Resources, int, error)
}
dummyRepository struct{}
)
func NewDummyRepository() dummyRepository {
return dummyRepository{}
}
func (dummyRepository) Get(ctx context.Context, path string) (*domain.Resource, error) {
return nil, nil
}
func (dummyRepository) Fetch(ctx context.Context, pattern string) (domain.Resources, int, error) {
return nil, 0, nil
// Fetch returns all resources from dir recursevly.
Fetch(ctx context.Context, pattern string) (domain.Resources, int, error)
}

View File

@ -0,0 +1,21 @@
package dummy
import (
"context"
"source.toby3d.me/toby3d/home/internal/domain"
)
type dummyResourceRepository struct{}
func NewDummyResourceRepository() dummyResourceRepository {
return dummyResourceRepository{}
}
func (dummyResourceRepository) Get(_ context.Context, _ string) (*domain.Resource, error) {
return nil, nil
}
func (dummyResourceRepository) Fetch(_ context.Context, _ string) (domain.Resources, int, error) {
return nil, 0, nil
}

View File

@ -3,14 +3,8 @@ package fs
import (
"context"
"fmt"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"io/fs"
_ "golang.org/x/image/bmp"
_ "golang.org/x/image/webp"
"source.toby3d.me/toby3d/home/internal/domain"
"source.toby3d.me/toby3d/home/internal/resource"
)

View File

@ -5,17 +5,11 @@ import (
"context"
"errors"
"fmt"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"io"
"io/fs"
"os"
"path/filepath"
_ "golang.org/x/image/bmp"
_ "golang.org/x/image/webp"
"source.toby3d.me/toby3d/home/internal/domain"
"source.toby3d.me/toby3d/home/internal/static"
)