This repository has been archived on 2024-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
core-old/internal/service/version.go
Dawid Wysokiński 1c75179c12
All checks were successful
continuous-integration/drone/push Build is passing
refactor: version - split the List function into two
2022-12-22 08:03:33 +01:00

47 lines
1.1 KiB
Go

package service
import (
"context"
"fmt"
"gitea.dwysokinski.me/twhelp/core/internal/domain"
)
type VersionRepository interface {
List(ctx context.Context) ([]domain.Version, error)
ListCount(ctx context.Context) ([]domain.Version, int64, error)
GetByCode(ctx context.Context, code string) (domain.Version, error)
}
type Version struct {
repo VersionRepository
}
func NewVersion(repo VersionRepository) *Version {
return &Version{repo: repo}
}
func (v *Version) List(ctx context.Context) ([]domain.Version, error) {
versions, err := v.repo.List(ctx)
if err != nil {
return nil, fmt.Errorf("VersionRepository.List: %w", err)
}
return versions, nil
}
func (v *Version) ListCount(ctx context.Context) ([]domain.Version, int64, error) {
versions, count, err := v.repo.ListCount(ctx)
if err != nil {
return nil, 0, fmt.Errorf("VersionRepository.ListCount: %w", err)
}
return versions, count, nil
}
func (v *Version) GetByCode(ctx context.Context, code string) (domain.Version, error) {
version, err := v.repo.GetByCode(ctx, code)
if err != nil {
return domain.Version{}, fmt.Errorf("VersionRepository.GetByCode: %w", err)
}
return version, nil
}