rest CRUD members minor update.

This commit is contained in:
Miroslav Šedivý 2020-11-27 20:00:14 +01:00
parent a90bf87e24
commit 59457b7658

View File

@ -13,6 +13,7 @@ type MemberCreatePayload struct {
type MemberDataPayload struct {
ID string `json:"id"`
Secret string `json:"secret,omitempty"`
Name string `json:"name"`
IsAdmin bool `json:"is_admin"`
//Enabled bool `json:"enabled"`
@ -27,26 +28,24 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
return
}
session, err := h.sessions.Create(types.MemberProfile{
Name: data.Name,
IsAdmin: data.IsAdmin,
})
id, err := utils.NewUID(32)
if err != nil {
utils.HttpInternalServer(w, err)
return
}
session := h.sessions.Create(id, types.MemberProfile{
Secret: data.Secret,
Name: data.Name,
IsAdmin: data.IsAdmin,
})
utils.HttpSuccess(w, MemberCreatePayload{
ID: session.ID(),
})
}
func (h *MembersHandler) membersRead(w http.ResponseWriter, r *http.Request) {
data := &MemberDataPayload{}
if !utils.HttpJsonRequest(w, r, data) {
return
}
member := GetMember(r)
utils.HttpSuccess(w, MemberDataPayload{