CRUD add payloads.

This commit is contained in:
Miroslav Šedivý 2020-11-22 00:06:55 +01:00
parent 43781cdf52
commit d49542013b

View File

@ -6,25 +6,63 @@ import (
"demodesk/neko/internal/utils" "demodesk/neko/internal/utils"
) )
func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) { type MemberCreatePayload struct {
ID string `json:"id"`
}
utils.HttpSuccess(w) type MemberDataPayload struct {
ID string `json:"id"`
Name string `json:"name"`
Admin bool `json:"admin"`
}
func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
data := &MemberDataPayload{}
if !utils.HttpJsonRequest(w, r, data) {
return
}
utils.HttpSuccess(w, MemberCreatePayload{
ID: "some_id",
})
} }
func (h *MembersHandler) membersRead(w http.ResponseWriter, r *http.Request) { func (h *MembersHandler) membersRead(w http.ResponseWriter, r *http.Request) {
data := &MemberDataPayload{}
if !utils.HttpJsonRequest(w, r, data) {
return
}
member := GetMember(r) member := GetMember(r)
utils.HttpSuccess(w, "Your name is " + member.Name() + ".") utils.HttpSuccess(w, MemberDataPayload{
ID: member.ID(),
Name: member.Name(),
Admin: member.Admin(),
})
} }
func (h *MembersHandler) membersUpdate(w http.ResponseWriter, r *http.Request) { func (h *MembersHandler) membersUpdate(w http.ResponseWriter, r *http.Request) {
data := &MemberDataPayload{}
if !utils.HttpJsonRequest(w, r, data) {
return
}
member := GetMember(r) member := GetMember(r)
utils.HttpSuccess(w, "Your name is " + member.Name() + ".") utils.HttpSuccess(w, MemberDataPayload{
ID: member.ID(),
Name: member.Name(),
Admin: member.Admin(),
})
} }
func (h *MembersHandler) membersDelete(w http.ResponseWriter, r *http.Request) { func (h *MembersHandler) membersDelete(w http.ResponseWriter, r *http.Request) {
member := GetMember(r) member := GetMember(r)
utils.HttpSuccess(w, "Your name is " + member.Name() + ".") utils.HttpSuccess(w, MemberDataPayload{
ID: member.ID(),
Name: member.Name(),
Admin: member.Admin(),
})
} }