neko/internal/api/members/crud.go

69 lines
1.3 KiB
Go
Raw Normal View History

2020-11-22 11:42:34 +13:00
package members
2020-11-22 11:39:24 +13:00
import (
"net/http"
"demodesk/neko/internal/utils"
)
2020-11-22 12:06:55 +13:00
type MemberCreatePayload struct {
ID string `json:"id"`
}
type MemberDataPayload struct {
ID string `json:"id"`
Name string `json:"name"`
Admin bool `json:"admin"`
}
2020-11-22 11:42:34 +13:00
func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
2020-11-22 12:06:55 +13:00
data := &MemberDataPayload{}
if !utils.HttpJsonRequest(w, r, data) {
return
}
2020-11-22 11:39:24 +13:00
2020-11-22 12:06:55 +13:00
utils.HttpSuccess(w, MemberCreatePayload{
ID: "some_id",
})
2020-11-22 11:39:24 +13:00
}
2020-11-22 11:42:34 +13:00
func (h *MembersHandler) membersRead(w http.ResponseWriter, r *http.Request) {
2020-11-22 12:06:55 +13:00
data := &MemberDataPayload{}
if !utils.HttpJsonRequest(w, r, data) {
return
}
2020-11-22 11:39:24 +13:00
member := GetMember(r)
2020-11-22 12:06:55 +13:00
utils.HttpSuccess(w, MemberDataPayload{
ID: member.ID(),
Name: member.Name(),
Admin: member.Admin(),
})
2020-11-22 11:39:24 +13:00
}
2020-11-22 11:42:34 +13:00
func (h *MembersHandler) membersUpdate(w http.ResponseWriter, r *http.Request) {
2020-11-22 12:06:55 +13:00
data := &MemberDataPayload{}
if !utils.HttpJsonRequest(w, r, data) {
return
}
2020-11-22 11:39:24 +13:00
member := GetMember(r)
2020-11-22 12:06:55 +13:00
utils.HttpSuccess(w, MemberDataPayload{
ID: member.ID(),
Name: member.Name(),
Admin: member.Admin(),
})
2020-11-22 11:39:24 +13:00
}
2020-11-22 11:42:34 +13:00
func (h *MembersHandler) membersDelete(w http.ResponseWriter, r *http.Request) {
2020-11-22 11:39:24 +13:00
member := GetMember(r)
2020-11-22 12:06:55 +13:00
utils.HttpSuccess(w, MemberDataPayload{
ID: member.ID(),
Name: member.Name(),
Admin: member.Admin(),
})
2020-11-22 11:39:24 +13:00
}