member in plural form.

This commit is contained in:
Miroslav Šedivý 2020-11-21 23:42:34 +01:00
parent d39d922f85
commit ce49d975c0
5 changed files with 31 additions and 31 deletions

View File

@ -1,12 +0,0 @@
package member
import (
"net/http"
"demodesk/neko/internal/utils"
)
func (h *MemberHandler) memberList(w http.ResponseWriter, r *http.Request) {
utils.HttpSuccess(w)
}

View File

@ -1,4 +1,4 @@
package member
package members
import (
"net/http"
@ -6,24 +6,24 @@ import (
"demodesk/neko/internal/utils"
)
func (h *MemberHandler) memberCreate(w http.ResponseWriter, r *http.Request) {
func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
utils.HttpSuccess(w)
}
func (h *MemberHandler) memberRead(w http.ResponseWriter, r *http.Request) {
func (h *MembersHandler) membersRead(w http.ResponseWriter, r *http.Request) {
member := GetMember(r)
utils.HttpSuccess(w, "Your name is " + member.Name() + ".")
}
func (h *MemberHandler) memberUpdate(w http.ResponseWriter, r *http.Request) {
func (h *MembersHandler) membersUpdate(w http.ResponseWriter, r *http.Request) {
member := GetMember(r)
utils.HttpSuccess(w, "Your name is " + member.Name() + ".")
}
func (h *MemberHandler) memberDelete(w http.ResponseWriter, r *http.Request) {
func (h *MembersHandler) membersDelete(w http.ResponseWriter, r *http.Request) {
member := GetMember(r)
utils.HttpSuccess(w, "Your name is " + member.Name() + ".")

View File

@ -1,4 +1,4 @@
package member
package members
import (
"context"
@ -17,29 +17,29 @@ const (
keyMemberCtx key = iota
)
type MemberHandler struct {
type MembersHandler struct {
sessions types.SessionManager
}
func New(
sessions types.SessionManager,
) *MemberHandler {
) *MembersHandler {
// Init
return &MemberHandler{
return &MembersHandler{
sessions: sessions,
}
}
func (h *MemberHandler) Route(r chi.Router) {
func (h *MembersHandler) Route(r chi.Router) {
r.With(auth.AdminsOnly).Group(func(r chi.Router) {
r.Get("/", h.memberList)
r.Get("/", h.membersList)
r.Post("/", h.memberCreate)
r.Get("/{memberId}/", h.memberRead)
r.Post("/{memberId}/", h.memberUpdate)
r.Delete("/{memberId}/", h.memberDelete)
r.Post("/", h.membersCreate)
r.Get("/{memberId}/", h.membersRead)
r.Post("/{memberId}/", h.membersUpdate)
r.Delete("/{memberId}/", h.membersDelete)
})
}
@ -53,7 +53,7 @@ func GetMember(r *http.Request) types.Session {
return r.Context().Value(keyMemberCtx).(types.Session)
}
func (h *MemberHandler) ExtractMember(next http.Handler) http.Handler {
func (h *MembersHandler) ExtractMember(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
memberId := chi.URLParam(r, "memberId")
session, ok := h.sessions.Get(memberId)

View File

@ -0,0 +1,12 @@
package members
import (
"net/http"
"demodesk/neko/internal/utils"
)
func (h *MembersHandler) membersList(w http.ResponseWriter, r *http.Request) {
utils.HttpSuccess(w)
}

View File

@ -5,7 +5,7 @@ import (
"github.com/go-chi/chi"
"demodesk/neko/internal/api/member"
"demodesk/neko/internal/api/members"
"demodesk/neko/internal/api/room"
"demodesk/neko/internal/http/auth"
"demodesk/neko/internal/types"
@ -36,8 +36,8 @@ func New(
func (api *ApiManagerCtx) Route(r chi.Router) {
r.Use(api.Authenticate)
memberHandler := member.New(api.sessions)
r.Route("/member", memberHandler.Route)
membersHandler := members.New(api.sessions)
r.Route("/members", membersHandler.Route)
roomHandler := room.New(api.sessions, api.desktop, api.capture)
r.Route("/room", roomHandler.Route)