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