add member page with organisations

This commit is contained in:
soukainna 2023-02-22 11:02:37 +01:00
parent e559359ff0
commit fa065f2a43
1 changed files with 87 additions and 2 deletions

View File

@ -6,9 +6,12 @@ import (
"fmt"
"net/http"
"strings"
"time"
formvalidators "git.coopgo.io/coopgo-apps/parcoursmob/utils/form-validators"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
"github.com/google/uuid"
"google.golang.org/protobuf/types/known/structpb"
)
@ -36,8 +39,34 @@ func (h *ApplicationHandler) MemberDisplay(w http.ResponseWriter, r *http.Reques
w.WriteHeader(http.StatusInternalServerError)
return
}
//////////////////////////////////add organisations/////////////////////////////////////////////////
h.Renderer.MemberDisplay(w, r, resp.Account.ToStorageType())
var allIds []string
for _, v := range resp.Account.ToStorageType().Data["groups"].([]any) {
s := fmt.Sprintf("%v", v)
if !(strings.Contains(s, "admin")) {
allIds = append(allIds, s)
}
}
reques := &groupsmanagement.GetGroupsBatchRequest{
Groupids: allIds,
}
res, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), reques)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
var groupsName []string
for _, group := range res.Groups {
g := fmt.Sprintf("%v", group.ToStorageType().Data["name"])
groupsName = append(groupsName, g)
}
h.Renderer.MemberDisplay(w, r, resp.Account.ToStorageType(), groupsName)
}
func (h *ApplicationHandler) MemberUpdate(w http.ResponseWriter, r *http.Request) {
@ -76,7 +105,7 @@ func (h *ApplicationHandler) MemberUpdate(w http.ResponseWriter, r *http.Request
return
}
http.Redirect(w, r, fmt.Sprintf("/app/profile/%s", resp.Account.Id), http.StatusFound)
http.Redirect(w, r, fmt.Sprintf("/app/members/%s", resp.Account.Id), http.StatusFound)
return
}
@ -126,3 +155,59 @@ func parseUserForm(r *http.Request) (map[string]any, error) {
return dataMap, nil
}
func (h *ApplicationHandler) MembersList(w http.ResponseWriter, r *http.Request) {
accounts, err := h.services.GetAccounts()
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
var groupsName []string
for _, v := range accounts {
adminid := v.ID
request := &mobilityaccounts.GetAccountRequest{
Id: adminid,
}
resp, err := h.services.GRPC.MobilityAccounts.GetAccount(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
//////////////////////////////////add organisations/////////////////////////////////////////////////
var allIds []string
for _, v := range resp.Account.ToStorageType().Data["groups"].([]any) {
s := fmt.Sprintf("%v", v)
if !(strings.Contains(s, "admin")) {
allIds = append(allIds, s)
}
}
reques := &groupsmanagement.GetGroupsBatchRequest{
Groupids: allIds,
}
res, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), reques)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
g := ""
for _, group := range res.Groups {
g += fmt.Sprintf("%v", group.ToStorageType().Data["name"]) + " "
}
groupsName = append(groupsName, g)
}
cacheid := uuid.NewString()
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
h.Renderer.MembersList(w, r, accounts, cacheid, groupsName)
}