101 lines
2.1 KiB
Go
101 lines
2.1 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"music-server/pkg/helpers"
|
|
"music-server/pkg/models"
|
|
"music-server/pkg/server"
|
|
"net/http"
|
|
)
|
|
|
|
type Music struct {
|
|
}
|
|
|
|
func NewMusic() *Music {
|
|
return &Music{}
|
|
}
|
|
|
|
func (m *Music) GetSong(ctx *gin.Context) {
|
|
song := ctx.Query("song")
|
|
if song == "" {
|
|
ctx.String(http.StatusBadRequest, "song can't be empty")
|
|
}
|
|
s := server.GetSong(song)
|
|
helpers.SendSong(ctx, s)
|
|
}
|
|
|
|
func (m *Music) GetSoundCheckSong(ctx *gin.Context) {
|
|
song := server.GetSoundCheckSong()
|
|
helpers.SendSong(ctx, song)
|
|
}
|
|
|
|
func (m *Music) ResetMusic(ctx *gin.Context) {
|
|
server.Reset()
|
|
ctx.Status(http.StatusOK)
|
|
}
|
|
|
|
func (m *Music) GetRandomSong(ctx *gin.Context) {
|
|
song := server.GetRandomSong()
|
|
helpers.SendSong(ctx, song)
|
|
}
|
|
|
|
func (m *Music) GetRandomSongLowChance(ctx *gin.Context) {
|
|
song := server.GetRandomSongLowChance()
|
|
helpers.SendSong(ctx, song)
|
|
}
|
|
|
|
func (m *Music) GetRandomSongClassic(ctx *gin.Context) {
|
|
song := server.GetRandomSongClassic()
|
|
helpers.SendSong(ctx, song)
|
|
}
|
|
|
|
func (m *Music) GetSongInfo(ctx *gin.Context) {
|
|
song := server.GetSongInfo()
|
|
ctx.JSON(http.StatusOK, song)
|
|
}
|
|
|
|
func (m *Music) GetPlayedSongs(ctx *gin.Context) {
|
|
songList := server.GetPlayedSongs()
|
|
ctx.JSON(http.StatusOK, songList)
|
|
}
|
|
|
|
func (m *Music) GetNextSong(ctx *gin.Context) {
|
|
song := server.GetNextSong()
|
|
helpers.SendSong(ctx, song)
|
|
}
|
|
|
|
func (m *Music) GetPreviousSong(ctx *gin.Context) {
|
|
song := server.GetPreviousSong()
|
|
helpers.SendSong(ctx, song)
|
|
}
|
|
|
|
func (m *Music) GetAllGames(ctx *gin.Context) {
|
|
gameList := server.GetAllGames()
|
|
ctx.JSON(http.StatusOK, gameList)
|
|
}
|
|
|
|
func (m *Music) GetAllGamesRandom(ctx *gin.Context) {
|
|
gameList := server.GetAllGamesRandom()
|
|
ctx.JSON(http.StatusOK, gameList)
|
|
}
|
|
|
|
func (m *Music) PutPlayed(ctx *gin.Context) {
|
|
var played models.Played
|
|
if err := ctx.ShouldBindJSON(&played); err != nil {
|
|
helpers.NewError(ctx, http.StatusBadRequest, err)
|
|
return
|
|
}
|
|
server.SetPlayed(played.Song)
|
|
ctx.Status(http.StatusOK)
|
|
}
|
|
|
|
func (m *Music) AddLatestToQue(ctx *gin.Context) {
|
|
server.AddLatestToQue()
|
|
ctx.Status(http.StatusOK)
|
|
}
|
|
|
|
func (m *Music) AddLatestPlayed(ctx *gin.Context) {
|
|
server.AddLatestPlayed()
|
|
ctx.Status(http.StatusOK)
|
|
}
|