forked from mtusi2026/mtusi2026lab4
chore(solution): port lab3 sources
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"messenger/internal/handler"
|
||||
)
|
||||
|
||||
func New(h *handler.Handler, instanceID string) http.Handler {
|
||||
r := chi.NewRouter()
|
||||
r.Use(handler.InstanceID(instanceID), handler.RequestID, h.AccessLog, h.Recoverer)
|
||||
|
||||
r.NotFound(h.NotFound)
|
||||
r.MethodNotAllowed(h.MethodNotAllowed)
|
||||
|
||||
r.Get("/health/live", h.Live)
|
||||
r.Get("/health/ready", h.Ready)
|
||||
|
||||
r.Route("/api/v1", func(r chi.Router) {
|
||||
r.Post("/users", h.RegisterUser)
|
||||
r.Post("/auth/sessions", h.CreateSession)
|
||||
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(h.Authenticate)
|
||||
r.Delete("/auth/sessions/current", h.DeleteSession)
|
||||
r.Get("/users/me", h.CurrentUser)
|
||||
r.Post("/chats", h.CreateChat)
|
||||
r.Get("/chats", h.ListChats)
|
||||
r.Get("/chats/{chat_id}", h.GetChat)
|
||||
r.Post("/chats/{chat_id}/messages", h.SendMessage)
|
||||
r.Get("/chats/{chat_id}/messages", h.ListMessages)
|
||||
})
|
||||
})
|
||||
return r
|
||||
}
|
||||
Reference in New Issue
Block a user