Replaced the gin framwwork with echo
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"music-server/pkg/helpers"
|
||||
"music-server/pkg/server"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo"
|
||||
)
|
||||
|
||||
type Index struct {
|
||||
@@ -14,16 +14,15 @@ func NewIndex() *Index {
|
||||
return &Index{}
|
||||
}
|
||||
|
||||
func (i *Index) GetVersion(ctx *gin.Context) {
|
||||
func (i *Index) GetVersion(ctx echo.Context) error {
|
||||
versionHistory := server.GetVersionHistory()
|
||||
if versionHistory.Version == "" {
|
||||
helpers.NewError(ctx, http.StatusNotFound, nil)
|
||||
return
|
||||
return ctx.JSON(http.StatusNotFound, "version not found")
|
||||
}
|
||||
ctx.JSON(http.StatusOK, versionHistory)
|
||||
return ctx.JSON(http.StatusOK, versionHistory)
|
||||
}
|
||||
|
||||
func (i *Index) GetDBTest(ctx *gin.Context) {
|
||||
func (i *Index) GetDBTest(ctx echo.Context) error {
|
||||
server.TestDB()
|
||||
ctx.JSON(http.StatusOK, "TestedDB")
|
||||
return ctx.JSON(http.StatusOK, "TestedDB")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"log"
|
||||
"music-server/pkg/server"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/labstack/echo"
|
||||
)
|
||||
|
||||
type Sync struct {
|
||||
@@ -14,25 +15,33 @@ func NewSync() *Sync {
|
||||
return &Sync{}
|
||||
}
|
||||
|
||||
func (s *Sync) SyncGames(ctx *gin.Context) {
|
||||
func (s *Sync) SyncGames(ctx echo.Context) error {
|
||||
server.SyncGames()
|
||||
server.Reset()
|
||||
ctx.JSON(http.StatusOK, "Games are synced")
|
||||
return ctx.JSON(http.StatusOK, "Games are synced")
|
||||
}
|
||||
|
||||
func (s *Sync) SyncGamesQuick(ctx *gin.Context) {
|
||||
func (s *Sync) SyncGamesQuick(ctx echo.Context) error {
|
||||
server.SyncGamesQuick()
|
||||
server.Reset()
|
||||
ctx.JSON(http.StatusOK, "Games are synced")
|
||||
return ctx.JSON(http.StatusOK, "Games are synced")
|
||||
}
|
||||
|
||||
func (s *Sync) SyncGamesNew(ctx *gin.Context) {
|
||||
response := server.SyncGamesNew()
|
||||
func (s *Sync) SyncGamesNewOnlyChanges(ctx echo.Context) error {
|
||||
log.Println("Syncing games new")
|
||||
response := server.SyncGamesNewOnlyChanges()
|
||||
server.Reset()
|
||||
ctx.JSON(http.StatusOK, response)
|
||||
return ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (s *Sync) ResetGames(ctx *gin.Context) {
|
||||
server.ResetDB()
|
||||
ctx.JSON(http.StatusOK, "Games and songs are deleted from the database")
|
||||
func (s *Sync) SyncGamesNewFull(ctx echo.Context) error {
|
||||
log.Println("Syncing games new full")
|
||||
response := server.SyncGamesNewFull()
|
||||
server.Reset()
|
||||
return ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (s *Sync) ResetGames(ctx echo.Context) error {
|
||||
server.ResetDB()
|
||||
return ctx.JSON(http.StatusOK, "Games and songs are deleted from the database")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user