adding spotify api interaction

This commit is contained in:
2025-11-20 18:04:31 +00:00
parent 10b5dfabfd
commit 9aabff9752
4 changed files with 26 additions and 4 deletions

View File

@@ -13,7 +13,7 @@ type CreatePostInput struct {
Author string `json:"author" binding:"required"` Author string `json:"author" binding:"required"`
} }
func (h *Handler) GetPosts(c *gin.Context) { func (h *Store) GetPosts(c *gin.Context) {
var posts []models.Post var posts []models.Post
if err := h.DB.Find(&posts).Error; err != nil { if err := h.DB.Find(&posts).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) 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{}}) 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 var input CreatePostInput
if err := c.ShouldBindBodyWithJSON(&input); err != nil { if err := c.ShouldBindBodyWithJSON(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) 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}) 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") id := c.Param("id")
var post models.Post var post models.Post
if err := h.DB.First(&post, id).Error; err != nil { if err := h.DB.First(&post, id).Error; err != nil {

View File

@@ -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
}

View File

@@ -4,6 +4,6 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
type Handler struct { type Store struct {
DB *gorm.DB DB *gorm.DB
} }

View File

@@ -0,0 +1 @@
package services