From: 2weiEmu Date: Fri, 19 Jun 2026 14:32:44 +0000 (+0200) Subject: fixed the hardcoded startcount X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=48223cd81274277dc9cb5819c8287e5d3abbb8f4;p=binbsis50-sm.git fixed the hardcoded startcount --- diff --git a/main.go b/main.go index d12e12c..3fcb286 100644 --- 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 diff --git a/pkg/dbhandling/dbhandling.go b/pkg/dbhandling/dbhandling.go index 1b6e1f1..15ff76a 100644 --- a/pkg/dbhandling/dbhandling.go +++ b/pkg/dbhandling/dbhandling.go @@ -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, } } diff --git a/pkg/dbhandling/songsapi.go b/pkg/dbhandling/songsapi.go index 068b2f2..e1e5506 100644 --- a/pkg/dbhandling/songsapi.go +++ b/pkg/dbhandling/songsapi.go @@ -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, diff --git a/songmanager b/songmanager index 8cf3738..0627d51 100755 Binary files a/songmanager and b/songmanager differ