Files
MusicServer/pkg/api/music.go

103 lines
2.4 KiB
Go

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