Skip to content
Snippets Groups Projects
Commit b7d92d36 authored by Alexander Kohler's avatar Alexander Kohler
Browse files

Web-Controller um Kürzel-Unterstützung erweitert

- max8 Validator für Kürzel-Längenbegrenzung hinzugefügt
- Datum-Parsing für Formulare verbessert
- Kürzel-Feld in Create- und Update-Controllern integriert
parent 690294d2
1 merge request!4merge dev to main
...@@ -41,6 +41,16 @@ type ProjectDetailData struct { ...@@ -41,6 +41,16 @@ type ProjectDetailData struct {
func RegisterController(appCtx *hctx.AppCtx, webCtx *web.Ctx, mongoManager *project.MongoManager) { func RegisterController(appCtx *hctx.AppCtx, webCtx *web.Ctx, mongoManager *project.MongoManager) {
log.Println("INFO: Registering project controllers...") log.Println("INFO: Registering project controllers...")
// Add max8 validator for string length validation (needed for project shortcut field)
appCtx.Validator.AddFunc("max8", func(value any) error {
if str, ok := value.(string); ok {
if len(str) > 8 {
return errors.New("harmony.error.validation.max")
}
}
return nil
})
// Initialize the data access layer (repository) and business logic layer (service) // Initialize the data access layer (repository) and business logic layer (service)
// Repository handles MongoDB operations, Service handles business rules // Repository handles MongoDB operations, Service handles business rules
projectRepo := project.NewMongoProjectRepository(mongoManager.GetDatabase()) projectRepo := project.NewMongoProjectRepository(mongoManager.GetDatabase())
...@@ -166,6 +176,21 @@ func projectCreateController(appCtx *hctx.AppCtx, webCtx *web.Ctx, service *proj ...@@ -166,6 +176,21 @@ func projectCreateController(appCtx *hctx.AppCtx, webCtx *web.Ctx, service *proj
return io.Error(web.ErrInternal, err) return io.Error(web.ErrInternal, err)
} }
// Manual parsing for date fields since web.ReadForm doesn't support time.Time
request := io.Request()
if err := request.ParseForm(); err == nil {
if startDateStr := request.FormValue("StartDate"); startDateStr != "" {
if startDate, parseErr := time.Parse("2006-01-02", startDateStr); parseErr == nil {
toCreate.StartDate = startDate
}
}
if endDateStr := request.FormValue("EndDate"); endDateStr != "" {
if endDate, parseErr := time.Parse("2006-01-02", endDateStr); parseErr == nil {
toCreate.EndDate = endDate
}
}
}
// If there are validation errors, redisplay the form with error messages // If there are validation errors, redisplay the form with error messages
if validationErrs != nil { if validationErrs != nil {
log.Printf("WARN: Project creation validation failed: %d errors", len(validationErrs)) log.Printf("WARN: Project creation validation failed: %d errors", len(validationErrs))
...@@ -325,6 +350,21 @@ func projectUpdateController(appCtx *hctx.AppCtx, webCtx *web.Ctx, service *proj ...@@ -325,6 +350,21 @@ func projectUpdateController(appCtx *hctx.AppCtx, webCtx *web.Ctx, service *proj
return io.InlineError(web.ErrInternal, err) return io.InlineError(web.ErrInternal, err)
} }
// Manual parsing for date fields since web.ReadForm doesn't support time.Time
request := io.Request()
if err := request.ParseForm(); err == nil {
if startDateStr := request.FormValue("StartDate"); startDateStr != "" {
if startDate, parseErr := time.Parse("2006-01-02", startDateStr); parseErr == nil {
toUpdate.StartDate = startDate
}
}
if endDateStr := request.FormValue("EndDate"); endDateStr != "" {
if endDate, parseErr := time.Parse("2006-01-02", endDateStr); parseErr == nil {
toUpdate.EndDate = endDate
}
}
}
// If validation fails, redisplay the form with error messages // If validation fails, redisplay the form with error messages
if validationErrs != nil { if validationErrs != nil {
log.Printf("WARN: Project update validation failed: %d errors", len(validationErrs)) log.Printf("WARN: Project update validation failed: %d errors", len(validationErrs))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment