summaryrefslogtreecommitdiff
path: root/internal/listing/service.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/listing/service.go')
-rw-r--r--internal/listing/service.go36
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
+}