Edit diags handlers

This commit is contained in:
Nicolas CARON 2024-12-04 18:21:29 +01:00
parent 42f33a17dd
commit 7665fc75a0
1 changed files with 1 additions and 7 deletions

View File

@ -91,14 +91,12 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
if r.Method == http.MethodPost {
// Récupérer le groupe courant
g := r.Context().Value(identification.GroupKey)
if g == nil {
http.Error(w, "Missing group information", http.StatusBadRequest)
return
}
// Parse le formulaire
diagForm, err := parseDiagsForm(r)
if err != nil {
log.Error().Err(err).Msg("Invalid form data")
@ -108,7 +106,6 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
log.Debug().Interface("diagForm", diagForm).Msg("Form data parsed")
// Préparation des données supplémentaires
data, err := structpb.NewStruct(map[string]any{
"beneficiary": beneficiaryID,
})
@ -118,7 +115,6 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
return
}
// Crée la requête gRPC pour créer le diagnostic
request := &diags.CreateDiagRequest{
Diag: &diags.Diag{
Name: diagForm.Name,
@ -130,7 +126,6 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
},
}
// Appelle le service gRPC
resp, err := h.services.GRPC.Diags.CreateDiag(context.TODO(), request)
if err != nil {
log.Error().Err(err).Msg("Failed to create diagnostic")
@ -138,8 +133,7 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
return
}
// Redirection après succès
http.Redirect(w, r, fmt.Sprintf("/app/benefeciaries/%s", resp.Diag), http.StatusFound)
http.Redirect(w, r, fmt.Sprintf("/app/diags/%s", resp.Diag.Id), http.StatusFound)
return
}