From 973c48295ba3c2b5802e9767ec419f99280bc156 Mon Sep 17 00:00:00 2001 From: cangui Date: Sun, 11 May 2025 18:27:41 +0200 Subject: [PATCH] documentations --- backend/handlers/main.go | 55 ++++++++++++++++++++++---------------- backend/renders/renders.go | 6 ++--- backend/routes/routes.go | 29 -------------------- 3 files changed, 35 insertions(+), 55 deletions(-) diff --git a/backend/handlers/main.go b/backend/handlers/main.go index d2cd882..2f83c0c 100644 --- a/backend/handlers/main.go +++ b/backend/handlers/main.go @@ -16,8 +16,7 @@ import ( "golang.org/x/crypto/bcrypt" "gorm.io/gorm" ) - -// Simuler un SSO + Redirection selon rôle +// login fonction func LoginHandler(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") @@ -93,6 +92,7 @@ func SSOLoginHandler(db *gorm.DB) http.HandlerFunc { http.Redirect(w, r, "/dashboard", http.StatusSeeOther) } } +// sso connection func SSOLoginPostHandler(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var body struct { @@ -203,6 +203,7 @@ func WebhookHandler(db *gorm.DB) http.HandlerFunc { w.WriteHeader(http.StatusOK) } } +// fonction pour extraire les message func extractMessageContent(m map[string]interface{}) string { t := m["type"].(string) switch t { @@ -361,7 +362,11 @@ func WebhookReceiveHandler(db *gorm.DB) http.HandlerFunc { w.WriteHeader(http.StatusOK) } } - +/* +* +* Block pour le crud user/ client +* +*/ func CreateUser(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -444,6 +449,29 @@ func DeleteUser(db *gorm.DB) http.HandlerFunc { w.WriteHeader(http.StatusNoContent) } } +func AdminUserDelete(db *gorm.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + id := mux.Vars(r)["id"] + + var user models.User + if err := db.Unscoped().First(&user, id).Error; err != nil { + http.Error(w, "Utilisateur introuvable", http.StatusNotFound) + return + } + + // Suppression définitive + if err := db.Unscoped().Delete(&user).Error; err != nil { + http.Error(w, "Erreur suppression", http.StatusInternalServerError) + return + } + + w.WriteHeader(http.StatusOK) + w.Write([]byte("")) + } +} + + +// function pour l envoie des messages par template. func HandleTemplateTest(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { val := r.Context().Value("ssoid") @@ -522,6 +550,7 @@ func HandleTemplateTest(db *gorm.DB) http.HandlerFunc { json.NewEncoder(w).Encode(respBody) } } +// function pour envoie de message sans template. ne peux fonctionner que si le receveur a repondu func SendWhatsAppMessage(db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { val := r.Context().Value("ssoid") @@ -597,26 +626,6 @@ func SendWhatsAppMessage(db *gorm.DB) http.HandlerFunc { w.Write(respBody) } } -func AdminUserDelete(db *gorm.DB) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - id := mux.Vars(r)["id"] - - var user models.User - if err := db.Unscoped().First(&user, id).Error; err != nil { - http.Error(w, "Utilisateur introuvable", http.StatusNotFound) - return - } - - // Suppression définitive - if err := db.Unscoped().Delete(&user).Error; err != nil { - http.Error(w, "Erreur suppression", http.StatusInternalServerError) - return - } - - w.WriteHeader(http.StatusOK) - w.Write([]byte("")) - } -} diff --git a/backend/renders/renders.go b/backend/renders/renders.go index 5b2ec81..ae35168 100644 --- a/backend/renders/renders.go +++ b/backend/renders/renders.go @@ -11,7 +11,7 @@ import ( "golang.org/x/crypto/bcrypt" "gorm.io/gorm" ) - +// les renders permette d afficher les pages html. func Login(w http.ResponseWriter, r *http.Request){ renderTemplate(w,"login",nil) @@ -460,7 +460,7 @@ func Dashboard(db *gorm.DB) http.HandlerFunc { } } - +// pour un rendu complet de la page func renderTemplate(w http.ResponseWriter, templ string, data map[string]interface{}) { t, err := template.ParseFiles( "./frontend/templates/head.pages.tmpl", @@ -480,7 +480,7 @@ func renderTemplate(w http.ResponseWriter, templ string, data map[string]interfa http.Error(w, err.Error(), http.StatusInternalServerError) } } - +// pour un rendu de composent. func renderPartial(w http.ResponseWriter, templ string, data map[string]interface{}) { t, err := template.ParseFiles("./frontend/templates/" + templ + ".pages.tmpl") if err != nil { diff --git a/backend/routes/routes.go b/backend/routes/routes.go index 227b7dd..56e5c2f 100644 --- a/backend/routes/routes.go +++ b/backend/routes/routes.go @@ -88,34 +88,5 @@ func RoutesPublic(r *mux.Router, db *gorm.DB) { }) r.HandleFunc("/apidoc", renders.ApiDocPage(db)) - - - // // 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 - } \ No newline at end of file