]> git.example.dev Git - binbsis50-sm.git/commitdiff
fixed the hardcoded startcount
author2weiEmu <saalbach.robert@outlook.de>
Fri, 19 Jun 2026 14:32:44 +0000 (16:32 +0200)
committer2weiEmu <saalbach.robert@outlook.de>
Fri, 19 Jun 2026 14:32:44 +0000 (16:32 +0200)
main.go
pkg/dbhandling/dbhandling.go
pkg/dbhandling/songsapi.go
songmanager

diff --git a/main.go b/main.go
index d12e12c096d9463de7828ccbf4ac9e3b89413f74..3fcb2860c26bf61a9f3395bc062c9b7e44241584 100644 (file)
--- a/main.go
+++ b/main.go
@@ -39,7 +39,7 @@ func main() {
        mainLogger.Println("Given container_name:", *paramContainerName) // eg: binbsis50
        
 
-       DBwrapper := dbhandling.NewDbWrapper(*paramRedisLocation, *paramSongsLocation, *paramContainerName, *paramBinbLocation)
+       DBwrapper := dbhandling.NewDbWrapperWithLogging(*paramRedisLocation, *paramSongsLocation, *paramContainerName, *paramBinbLocation, mainLogger)
 
 
        // Setting up the routing
index 1b6e1f11cc00716d8c1115252de3991b2678b988..15ff76a3fae56d6a9171b479b0c7c2b25bf1f390 100644 (file)
@@ -3,6 +3,7 @@ package dbhandling
 import (
        "context"
        "encoding/json"
+       "log"
        "net/http"
        "os"
        "path/filepath"
@@ -46,6 +47,8 @@ type DBWrapper struct {
        PathToSongs string
        ImageName string
        BinbLocation string
+
+       log *log.Logger
 }
 
 func NewDbWrapper(redisLocation string, songsLocation string, imageName string, binbLocation string) DBWrapper {
@@ -60,6 +63,26 @@ func NewDbWrapper(redisLocation string, songsLocation string, imageName string,
                songsLocation,
                imageName,
                binbLocation,
+               log.Default(),
+       }
+}
+
+func NewDbWrapperWithLogging(
+       redisLocation string, songsLocation string, imageName string,
+       binbLocation string, logger *log.Logger,
+) DBWrapper {
+       return DBWrapper {
+               redis.NewClient(&redis.Options{
+                       Addr: redisLocation,
+                       Password: "",
+                       DB: 0,
+                       Protocol: 2,
+               }),
+               context.Background(),
+               songsLocation,
+               imageName,
+               binbLocation,
+               logger,
        }
 }
 
index 068b2f2f055e992aa1deb71c18ea69937b8cb6d7..e1e5506b8c59aa37f97cd6d2ec6b08f7ddb7d6d9 100644 (file)
@@ -87,11 +87,13 @@ func (dbw *DBWrapper) SongsGet(w http.ResponseWriter, r *http.Request) {
  * Create a new song in the database (only in the main list don't add to anything)
  **/
 func (dbw *DBWrapper) SongsCreate(w http.ResponseWriter, r *http.Request) {
-       count := START_COUNT // safe high count to create new songs WARNING:, this should only be used once ideally
-       START_COUNT += 1
-
+       count, err := dbw.getSongCount()
+       if err != nil {
+               w.WriteHeader(http.StatusInternalServerError)
+               return
+       }
        newSong := DBSong{}
-       err := json.NewDecoder(r.Body).Decode(&newSong)
+       err = json.NewDecoder(r.Body).Decode(&newSong)
 
        cmd := dbw.RedisDb.HSet(dbw.Ctx, "song:" + strconv.Itoa(count + 1),
                "artistName", newSong.ArtistName,
index 8cf37388757ef3b2e66e53609eb480b946092b5b..0627d51c4602dc5c88a1b06b5e03aab7ba6b4c75 100755 (executable)
Binary files a/songmanager and b/songmanager differ