lab2: postgres, sessions, redis, persistence, stale read
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/charawein/mtusi2026lab2/internal/service"
|
||||
"github.com/charawein/mtusi2026lab2/internal/transport/http/middleware"
|
||||
)
|
||||
|
||||
func NewRouter(
|
||||
users *service.UserService,
|
||||
chats *service.ChatService,
|
||||
messages *service.MessageService,
|
||||
auth *service.AuthService,
|
||||
) http.Handler {
|
||||
userH := NewUserHandler(users)
|
||||
chatH := NewChatHandler(chats)
|
||||
msgH := NewMessageHandler(messages)
|
||||
authH := NewAuthHandler(auth)
|
||||
healthH := NewHealthHandler()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.HandleFunc("GET /health/live", healthH.Live)
|
||||
mux.HandleFunc("GET /health/ready", healthH.Ready)
|
||||
mux.HandleFunc("POST /api/v1/users", userH.CreateUser)
|
||||
mux.HandleFunc("POST /api/v1/auth/sessions", authH.CreateSession)
|
||||
|
||||
// Debug endpoints для демонстрации трека 5.1 (не входят в публичный контракт).
|
||||
mux.HandleFunc("POST /debug/cache/on", func(w http.ResponseWriter, r *http.Request) {
|
||||
messages.SetInvalidate(true)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
mux.HandleFunc("POST /debug/cache/off", func(w http.ResponseWriter, r *http.Request) {
|
||||
messages.SetInvalidate(false)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
})
|
||||
|
||||
authMW := middleware.Auth(auth)
|
||||
|
||||
mux.Handle("DELETE /api/v1/auth/sessions/current", authMW(http.HandlerFunc(authH.RevokeSession)))
|
||||
mux.Handle("GET /api/v1/users/me", authMW(http.HandlerFunc(userH.CurrentUser)))
|
||||
mux.Handle("POST /api/v1/chats", authMW(http.HandlerFunc(chatH.CreateChat)))
|
||||
mux.Handle("GET /api/v1/chats", authMW(http.HandlerFunc(chatH.ListChats)))
|
||||
mux.Handle("GET /api/v1/chats/{chat_id}", authMW(http.HandlerFunc(chatH.GetChat)))
|
||||
mux.Handle("POST /api/v1/chats/{chat_id}/messages", authMW(http.HandlerFunc(msgH.SendMessage)))
|
||||
mux.Handle("GET /api/v1/chats/{chat_id}/messages", authMW(http.HandlerFunc(msgH.ListMessages)))
|
||||
|
||||
handler := middleware.Logging(mux)
|
||||
handler = middleware.Recovery(handler)
|
||||
handler = middleware.RequestID(handler)
|
||||
return handler
|
||||
}
|
||||
Reference in New Issue
Block a user