]> git.example.dev Git - binbsis50-sm.git/commitdiff
updated: some handling, can count songs and makefile better
author2weiEmu <saalbach.robert@outlook.de>
Thu, 12 Mar 2026 00:32:58 +0000 (01:32 +0100)
committer2weiEmu <saalbach.robert@outlook.de>
Thu, 12 Mar 2026 00:32:58 +0000 (01:32 +0100)
Makefile
pkg/dbhandling/dbhandling.go
songmanager
testing/dummy_testing_data.py

index 073dee5c3a531b767c2bb6f12ff25266bbc21166..a9aceee0d8f14cf82b678bfc279097170c7c2232 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,11 +2,12 @@
 
 default: .
        # first we must setup the test database
-       sudo docker stop redis || true
-       sudo docker rm redis || true
        sudo docker run -d --name redis -p 6379:6379 redis:latest
        
        python3 ./testing/dummy_testing_data.py
        # now we can run the main app with the right arguments
        go build .
-       ./songmanager -port 8000 -binb_location="" -songs_location="" -redis_location="localhost:6379" -container_name=""
+       ./songmanager -port 8000 -binb_location="" -songs_location="" -redis_location="localhost:6379" -container_name="" || true
+
+       docker stop redis || true
+       docker rm redis || true
index bf16812b428883facac146022a63118b5dde805c..9111ba9aaf07b939b2a3c6c952d6bf002365fe5e 100644 (file)
@@ -2,12 +2,16 @@ package dbhandling
 
 import (
        "context"
-       "fmt"
+       "encoding/json"
        "net/http"
 
        "github.com/redis/go-redis/v9"
 )
 
+type DBStatusMessage struct {
+       TotalSongCount int
+}
+
 type DBWrapper struct {
        RedisDb *redis.Client
        ctx context.Context
@@ -31,5 +35,19 @@ func (dbw *DBWrapper) GetDBStatus(w http.ResponseWriter, r *http.Request) {
                return
        }
 
-       fmt.Println(dbw.RedisDb.Keys(dbw.ctx, "song"))
+       keys, err := dbw.RedisDb.Keys(dbw.ctx, "song:*").Result()
+       if err != nil {
+               panic(err)
+       }
+       key_count := len(keys)
+
+       m := DBStatusMessage{
+               TotalSongCount: key_count,
+       }
+       b, err := json.Marshal(m)
+       if err != nil {
+               panic(err)
+       }
+
+       w.Write(b)
 }
index a1639032362bbe340b9076fe60017dd652a16731..07965293f111cccd5028d7907e94d1815e973a02 100755 (executable)
Binary files a/songmanager and b/songmanager differ
index 82c80a830bb647195d79bb107b3a0a0e24d36a1d..3dd24c2f591d3c551da09729693bb2c6f1912f9d 100644 (file)
@@ -1,5 +1,6 @@
 import redis
 
+
 def main():
     r = redis.Redis(host="localhost", port="6379", decode_responses=True)
 
@@ -8,9 +9,7 @@ def main():
             "artistNames": "firstartist, secondartist",
             "songNames": "firstsongname, secondsongname"
         })
-        r.zadd("hits", { i: i } )
-
-
+        r.zadd("hits", {i: i})
 
 
 if __name__ == "__main__":