Add check in Diags home if its the same groupID
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 1m49s
Some checks failed
Build and Push Docker Image / build_and_push (push) Failing after 1m49s
This commit is contained in:
@@ -21,8 +21,8 @@ import (
|
||||
diags "git.coopgo.io/coopgo-platform/diags/grpcapi"
|
||||
diagsstorage "git.coopgo.io/coopgo-platform/diags/storage"
|
||||
|
||||
// groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
// "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
// mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
// "github.com/google/uuid"
|
||||
"github.com/google/uuid"
|
||||
@@ -40,9 +40,12 @@ type DiagsForm struct {
|
||||
Data map[string]any `json:"data"`
|
||||
Deleted bool `json:"deleted"`
|
||||
Diagdate *time.Time `json:"diagdate"`
|
||||
Owners []string `json:"owners"`
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) DiagsHome(w http.ResponseWriter, r *http.Request) {
|
||||
groupID := r.Context().Value(identification.GroupKey).(storage.Group).ID
|
||||
|
||||
resp, err := h.services.GRPC.Diags.GetDiags(context.TODO(), &diags.GetDiagsRequest{
|
||||
Namespaces: []string{"parcoursmob_beneficiaries", "parcoursmob_diagnostiques", "parcoursmob_vehicles", "parcoursmob_bookings"},
|
||||
})
|
||||
@@ -55,11 +58,35 @@ func (h *ApplicationHandler) DiagsHome(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
responses := []diagsstorage.Diag{}
|
||||
|
||||
groupids := []string{}
|
||||
for _, e := range resp.Diags {
|
||||
groupids = append(groupids, e.Owners...)
|
||||
responses = append(responses, e.ToStorageType())
|
||||
}
|
||||
|
||||
h.Renderer.DiagsHome(w, r, responses)
|
||||
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: groupids,
|
||||
})
|
||||
groups := map[string]any{}
|
||||
|
||||
if err == nil {
|
||||
for _, g := range groupsresp.Groups {
|
||||
groups[g.Id] = g.ToStorageType()
|
||||
}
|
||||
}
|
||||
|
||||
filteredDiags := []diagsstorage.Diag{}
|
||||
for _, diag := range responses {
|
||||
for _, owner := range diag.Owners {
|
||||
if string(owner) == groupID {
|
||||
filteredDiags = append(filteredDiags, diag)
|
||||
log.Debug().Msgf("Diag %s added to filtered list", diag.ID)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
h.Renderer.DiagsHome(w, r, filteredDiags, groups)
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) DiagsHistory(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -102,6 +129,8 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
|
||||
return
|
||||
}
|
||||
|
||||
group := g.(storage.Group)
|
||||
|
||||
diagForm, err := parseDiagsForm(r)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Invalid form data")
|
||||
@@ -109,8 +138,6 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
|
||||
return
|
||||
}
|
||||
|
||||
log.Debug().Interface("diagForm", diagForm).Msg("Form data parsed")
|
||||
|
||||
data, err := structpb.NewStruct(map[string]any{
|
||||
"beneficiary": beneficiaryID,
|
||||
})
|
||||
@@ -129,6 +156,7 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
|
||||
Data: data,
|
||||
Deleted: diagForm.Deleted,
|
||||
Diagdate: timestamppb.New(time.Now()),
|
||||
Owners: []string{group.ID},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -173,7 +201,7 @@ func (h *ApplicationHandler) BeneficiariesCreateDiag(w http.ResponseWriter, r *h
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/diags/%s", resp.Diag.Id), http.StatusFound)
|
||||
return
|
||||
}
|
||||
@@ -217,6 +245,8 @@ func (h *ApplicationHandler) VehiclesCreateDiag(w http.ResponseWriter, r *http.R
|
||||
return
|
||||
}
|
||||
|
||||
group := g.(storage.Group)
|
||||
|
||||
request := &diags.CreateDiagRequest{
|
||||
Diag: &diags.Diag{
|
||||
Name: diagForm.Name,
|
||||
@@ -226,6 +256,7 @@ func (h *ApplicationHandler) VehiclesCreateDiag(w http.ResponseWriter, r *http.R
|
||||
Data: data,
|
||||
Deleted: diagForm.Deleted,
|
||||
Diagdate: timestamppb.New(time.Now()),
|
||||
Owners: []string{group.ID},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -279,6 +310,8 @@ func (h *ApplicationHandler) BookingsCreateDiag(w http.ResponseWriter, r *http.R
|
||||
return
|
||||
}
|
||||
|
||||
group := g.(storage.Group)
|
||||
|
||||
request := &diags.CreateDiagRequest{
|
||||
Diag: &diags.Diag{
|
||||
Name: diagForm.Name,
|
||||
@@ -288,6 +321,7 @@ func (h *ApplicationHandler) BookingsCreateDiag(w http.ResponseWriter, r *http.R
|
||||
Data: data,
|
||||
Deleted: diagForm.Deleted,
|
||||
Diagdate: timestamppb.New(time.Now()),
|
||||
Owners: []string{group.ID},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -341,6 +375,8 @@ func (h *ApplicationHandler) VehicleBookingsCreateDiag(w http.ResponseWriter, r
|
||||
return
|
||||
}
|
||||
|
||||
group := g.(storage.Group)
|
||||
|
||||
request := &diags.CreateDiagRequest{
|
||||
Diag: &diags.Diag{
|
||||
Name: diagForm.Name,
|
||||
@@ -350,6 +386,7 @@ func (h *ApplicationHandler) VehicleBookingsCreateDiag(w http.ResponseWriter, r
|
||||
Data: data,
|
||||
Deleted: diagForm.Deleted,
|
||||
Diagdate: timestamppb.New(time.Now()),
|
||||
Owners: []string{group.ID},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -447,6 +484,8 @@ func (h *ApplicationHandler) DiagUpdate(w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
group := g.(storage.Group)
|
||||
|
||||
diagForm, err := parseDiagsForm(r)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("")
|
||||
@@ -465,6 +504,7 @@ func (h *ApplicationHandler) DiagUpdate(w http.ResponseWriter, r *http.Request)
|
||||
UiSchema: diagForm.UiSchema,
|
||||
Data: data,
|
||||
Diagdate: timestamppb.New(time.Now()),
|
||||
Owners: []string{group.ID},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -599,4 +639,4 @@ func (h *ApplicationHandler) DiagsDocumentDownload(w http.ResponseWriter, r *htt
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/diags/%s", diagID), http.StatusFound)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user