aboutsummaryrefslogtreecommitdiff
path: root/internal/api/photo.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/photo.go')
-rw-r--r--internal/api/photo.go43
1 files changed, 42 insertions, 1 deletions
diff --git a/internal/api/photo.go b/internal/api/photo.go
index 7174491..37f9587 100644
--- a/internal/api/photo.go
+++ b/internal/api/photo.go
@@ -1,6 +1,13 @@
package api
-import "time"
+import (
+ "errors"
+ "log"
+ "net/http"
+ "time"
+
+ "github.com/RanXom/galleryd/internal/service"
+)
type photoResponse struct {
ID string `json:"id"`
@@ -10,3 +17,37 @@ type photoResponse struct {
ThumbnailURL string `json:"thumbnail"`
PhotoURL string `json:"photo"`
}
+
+func (s *Server) handlePhoto(
+ w http.ResponseWriter,
+ r *http.Request,
+) {
+ id := r.PathValue("id")
+
+ photo, err := s.gallery.Photo(r.Context(), id)
+ if err != nil {
+ if errors.Is(err, service.ErrPhotoNotFound) {
+ writeError(
+ w,
+ http.StatusNotFound,
+ "photo not found",
+ )
+ return
+ }
+
+ log.Printf("lookup photo: %v", err)
+
+ writeError(
+ w,
+ http.StatusInternalServerError,
+ "failed to lookup photo",
+ )
+ return
+ }
+
+ http.ServeFile(
+ w,
+ r,
+ photo.Path,
+ )
+}