From 9aabff9752b3464291bc42a4543477369acd4d35 Mon Sep 17 00:00:00 2001 From: Adam French Date: Thu, 20 Nov 2025 18:04:31 +0000 Subject: [PATCH] adding spotify api interaction --- backend/handlers/handle_post.go | 6 +++--- backend/handlers/handle_spotify.go | 21 +++++++++++++++++++++ backend/handlers/{handler.go => store.go} | 2 +- backend/services/spotify.go | 1 + 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 backend/handlers/handle_spotify.go rename backend/handlers/{handler.go => store.go} (73%) create mode 100644 backend/services/spotify.go diff --git a/backend/handlers/handle_post.go b/backend/handlers/handle_post.go index f31d5e9..399b2df 100644 --- a/backend/handlers/handle_post.go +++ b/backend/handlers/handle_post.go @@ -13,7 +13,7 @@ type CreatePostInput struct { Author string `json:"author" binding:"required"` } -func (h *Handler) GetPosts(c *gin.Context) { +func (h *Store) GetPosts(c *gin.Context) { var posts []models.Post if err := h.DB.Find(&posts).Error; err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) @@ -22,7 +22,7 @@ func (h *Handler) GetPosts(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"data": models.Post{}}) } -func (h *Handler) CreatePost(c *gin.Context) { +func (h *Store) CreatePost(c *gin.Context) { var input CreatePostInput if err := c.ShouldBindBodyWithJSON(&input); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -36,7 +36,7 @@ func (h *Handler) CreatePost(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"data": post}) } -func (h *Handler) UpdatePost(c *gin.Context) { +func (h *Store) UpdatePost(c *gin.Context) { id := c.Param("id") var post models.Post if err := h.DB.First(&post, id).Error; err != nil { diff --git a/backend/handlers/handle_spotify.go b/backend/handlers/handle_spotify.go new file mode 100644 index 0000000..7f6f1cf --- /dev/null +++ b/backend/handlers/handle_spotify.go @@ -0,0 +1,21 @@ +package handlers + +import ( + "github.com/gin-gonic/gin" +) + +func (store *Store) ListeningTo(c *gin.Context) { + + // Communicate with spotify API + // Return if I'm listening to a song + return +} + +func (store *Store) SendSong(c *gin.Context) { + + // Communicate with spotify API + // Play song on spotify + // Disallow new song for duration of song + + return +} diff --git a/backend/handlers/handler.go b/backend/handlers/store.go similarity index 73% rename from backend/handlers/handler.go rename to backend/handlers/store.go index 13e07c2..75ad1b5 100644 --- a/backend/handlers/handler.go +++ b/backend/handlers/store.go @@ -4,6 +4,6 @@ import ( "gorm.io/gorm" ) -type Handler struct { +type Store struct { DB *gorm.DB } diff --git a/backend/services/spotify.go b/backend/services/spotify.go new file mode 100644 index 0000000..5e568ea --- /dev/null +++ b/backend/services/spotify.go @@ -0,0 +1 @@ +package services