From 58ff8a64cc52953aebf3860e29be259f174271bd Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 23 Apr 2022 11:40:54 +0200 Subject: [PATCH] Fixed some bugs * Fixed bug with sync * Made default list of game randomized * Added get all games ordered * Added air for live reload --- .air.toml | 36 ++++++++++++++++++++++++++++++++++++ .gitignore | 2 +- .idea/dataSources.xml | 6 ++++++ cmd/swagger/swagger.yaml | 19 +++++++++++++++++++ go.sum | 4 ++++ pkg/conf/conf.go | 3 ++- pkg/server/sync.go | 14 ++++++++------ 7 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 .air.toml diff --git a/.air.toml b/.air.toml new file mode 100644 index 0000000..6c164b6 --- /dev/null +++ b/.air.toml @@ -0,0 +1,36 @@ +root = "." +testdata_dir = "testdata" +tmp_dir = "tmp" + +[build] + bin = "./tmp/main" + cmd = "go build -o ./tmp/main ./cmd" + delay = 1000 + exclude_dir = ["assets", "tmp", "vendor", "testdata", "frontend", "swagger", "cmd/frontend", "cmd/swagger"] + exclude_file = [] + exclude_regex = ["_test.go"] + exclude_unchanged = false + follow_symlink = false + full_bin = "" + include_dir = [] + include_ext = ["go", "tpl", "tmpl", "html"] + kill_delay = "0s" + log = "build-errors.log" + send_interrupt = false + stop_on_error = true + +[color] + app = "" + build = "yellow" + main = "magenta" + runner = "green" + watcher = "cyan" + +[log] + time = false + +[misc] + clean_on_exit = false + +[screen] + clear_on_rebuild = false diff --git a/.gitignore b/.gitignore index 8b13789..1c2f433 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ - +tmp \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 16a0ef3..49a4119 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -19,5 +19,11 @@ org.postgresql.Driver jdbc:postgresql://ssh.sanplex.xyz:9432/music_test + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://ssh.sanplex.xyz:9432/music_prod + \ No newline at end of file diff --git a/cmd/swagger/swagger.yaml b/cmd/swagger/swagger.yaml index 1e3e591..6910dc2 100644 --- a/cmd/swagger/swagger.yaml +++ b/cmd/swagger/swagger.yaml @@ -182,6 +182,25 @@ paths: example: ["God of War", "Final Fantasy VII"] "500": description: "Something went wrong on the server" + /music/all/order: + get: + tags: + - "Music" + summary: "Gets all games in order" + description: "Gets a ordered list of all games that is in the database" + operationId: "getAll" + responses: + "200": + description: "A list" + content: + application/json: + schema: + type: array + items: + type: string + example: [ "God of War", "Final Fantasy VII" ] + "500": + description: "Something went wrong on the server" /music/all/random: get: tags: diff --git a/go.sum b/go.sum index bf6c087..d82d39d 100644 --- a/go.sum +++ b/go.sum @@ -145,6 +145,8 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -710,6 +712,8 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ= golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= diff --git a/pkg/conf/conf.go b/pkg/conf/conf.go index a44b07f..e1b2cac 100644 --- a/pkg/conf/conf.go +++ b/pkg/conf/conf.go @@ -74,7 +74,8 @@ func SetupRestServer(frontend embed.FS, swagger embed.FS) { musicGroup.GET("list", music.GetPlayedSongs) musicGroup.GET("next", music.GetNextSong) musicGroup.GET("previous", music.GetPreviousSong) - musicGroup.GET("all", music.GetAllGames) + musicGroup.GET("all", music.GetAllGamesRandom) + musicGroup.GET("all/order", music.GetAllGames) musicGroup.GET("all/random", music.GetAllGamesRandom) musicGroup.PUT("played", music.PutPlayed) musicGroup.GET("addQue", music.AddLatestToQue) diff --git a/pkg/server/sync.go b/pkg/server/sync.go index 7eb629d..337e32d 100644 --- a/pkg/server/sync.go +++ b/pkg/server/sync.go @@ -40,7 +40,7 @@ func SyncGames() { innerFiles, err := ioutil.ReadDir(path) if err != nil { - log.Fatal(err) + log.Println(err) } id := -1 for _, song := range innerFiles { @@ -114,7 +114,7 @@ func checkSongs(gameDir string, gameId int) { files, err := ioutil.ReadDir(gameDir) if err != nil { - log.Fatal(err) + log.Println(err) } for _, entry := range files { path := gameDir + entry.Name() @@ -143,10 +143,12 @@ func checkBrokenSongs() { if err != nil { //File not found brokenSongs = append(brokenSongs, song) - } - err = openFile.Close() - if err != nil { - log.Fatal(err) + fmt.Printf("song broken: %v", song.Path) + } else { + err = openFile.Close() + if err != nil { + log.Println(err) + } } } db.RemoveBrokenSongs(brokenSongs)