package routes import ( "cangui/whatsapp/backend/handlers" "cangui/whatsapp/backend/renders" "net/http" "github.com/gorilla/mux" "gorm.io/gorm" ) // Routes non protégées func RoutesPublic(r *mux.Router, db *gorm.DB) { // Fichiers statiques (CSS, JS, etc.) staticDir := "./frontend/assets/" r.PathPrefix("/frontend/assets/").Handler( http.StripPrefix("/frontend/assets/", http.FileServer(http.Dir(staticDir))), ) // Page de login r.HandleFunc("/login", renders.Login) r.HandleFunc("/api/whatsapp/webhook", handlers.WebhookVerifyHandler()).Methods("GET") r.HandleFunc("/api/whatsapp/webhook", handlers.WebhookReceiveHandler(db)).Methods("POST") // Endpoint d'API pour se logger r.HandleFunc("/api/login", handlers.LoginHandler(db)).Methods("POST") } // Routes protégées func RoutesProtected(r *mux.Router, db *gorm.DB) { r.HandleFunc("/jwt", renders.JwtTest) r.HandleFunc("/api/message/send", handlers.SendWhatsAppMessage(db)).Methods("POST") r.HandleFunc("/admin/user/{id}/conversations", renders.AdminConversationPage(db)) r.HandleFunc("/api/user/{id}/conversations", renders.AdminConversationRows(db)) r.HandleFunc("/admin/user/{id}/edit", renders.AdminUserEdit(db)).Methods("GET") r.HandleFunc("/admin/user", renders.AdminUserList(db)) r.HandleFunc("/api/user/delete/{id}", handlers.AdminUserDelete(db)).Methods("DELETE") r.HandleFunc("/api/user/update/{id}", renders.AdminUserUpdate(db)).Methods("POST") r.HandleFunc("/api/user/create", renders.CreateUserHandler(db)).Methods("POST") r.HandleFunc("/admin/user/create-form", renders.AdminUserCreateForm()).Methods("GET") r.HandleFunc("/dashboard", renders.Dashboard(db)) r.HandleFunc("/test/send", renders.TestMessagesPages) r.HandleFunc("/test/send2", renders.TestMessagesPages2) r.HandleFunc("/admin/user/{id}/conversation-thread", renders.AdminConversationThread(db)).Methods("GET") r.HandleFunc("/api/message/send2", handlers.HandleTemplateTest(db)).Methods("POST") r.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) { http.SetCookie(w, &http.Cookie{ Name: "token", Value: "", Path: "/", MaxAge: -1, HttpOnly: true, }) http.Redirect(w, r, "/login", http.StatusSeeOther) }) // // Ici on place les vues et API qui doivent être protégées // r.HandleFunc("/stream", StreamHandler) // r.HandleFunc("/dashboard", renders.Dashboard(bd)) // r.HandleFunc("/settings", renders.Settings) // r.HandleFunc("/library", renders.Library) // r.HandleFunc("/menuLibary", renders.Library) // r.HandleFunc("/godownloader/downloads", renders.GoDownload) // r.HandleFunc("/godownloader/linkcollectors", renders.GoDownloadLinkCollectors) // r.HandleFunc("/godownloader/settings", renders.GoDownloadSetting) // // API user // r.HandleFunc("/api/user/create", users.CreateUser(bd)).Methods("POST") // r.HandleFunc("/api/user/update/{id}", users.UpdateUser(bd)).Methods("PUT") // r.HandleFunc("/api/user/delete/{id}", users.DeleteUser(bd)).Methods("DELETE") // r.HandleFunc("/api/user/all/", users.ReadAllUser(bd)).Methods("GET") // r.HandleFunc("/api/user/{id}", users.FindUserById(bd)).Methods("GET") // // API download // r.HandleFunc("/api/pathDownload/create", download.CreateSavePath(bd)).Methods("POST") // r.HandleFunc("/api/pathDownload/update/{id}", download.UpdateSavePath(bd)).Methods("PUT") // r.HandleFunc("/api/pathDownload/delete/{id}", download.DeleteSavePath(bd)).Methods("DELETE") // r.HandleFunc("/api/pathDownload/all/", download.ReadAllSavePath(bd)).Methods("GET") // //API Check path // r.HandleFunc("/validate-path", download.PathValidationHandler) //API Scan folder }