Add backend foundation and config-driven workbench
This commit is contained in:
40
backend/internal/httpapi/handlers/entry_home_handler.go
Normal file
40
backend/internal/httpapi/handlers/entry_home_handler.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"cmr-backend/internal/apperr"
|
||||
"cmr-backend/internal/httpapi/middleware"
|
||||
"cmr-backend/internal/httpx"
|
||||
"cmr-backend/internal/service"
|
||||
)
|
||||
|
||||
type EntryHomeHandler struct {
|
||||
entryHomeService *service.EntryHomeService
|
||||
}
|
||||
|
||||
func NewEntryHomeHandler(entryHomeService *service.EntryHomeService) *EntryHomeHandler {
|
||||
return &EntryHomeHandler{entryHomeService: entryHomeService}
|
||||
}
|
||||
|
||||
func (h *EntryHomeHandler) Get(w http.ResponseWriter, r *http.Request) {
|
||||
auth := middleware.GetAuthContext(r.Context())
|
||||
if auth == nil {
|
||||
httpx.WriteError(w, apperr.New(http.StatusUnauthorized, "unauthorized", "missing auth context"))
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.entryHomeService.GetEntryHome(r.Context(), service.EntryHomeInput{
|
||||
UserID: auth.UserID,
|
||||
ChannelCode: r.URL.Query().Get("channelCode"),
|
||||
ChannelType: r.URL.Query().Get("channelType"),
|
||||
PlatformAppID: r.URL.Query().Get("platformAppId"),
|
||||
TenantCode: r.URL.Query().Get("tenantCode"),
|
||||
})
|
||||
if err != nil {
|
||||
httpx.WriteError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"data": result})
|
||||
}
|
||||
Reference in New Issue
Block a user