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
|
||||
version: 2.1.0
|
||||
version: 2.1.4
|
||||
runtime: go115
|
||||
api_version: go1
|
||||
|
||||
|
||||
@@ -182,7 +182,9 @@ func resetGameIdSeq() {
|
||||
|
||||
func findAllGames() []GameData {
|
||||
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 {
|
||||
_, _ = fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
openapi: 3.0.3
|
||||
info:
|
||||
version: "2.1.3"
|
||||
version: "2.1.4"
|
||||
title: "Music Server"
|
||||
description: "Added a check to see if song exists before returning it, if not a new song will be picked up."
|
||||
contact:
|
||||
@@ -166,7 +166,7 @@ paths:
|
||||
tags:
|
||||
- "Music"
|
||||
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"
|
||||
responses:
|
||||
"200":
|
||||
@@ -180,6 +180,25 @@ paths:
|
||||
example: ["God of War", "Final Fantasy VII"]
|
||||
"500":
|
||||
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:
|
||||
put:
|
||||
tags:
|
||||
|
||||
@@ -16,9 +16,13 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
testf()
|
||||
|
||||
data := 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.",
|
||||
data := VersionData{Version: "2.1.4",
|
||||
Changelog: "Game list should now be sorted, a new endpoint with the game list in random order have been added.",
|
||||
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",
|
||||
Changelog: "Added test server to swagger file.",
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var currentSong = -1
|
||||
@@ -161,6 +162,20 @@ func getAllGames() []string {
|
||||
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) {
|
||||
if songQue == nil || len(songQue) == 0 || songNumber >= len(songQue) {
|
||||
return
|
||||
@@ -248,6 +263,10 @@ func musicHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
_ = 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 {
|
||||
var p Played
|
||||
err := json.NewDecoder(r.Body).Decode(&p)
|
||||
|
||||
Reference in New Issue
Block a user