MemberDataPayload & membersList implemented.

This commit is contained in:
Miroslav Šedivý 2020-12-08 16:04:54 +01:00
parent 7fb40c0384
commit f1f26b5f25
2 changed files with 12 additions and 4 deletions

View File

@ -7,13 +7,13 @@ import (
"demodesk/neko/internal/types" "demodesk/neko/internal/types"
) )
type MemberCreatePayload struct { type MemberDataPayload struct {
ID string `json:"id"` ID string `json:"id"`
*types.MemberProfile *types.MemberProfile
} }
func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) { func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
data := &MemberCreatePayload{ data := &MemberDataPayload{
// default values // default values
MemberProfile: &types.MemberProfile{ MemberProfile: &types.MemberProfile{
IsAdmin: false, IsAdmin: false,
@ -58,7 +58,7 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
return return
} }
utils.HttpSuccess(w, MemberCreatePayload{ utils.HttpSuccess(w, MemberDataPayload{
ID: session.ID(), ID: session.ID(),
}) })
} }

View File

@ -7,6 +7,14 @@ import (
) )
func (h *MembersHandler) membersList(w http.ResponseWriter, r *http.Request) { func (h *MembersHandler) membersList(w http.ResponseWriter, r *http.Request) {
members := []MemberDataPayload{}
for _, session := range h.sessions.Members() {
profile := session.GetProfile()
members = append(members, MemberDataPayload{
ID: session.ID(),
MemberProfile: &profile,
})
}
utils.HttpSuccess(w) utils.HttpSuccess(w, members)
} }