]> git.example.dev Git - binbsis50-sm.git/commitdiff
updated: mux has method filtering built-in
author2weiEmu <saalbach.robert@outlook.de>
Mon, 13 Apr 2026 08:46:15 +0000 (10:46 +0200)
committer2weiEmu <saalbach.robert@outlook.de>
Mon, 13 Apr 2026 08:46:15 +0000 (10:46 +0200)
main.go
pkg/dbhandling/filesapi.go
pkg/dbhandling/roomsapi.go
pkg/dbhandling/songsapi.go
pkg/dbhandling/songsapi_test.go [new file with mode: 0644]
testing/dummy_testing_data.py

diff --git a/main.go b/main.go
index 8fedd66a43fd736df374dbc65470676fcba0f654..6f5b5029c622ea105fa20148a43cecdb56d4b7c8 100644 (file)
--- a/main.go
+++ b/main.go
@@ -52,25 +52,25 @@ func main() {
        mux.Handle("/", http.FileServer(http.Dir("./public/")))
 
        // api/songs/ - api related to raw songs
-       mux.HandleFunc("/api/songs/get", DBwrapper.SongsGet)
-       mux.HandleFunc("/api/songs/create", DBwrapper.SongsCreate)
-       mux.HandleFunc("/api/songs/update/{id}", DBwrapper.SongsUpdateById)
-       mux.HandleFunc("/api/songs/delete/{id}", DBwrapper.SongsDeleteById)
+       mux.HandleFunc("GET /api/songs/get", DBwrapper.SongsGet)
+       mux.HandleFunc("POST /api/songs/create", DBwrapper.SongsCreate)
+       mux.HandleFunc("PUT /api/songs/update/{id}", DBwrapper.SongsUpdateById)
+       mux.HandleFunc("DELETE /api/songs/delete/{id}", DBwrapper.SongsDeleteById)
 
        // api/rooms - api related to managaing rooms
-       mux.HandleFunc("/api/rooms/get", DBwrapper.RoomsGet)
-       mux.HandleFunc("/api/rooms/create/", DBwrapper.RoomsCreate)
-       mux.HandleFunc("/api/rooms/add/{name}/{id}", DBwrapper.RoomsAddByNameAndId)
-       mux.HandleFunc("/api/rooms/remove/{name}/{id}", DBwrapper.RoomsRemoveByNameAndId)
-       mux.HandleFunc("/api/rooms/delete/{name}", DBwrapper.RoomsDeleteByName)
+       mux.HandleFunc("GET /api/rooms/get", DBwrapper.RoomsGet)
+       mux.HandleFunc("POST /api/rooms/create/", DBwrapper.RoomsCreate)
+       mux.HandleFunc("PUT /api/rooms/add/{name}/{id}", DBwrapper.RoomsAddByNameAndId)
+       mux.HandleFunc("PUT /api/rooms/remove/{name}/{id}", DBwrapper.RoomsRemoveByNameAndId)
+       mux.HandleFunc("DELETE /api/rooms/delete/{name}", DBwrapper.RoomsDeleteByName)
 
        // api/files - api related to song files
-       mux.HandleFunc("/api/files/get", DBwrapper.FilesGet)
-       mux.HandleFunc("/api/files/createWithURL", DBwrapper.FilesCreateWithURL)
-       mux.HandleFunc("/api/files/createWithUpload", DBwrapper.FilesCreateWithUpload)
-       mux.HandleFunc("/api/files/delete/{id}", DBwrapper.FilesDeleteById)
-       mux.HandleFunc("/api/files/rename/{id}", DBwrapper.FilesRenameById)
-       mux.HandleFunc("/api/files/replace/{id}", DBwrapper.FilesReplaceById)
+       mux.HandleFunc("GET /api/files/get", DBwrapper.FilesGet)
+       mux.HandleFunc("POST /api/files/createWithURL", DBwrapper.FilesCreateWithURL)
+       mux.HandleFunc("POST /api/files/createWithUpload", DBwrapper.FilesCreateWithUpload)
+       mux.HandleFunc("DELETE /api/files/delete/{id}", DBwrapper.FilesDeleteById)
+       mux.HandleFunc("PUT /api/files/rename/{id}", DBwrapper.FilesRenameById)
+       mux.HandleFunc("PUT /api/files/replace/{id}", DBwrapper.FilesReplaceById)
 
        listenPort := ":" + strconv.Itoa(*paramPort)
 
index 3f1278bebfe9815fd33ffbe7b09a4503dbd157a3..c79d1b8ae1effa2b84304fb53d39afab6f83ad4f 100644 (file)
@@ -6,58 +6,34 @@ import "net/http"
  *
  **/
 func (dbw *DBWrapper) FilesGet(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "GET" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
 
 /** TODO
  *
  **/
 func (dbw *DBWrapper) FilesCreateWithURL(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "GET" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
 
 /** TODO
  *
  **/
 func (dbw *DBWrapper) FilesCreateWithUpload(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "GET" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
 
 /** TODO
  *
  **/
 func (dbw *DBWrapper) FilesDeleteById(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "GET" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
 
 /** TODO
  *
  **/
 func (dbw *DBWrapper) FilesRenameById(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "GET" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
 
 /** TODO
  *
  **/
 func (dbw *DBWrapper) FilesReplaceById(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "GET" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
index 0f38929f46a6354d411b85d416bd2bccb54b79e7..64af91afd4613cd2594c170ff7327ec624a24106 100644 (file)
@@ -6,48 +6,28 @@ import "net/http"
  *
  **/
 func (dbw *DBWrapper) RoomsGet(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "GET" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
 
 /** TODO
  *
  **/
 func (dbw *DBWrapper) RoomsCreate(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "POST" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
 
 /** TODO
  *
  **/
 func (dbw *DBWrapper) RoomsAddByNameAndId(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "POST" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
 
 /** TODO
  *
  **/
 func (dbw *DBWrapper) RoomsRemoveByNameAndId(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "GET" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
 
 /** TODO
  *
  **/
 func (dbw *DBWrapper) RoomsDeleteByName(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "GET" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
index 98e70914f4b602e3cf7a13fde77b53b561e97805..58d794c04cd5cf60e55a6b296a3399f870da4044 100644 (file)
@@ -6,50 +6,24 @@ import "net/http"
  * Get all songs, and all their assosciated information from the db
  **/
 func (dbw *DBWrapper) SongsGet(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "GET" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
-
        // Here we should return an entire list of songs
-}
 
-/** TODO
- * 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) {
-       if r.Method != "POST" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
 
 /** TODO
  * 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) {
-       if r.Method != "POST" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
 
 /** TODO
  * Create a new song in the database (only in the main list don't add to anything)
  **/
 func (dbw *DBWrapper) SongsUpdateById(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "PUT" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
 
 /** TODO
  * Create a new song in the database (only in the main list don't add to anything)
  **/
 func (dbw *DBWrapper) SongsDeleteById(w http.ResponseWriter, r *http.Request) {
-       if r.Method != "DELETE" {
-               w.WriteHeader(http.StatusMethodNotAllowed)
-               return
-       }
 }
diff --git a/pkg/dbhandling/songsapi_test.go b/pkg/dbhandling/songsapi_test.go
new file mode 100644 (file)
index 0000000..524e3ca
--- /dev/null
@@ -0,0 +1,11 @@
+package dbhandling_test
+
+import "testing"
+
+func TestGetSongs(t *testing.T) {
+       // setup some fake requests
+
+       // subtests
+
+       // get answers to those requests
+}
index 2bde741f3ac496558636a4c29daaee0a9db4d4e9..6d41e51055df7052d42ffa14731933e606b054eb 100644 (file)
@@ -7,7 +7,7 @@ def main():
     with open("song-map.csv", "r") as mapcsv:
         all = mapcsv.readlines()
 
-    for i in range(0, 100):
+    for i in range(0, 10):
         line = all[i].split(",")
         r.hmset(f"song:{i}", {
             "artistName": line[0],