diff options
| author | mihna123 <mihailonvojinovic@gmail.com> | 2026-08-23 17:47:16 +0200 |
|---|---|---|
| committer | mihna123 <mihailonvojinovic@gmail.com> | 2026-08-23 17:47:16 +0200 |
| commit | 1e43f2a59bba0462494066767fac140601791718 (patch) | |
| tree | 45a4d0c4f3159f4acd7949eebbbfe138e4c1bc3f /internal/listing/service.go | |
| parent | 516ed55e09a253255e7056d31eb59acfd68db3a8 (diff) | |
| download | openstore-1e43f2a59bba0462494066767fac140601791718.tar.gz openstore-1e43f2a59bba0462494066767fac140601791718.zip | |
listing: implement a service layer stub along with tests
Diffstat (limited to 'internal/listing/service.go')
| -rw-r--r-- | internal/listing/service.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/listing/service.go b/internal/listing/service.go new file mode 100644 index 0000000..302628b --- /dev/null +++ b/internal/listing/service.go @@ -0,0 +1,36 @@ +package listing + +import "log/slog" + +type Repository interface { + GetAll() ([]Listing, error) + GetByCategory(category string) ([]Listing, error) +} + +type Service struct { + repository Repository +} + +func New(r Repository) *Service { + return &Service{repository: r} +} + +func (s *Service) GetAll() ([]Listing, error) { + listings, err := s.repository.GetAll() + if err != nil { + slog.Error("listing service", "error", err) + return nil, err + } + + return listings, nil +} + +func (s *Service) GetByCategory(c string) ([]Listing, error) { + listings, err := s.repository.GetByCategory(c) + if err != nil { + slog.Error("listing service", "error", err) + return nil, err + } + + return listings, nil +} |
