Replaced the gin framwwork with echo
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"music-server/pkg/helpers"
|
||||
"music-server/pkg/models"
|
||||
"music-server/pkg/server"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo"
|
||||
)
|
||||
|
||||
type Music struct {
|
||||
@@ -15,86 +16,87 @@ func NewMusic() *Music {
|
||||
return &Music{}
|
||||
}
|
||||
|
||||
func (m *Music) GetSong(ctx *gin.Context) {
|
||||
song := ctx.Query("song")
|
||||
func (m *Music) GetSong(ctx echo.Context) error {
|
||||
song := ctx.QueryParam("song")
|
||||
if song == "" {
|
||||
ctx.String(http.StatusBadRequest, "song can't be empty")
|
||||
return ctx.String(http.StatusBadRequest, "song can't be empty")
|
||||
}
|
||||
s := server.GetSong(song)
|
||||
helpers.SendSong(ctx, s)
|
||||
return helpers.SendSong(ctx, s)
|
||||
}
|
||||
|
||||
func (m *Music) GetSoundCheckSong(ctx *gin.Context) {
|
||||
func (m *Music) GetSoundCheckSong(ctx echo.Context) error {
|
||||
song := server.GetSoundCheckSong()
|
||||
helpers.SendSong(ctx, song)
|
||||
return helpers.SendSong(ctx, song)
|
||||
}
|
||||
|
||||
func (m *Music) ResetMusic(ctx *gin.Context) {
|
||||
func (m *Music) ResetMusic(ctx echo.Context) error {
|
||||
server.Reset()
|
||||
ctx.Status(http.StatusOK)
|
||||
return ctx.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
func (m *Music) GetRandomSong(ctx *gin.Context) {
|
||||
func (m *Music) GetRandomSong(ctx echo.Context) error {
|
||||
song := server.GetRandomSong()
|
||||
helpers.SendSong(ctx, song)
|
||||
return helpers.SendSong(ctx, song)
|
||||
}
|
||||
|
||||
func (m *Music) GetRandomSongLowChance(ctx *gin.Context) {
|
||||
func (m *Music) GetRandomSongLowChance(ctx echo.Context) error {
|
||||
song := server.GetRandomSongLowChance()
|
||||
helpers.SendSong(ctx, song)
|
||||
return helpers.SendSong(ctx, song)
|
||||
}
|
||||
|
||||
func (m *Music) GetRandomSongClassic(ctx *gin.Context) {
|
||||
func (m *Music) GetRandomSongClassic(ctx echo.Context) error {
|
||||
song := server.GetRandomSongClassic()
|
||||
helpers.SendSong(ctx, song)
|
||||
return helpers.SendSong(ctx, song)
|
||||
}
|
||||
|
||||
func (m *Music) GetSongInfo(ctx *gin.Context) {
|
||||
func (m *Music) GetSongInfo(ctx echo.Context) error {
|
||||
song := server.GetSongInfo()
|
||||
ctx.JSON(http.StatusOK, song)
|
||||
return ctx.JSON(http.StatusOK, song)
|
||||
}
|
||||
|
||||
func (m *Music) GetPlayedSongs(ctx *gin.Context) {
|
||||
func (m *Music) GetPlayedSongs(ctx echo.Context) error {
|
||||
songList := server.GetPlayedSongs()
|
||||
ctx.JSON(http.StatusOK, songList)
|
||||
return ctx.JSON(http.StatusOK, songList)
|
||||
}
|
||||
|
||||
func (m *Music) GetNextSong(ctx *gin.Context) {
|
||||
func (m *Music) GetNextSong(ctx echo.Context) error {
|
||||
song := server.GetNextSong()
|
||||
helpers.SendSong(ctx, song)
|
||||
return helpers.SendSong(ctx, song)
|
||||
}
|
||||
|
||||
func (m *Music) GetPreviousSong(ctx *gin.Context) {
|
||||
func (m *Music) GetPreviousSong(ctx echo.Context) error {
|
||||
song := server.GetPreviousSong()
|
||||
helpers.SendSong(ctx, song)
|
||||
return helpers.SendSong(ctx, song)
|
||||
}
|
||||
|
||||
func (m *Music) GetAllGames(ctx *gin.Context) {
|
||||
func (m *Music) GetAllGames(ctx echo.Context) error {
|
||||
gameList := server.GetAllGames()
|
||||
ctx.JSON(http.StatusOK, gameList)
|
||||
return ctx.JSON(http.StatusOK, gameList)
|
||||
}
|
||||
|
||||
func (m *Music) GetAllGamesRandom(ctx *gin.Context) {
|
||||
func (m *Music) GetAllGamesRandom(ctx echo.Context) error {
|
||||
gameList := server.GetAllGamesRandom()
|
||||
ctx.JSON(http.StatusOK, gameList)
|
||||
return ctx.JSON(http.StatusOK, gameList)
|
||||
}
|
||||
|
||||
func (m *Music) PutPlayed(ctx *gin.Context) {
|
||||
func (m *Music) PutPlayed(ctx echo.Context) error {
|
||||
var played models.Played
|
||||
if err := ctx.ShouldBindJSON(&played); err != nil {
|
||||
helpers.NewError(ctx, http.StatusBadRequest, err)
|
||||
return
|
||||
err := ctx.Bind(&played)
|
||||
if err != nil {
|
||||
//helpers.NewError(ctx, http.StatusBadRequest, err)
|
||||
return ctx.JSON(http.StatusBadRequest, err)
|
||||
}
|
||||
server.SetPlayed(played.Song)
|
||||
ctx.Status(http.StatusOK)
|
||||
return ctx.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
func (m *Music) AddLatestToQue(ctx *gin.Context) {
|
||||
func (m *Music) AddLatestToQue(ctx echo.Context) error {
|
||||
server.AddLatestToQue()
|
||||
ctx.Status(http.StatusOK)
|
||||
return ctx.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
func (m *Music) AddLatestPlayed(ctx *gin.Context) {
|
||||
func (m *Music) AddLatestPlayed(ctx echo.Context) error {
|
||||
server.AddLatestPlayed()
|
||||
ctx.Status(http.StatusOK)
|
||||
return ctx.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user