From 90f0dd60e3ad1885e90f6372b0cac21cf2f6f569 Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Sun, 18 Mar 2018 01:09:48 +0100
Subject: [PATCH] Switched to dark theme

---
 main.go | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)

diff --git a/main.go b/main.go
index 9bb3c47..e153ae3 100644
--- a/main.go
+++ b/main.go
@@ -346,6 +346,92 @@ func main() {
 		fmt.Fprint(w, "Image not found")
 	})))
 
+	http.Handle("/a/", http.StripPrefix("/a/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		user := parseUser(r)
+
+		type AlbumImage struct {
+			Id string
+			Title string
+			Description string
+			Position int
+		}
+
+		type Album struct {
+			Id string
+			Title string
+			Description string
+			CreatedAt time.Time
+			Images []AlbumImage
+		}
+
+		type AlbumDetailData struct {
+			User   UserInfo
+			Album Album
+			IsMine bool
+		}
+
+		_, albumId := path.Split(r.URL.Path)
+		result, err := db.Query(`
+			SELECT
+				id,
+				owner,
+				coalesce(title,  ''),
+				coalesce(description, ''),
+        		coalesce(created_at, to_timestamp(0))
+			FROM albums
+			WHERE id = $1
+			`, albumId)
+		if err != nil {
+			panic(err)
+		}
+
+		var info Album
+		if result.Next() {
+			var owner string
+			err := result.Scan(&info.Id, &owner, &info.Title, &info.Description, &info.CreatedAt)
+			if err != nil {
+				panic(err)
+			}
+
+			result, err := db.Query(`
+			SELECT
+				image,
+				title,
+				description,
+				position
+			FROM album_images
+			WHERE album = $1
+			ORDER BY position ASC
+			`, albumId)
+			if err != nil {
+				panic(err)
+			}
+
+			for result.Next() {
+				var image AlbumImage
+				err := result.Scan(&image.Id, &owner, &image.Title, &image.Description, &image.Position)
+				if err != nil {
+					panic(err)
+				}
+
+				info.Images = append(info.Images, image)
+			}
+
+			if err = returnResult(w, "album_detail.html", AlbumDetailData{
+				user,
+				info,
+				owner == user.Id,
+			}); err != nil {
+				panic(err)
+			}
+
+			return
+		}
+
+		w.WriteHeader(http.StatusNotFound)
+		fmt.Fprint(w, "Image not found")
+	})))
+
 	http.HandleFunc("/me/images/", func(w http.ResponseWriter, r *http.Request) {
 		user := parseUser(r)
 
-- 
GitLab