Game list should now be sorted, a new endpoint with the game list in random order have been added.
This commit is contained in:
2
app.yaml
2
app.yaml
@@ -1,5 +1,5 @@
|
|||||||
application: musicserver
|
application: musicserver
|
||||||
version: 2.1.0
|
version: 2.1.4
|
||||||
runtime: go115
|
runtime: go115
|
||||||
api_version: go1
|
api_version: go1
|
||||||
|
|
||||||
|
|||||||
@@ -182,7 +182,9 @@ func resetGameIdSeq() {
|
|||||||
|
|
||||||
func findAllGames() []GameData {
|
func findAllGames() []GameData {
|
||||||
rows, err := dbPool.Query(context.Background(),
|
rows, err := dbPool.Query(context.Background(),
|
||||||
"SELECT id, game_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs FROM game")
|
"SELECT id, game_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs "+
|
||||||
|
"FROM game "+
|
||||||
|
"ORDER BY game_name")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
|
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
openapi: 3.0.3
|
openapi: 3.0.3
|
||||||
info:
|
info:
|
||||||
version: "2.1.3"
|
version: "2.1.4"
|
||||||
title: "Music Server"
|
title: "Music Server"
|
||||||
description: "Added a check to see if song exists before returning it, if not a new song will be picked up."
|
description: "Added a check to see if song exists before returning it, if not a new song will be picked up."
|
||||||
contact:
|
contact:
|
||||||
@@ -166,7 +166,7 @@ paths:
|
|||||||
tags:
|
tags:
|
||||||
- "Music"
|
- "Music"
|
||||||
summary: "Gets all games"
|
summary: "Gets all games"
|
||||||
description: "Gets a list of all games that is in the databse"
|
description: "Gets a list of all games that is in the database"
|
||||||
operationId: "getAll"
|
operationId: "getAll"
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
@@ -180,6 +180,25 @@ paths:
|
|||||||
example: ["God of War", "Final Fantasy VII"]
|
example: ["God of War", "Final Fantasy VII"]
|
||||||
"500":
|
"500":
|
||||||
description: "Something went wrong on the server"
|
description: "Something went wrong on the server"
|
||||||
|
/music/all/random:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- "Music"
|
||||||
|
summary: "Gets all games in random order"
|
||||||
|
description: "Gets a list of all games that is in the database in random order"
|
||||||
|
operationId: "getAllRandom"
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: "A list"
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
example: ["Final Fantasy VII", "God of War"]
|
||||||
|
"500":
|
||||||
|
description: "Something went wrong on the server"
|
||||||
/music/played:
|
/music/played:
|
||||||
put:
|
put:
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
@@ -16,9 +16,13 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
testf()
|
testf()
|
||||||
|
|
||||||
data := VersionData{Version: "2.1.3",
|
data := VersionData{Version: "2.1.4",
|
||||||
Changelog: "Added a check to see if song exists before returning it, if not a new song will be picked up.",
|
Changelog: "Game list should now be sorted, a new endpoint with the game list in random order have been added.",
|
||||||
History: []VersionData{
|
History: []VersionData{
|
||||||
|
{
|
||||||
|
Version: "2.1.3",
|
||||||
|
Changelog: "Added a check to see if song exists before returning it, if not a new song will be picked up.",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Version: "2.1.2",
|
Version: "2.1.2",
|
||||||
Changelog: "Added test server to swagger file.",
|
Changelog: "Added test server to swagger file.",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var currentSong = -1
|
var currentSong = -1
|
||||||
@@ -161,6 +162,20 @@ func getAllGames() []string {
|
|||||||
return jsonArray
|
return jsonArray
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAllGamesRandom() []string {
|
||||||
|
if games == nil || len(games) == 0 {
|
||||||
|
games = findAllGames()
|
||||||
|
}
|
||||||
|
|
||||||
|
var jsonArray []string
|
||||||
|
for _, game := range games {
|
||||||
|
jsonArray = append(jsonArray, game.gameName)
|
||||||
|
}
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
rand.Shuffle(len(jsonArray), func(i, j int) { jsonArray[i], jsonArray[j] = jsonArray[j], jsonArray[i] })
|
||||||
|
return jsonArray
|
||||||
|
}
|
||||||
|
|
||||||
func setPlayed(songNumber int) {
|
func setPlayed(songNumber int) {
|
||||||
if songQue == nil || len(songQue) == 0 || songNumber >= len(songQue) {
|
if songQue == nil || len(songQue) == 0 || songNumber >= len(songQue) {
|
||||||
return
|
return
|
||||||
@@ -248,6 +263,10 @@ func musicHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
_ = json.NewEncoder(w).Encode(getAllGames())
|
_ = json.NewEncoder(w).Encode(getAllGames())
|
||||||
|
|
||||||
|
} else if r.URL.Path == "/music/all/random" && r.Method == http.MethodGet {
|
||||||
|
w.Header().Add("Content-Type", "application/json")
|
||||||
|
_ = json.NewEncoder(w).Encode(getAllGamesRandom())
|
||||||
|
|
||||||
} else if r.URL.Path == "/music/played" && r.Method == http.MethodPut {
|
} else if r.URL.Path == "/music/played" && r.Method == http.MethodPut {
|
||||||
var p Played
|
var p Played
|
||||||
err := json.NewDecoder(r.Body).Decode(&p)
|
err := json.NewDecoder(r.Body).Decode(&p)
|
||||||
|
|||||||
Reference in New Issue
Block a user