mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
REST create & Delete member.
This commit is contained in:
parent
71a84963bc
commit
a330a3cc76
@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"demodesk/neko/internal/utils"
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
type MemberCreatePayload struct {
|
||||
@ -13,7 +14,11 @@ type MemberCreatePayload struct {
|
||||
type MemberDataPayload struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Admin bool `json:"admin"`
|
||||
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user