REST create & Delete member.

This commit is contained in:
Miroslav Šedivý 2020-11-25 22:39:54 +01:00
parent 71a84963bc
commit a330a3cc76

View File

@ -4,16 +4,21 @@ import (
"net/http"
"demodesk/neko/internal/utils"
"demodesk/neko/internal/types"
)
type MemberCreatePayload struct {
ID string `json:"id"`
ID string `json:"id"`
}
type MemberDataPayload struct {
ID string `json:"id"`
Name string `json:"name"`
Admin bool `json:"admin"`
ID string `json:"id"`
Name string `json:"name"`
IsAdmin bool `json:"is_admin"`
//Enabled bool `json:"enabled"`
//CanControl bool `json:"can_control"`
//CanWatch bool `json:"can_watch"`
//ClipboardAccess bool `json:"clipboard_access"`
}
func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
@ -22,8 +27,17 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
return
}
session, err := h.sessions.Create(types.MemberProfile{
Name: data.Name,
IsAdmin: data.IsAdmin,
})
if err != nil {
utils.HttpInternalServer(w, err)
return
}
utils.HttpSuccess(w, MemberCreatePayload{
ID: "some_id",
ID: session.ID(),
})
}
@ -38,7 +52,7 @@ func (h *MembersHandler) membersRead(w http.ResponseWriter, r *http.Request) {
utils.HttpSuccess(w, MemberDataPayload{
ID: member.ID(),
Name: member.Name(),
Admin: member.Admin(),
IsAdmin: member.Admin(),
})
}
@ -53,16 +67,17 @@ func (h *MembersHandler) membersUpdate(w http.ResponseWriter, r *http.Request) {
utils.HttpSuccess(w, MemberDataPayload{
ID: member.ID(),
Name: member.Name(),
Admin: member.Admin(),
IsAdmin: member.Admin(),
})
}
func (h *MembersHandler) membersDelete(w http.ResponseWriter, r *http.Request) {
member := GetMember(r)
utils.HttpSuccess(w, MemberDataPayload{
ID: member.ID(),
Name: member.Name(),
Admin: member.Admin(),
})
if err := h.sessions.Delete(member.ID()); err != nil {
utils.HttpInternalServer(w, err)
return
}
utils.HttpSuccess(w)
}