58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"butterfliu/internal/controller"
|
|
"butterfliu/internal/repository"
|
|
"butterfliu/internal/service"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
)
|
|
|
|
func main() {
|
|
err := InitDB("./butterfliu.db")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
r := chi.NewRouter()
|
|
r.Use(middleware.Logger)
|
|
|
|
libraryRepo := repository.NewLibraryRepository(GetDB())
|
|
songRepo := repository.NewSongRepository(GetDB())
|
|
mediaRepo := repository.NewMediaRepository(GetDB())
|
|
libraryService := service.NewLibraryService(libraryRepo)
|
|
songService := service.NewSongService(songRepo, mediaRepo)
|
|
libraryController := controller.NewLibraryController(libraryService)
|
|
songController := controller.NewSongController(songService)
|
|
|
|
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Write([]byte("Hello World!"))
|
|
})
|
|
|
|
r.Route("/api/libraries", func(r chi.Router) {
|
|
r.Get("/", libraryController.GetAll)
|
|
r.Post("/", libraryController.Create)
|
|
r.Put("/{id}/name", libraryController.UpdateName)
|
|
r.Put("/{id}/path", libraryController.UpdatePath)
|
|
r.Post("/{id}/scan", libraryController.Scan)
|
|
r.Get("/scan-status", libraryController.GetScanStatus)
|
|
r.Delete("/{id}", libraryController.Delete)
|
|
r.Get("/{id}/songs", libraryController.GetSongs)
|
|
})
|
|
|
|
r.Route("/api/songs", func(r chi.Router) {
|
|
r.Get("/", songController.GetAllWithDetails)
|
|
r.Get("/{id}/stream", songController.Stream)
|
|
})
|
|
|
|
r.Route("/api", func(r chi.Router) {
|
|
r.Get("/artists", libraryController.GetArtists)
|
|
r.Get("/albums", libraryController.GetAlbums)
|
|
})
|
|
|
|
http.ListenAndServe(":8102", r)
|
|
}
|