diff options
| author | RanXom <saiyedshizain@gmail.com> | 2026-07-13 18:41:45 +0530 |
|---|---|---|
| committer | RanXom <saiyedshizain@gmail.com> | 2026-07-13 18:41:45 +0530 |
| commit | ef5a8b157db8361d2a592f1481ba809ca49dc57d (patch) | |
| tree | 6f597a6f8a144c6f15933b2d75ad1092f7794082 | |
| parent | d754ce4c11af51e06515275b58a3f337a440ed9d (diff) | |
| download | galleryd-ef5a8b157db8361d2a592f1481ba809ca49dc57d.tar.xz galleryd-ef5a8b157db8361d2a592f1481ba809ca49dc57d.zip | |
feat(service): add photo lookup
| -rw-r--r-- | internal/service/photo.go | 29 | ||||
| -rw-r--r-- | internal/service/service.go | 3 |
2 files changed, 32 insertions, 0 deletions
diff --git a/internal/service/photo.go b/internal/service/photo.go new file mode 100644 index 0000000..018ba6b --- /dev/null +++ b/internal/service/photo.go @@ -0,0 +1,29 @@ +package service + +import ( + "context" + "errors" + + "github.com/RanXom/galleryd/internal/gallery" +) + +var ErrPhotoNotFound = errors.New("photo not found") + +// Photo returns a single photo by its ID. +func (s *galleryService) Photo( + ctx context.Context, + id string, +) (gallery.Photo, error) { + select { + case <-ctx.Done(): + return gallery.Photo{}, ctx.Err() + default: + } + + photo, ok := s.index.byID[id] + if !ok { + return gallery.Photo{}, ErrPhotoNotFound + } + + return photo, nil +} diff --git a/internal/service/service.go b/internal/service/service.go index 252abed..68a764e 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -13,4 +13,7 @@ type GalleryService interface { // Gallery returns the currently loaded gallery. Gallery(ctx context.Context) ([]gallery.Photo, error) + + // Photo returns a single photo by its ID. + Photo(ctx context.Context, id string) (gallery.Photo, error) } |