From ce49d975c047a3db2146efb01890321f6ca2d8a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 21 Nov 2020 23:42:34 +0100 Subject: [PATCH] member in plural form. --- internal/api/member/list.go | 12 ----------- internal/api/{member => members}/crud.go | 10 +++++----- internal/api/{member => members}/handler.go | 22 ++++++++++----------- internal/api/members/list.go | 12 +++++++++++ internal/api/router.go | 6 +++--- 5 files changed, 31 insertions(+), 31 deletions(-) delete mode 100644 internal/api/member/list.go rename internal/api/{member => members}/crud.go (53%) rename internal/api/{member => members}/handler.go (70%) create mode 100644 internal/api/members/list.go diff --git a/internal/api/member/list.go b/internal/api/member/list.go deleted file mode 100644 index e9485e6b..00000000 --- a/internal/api/member/list.go +++ /dev/null @@ -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) -} diff --git a/internal/api/member/crud.go b/internal/api/members/crud.go similarity index 53% rename from internal/api/member/crud.go rename to internal/api/members/crud.go index 7ab90178..85f91c7b 100644 --- a/internal/api/member/crud.go +++ b/internal/api/members/crud.go @@ -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() + ".") diff --git a/internal/api/member/handler.go b/internal/api/members/handler.go similarity index 70% rename from internal/api/member/handler.go rename to internal/api/members/handler.go index c50cc26e..13444838 100644 --- a/internal/api/member/handler.go +++ b/internal/api/members/handler.go @@ -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) diff --git a/internal/api/members/list.go b/internal/api/members/list.go new file mode 100644 index 00000000..ec8a9540 --- /dev/null +++ b/internal/api/members/list.go @@ -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) +} diff --git a/internal/api/router.go b/internal/api/router.go index f1cdf64a..e828084c 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -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)