diff --git a/src/app/eiffel/web.go b/src/app/eiffel/web.go index b0778cefcb60e6d9ddf3cdb6125b705ca2a30aa7..4ef801e7e41cd7549bf189e7d009599609cd4b2c 100644 --- a/src/app/eiffel/web.go +++ b/src/app/eiffel/web.go @@ -455,7 +455,7 @@ func eiffelElicitationPage(cfg Cfg, appCtx *hctx.AppCtx, webCtx *web.Ctx) http.H variantKey := web.URLParam(io.Request(), "variant") requirementID := io.Request().PostFormValue("requirementID") // POST-Wert abrufen editMode := io.Request().PostFormValue("edit") == "true" - + // Extract project ID from URL parameter or cookie projectID := io.Request().URL.Query().Get("project") if projectID == "" { @@ -464,7 +464,7 @@ func eiffelElicitationPage(cfg Cfg, appCtx *hctx.AppCtx, webCtx *web.Ctx) http.H } } log.Printf("Extracted project ID from URL: %s", projectID) - + // Save project ID in cookie for subsequent requests if projectID != "" { cookie := &http.Cookie{ @@ -476,7 +476,7 @@ func eiffelElicitationPage(cfg Cfg, appCtx *hctx.AppCtx, webCtx *web.Ctx) http.H } io.Response().Header().Add("Set-Cookie", cookie.String()) } - + // Prüfe, ob `templateID` leer ist, und rendere ein leeres Formular if templateID == "" { log.Println("templateID ist leer, rendere leeres Formular.") @@ -506,7 +506,7 @@ func eiffelElicitationPage(cfg Cfg, appCtx *hctx.AppCtx, webCtx *web.Ctx) http.H formData.NeglectOptional = cfg.NeglectOptional formData.CopyAfterParse = CopyAfterParseSetting(io.Request(), sessionStore, true) - + // Set project ID from URL parameter if available if projectID != "" { formData.ProjectID = projectID @@ -645,7 +645,7 @@ func elicitationTemplate(cfg Cfg, appCtx *hctx.AppCtx, webCtx *web.Ctx, defaultF return web.NewController(appCtx, webCtx, func(io web.IO) error { templateID := web.URLParam(io.Request(), "templateID") variant := web.URLParam(io.Request(), "variant") - + // Extract project ID from URL parameter, form data, or session projectID := io.Request().URL.Query().Get("project") if projectID == "" { @@ -658,7 +658,7 @@ func elicitationTemplate(cfg Cfg, appCtx *hctx.AppCtx, webCtx *web.Ctx, defaultF } } log.Printf("Template selection: extracted project ID: %s", projectID) - + // Save project ID in cookie for subsequent requests if projectID != "" { cookie := &http.Cookie{ @@ -688,7 +688,7 @@ func elicitationTemplate(cfg Cfg, appCtx *hctx.AppCtx, webCtx *web.Ctx, defaultF formData.NeglectOptional = cfg.NeglectOptional formData.CopyAfterParse = CopyAfterParseSetting(io.Request(), sessionStore, true) - + // Set project ID from URL parameter if available if projectID != "" { formData.ProjectID = projectID @@ -714,13 +714,13 @@ func getProjectShortcut(ctx context.Context, projectID string) (string, error) { var project struct { Shortcut string `bson:"shortcut"` } - + err := projectCollection.FindOne(ctx, bson.M{"project_id": projectID}).Decode(&project) if err != nil { log.Printf("Error fetching project shortcut for project_id '%s': %v", projectID, err) return "", err } - + return project.Shortcut, nil } @@ -759,12 +759,12 @@ func saveToMongoDB(formData *TemplateFormData) error { if formData.ProjectID != "" { // UUID für diese Anforderung generieren document["uuid"] = uuid.New() - + // Shortcut basierend auf Projekt-Kürzel generieren if projectShortcut, err := getProjectShortcut(ctx, formData.ProjectID); err == nil && projectShortcut != "" { // Anzahl der existierenden Anforderungen für dieses Projekt abrufen count, _ := mongoCollection.CountDocuments(ctx, bson.M{"project_id": formData.ProjectID}) - + // Shortcut im Format: [PROJECT_SHORTCUT]-REQ-[NUMMER] (z.B. "HM-REQ-001") document["shortcut"] = fmt.Sprintf("%s-REQ-%03d", projectShortcut, count+1) }