49 lines
1014 B
Go
49 lines
1014 B
Go
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
"server/internal/model/common"
|
|
"server/internal/pkg/httputil"
|
|
"server/internal/router"
|
|
"server/internal/service/admin"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
type AccessLogHandler struct {
|
|
accessLogService *admin.AccessLogService
|
|
}
|
|
|
|
var _ router.Registrar = (*AccessLogHandler)(nil)
|
|
|
|
func NewAccessLogHandler(accessLogService *admin.AccessLogService) *AccessLogHandler {
|
|
return &AccessLogHandler{
|
|
accessLogService: accessLogService,
|
|
}
|
|
}
|
|
|
|
func (h *AccessLogHandler) Register(r chi.Router) {
|
|
r.Route("/access-logs", func(r chi.Router) {
|
|
r.Get("/", h.List)
|
|
})
|
|
}
|
|
|
|
func (h *AccessLogHandler) List(w http.ResponseWriter, r *http.Request) {
|
|
pagination := httputil.Pagination(r)
|
|
|
|
result, err := h.accessLogService.List(r.Context(), pagination)
|
|
if err != nil {
|
|
httputil.Fail(w, err)
|
|
return
|
|
}
|
|
|
|
resp := common.PageResponse{
|
|
Page: pagination.Page,
|
|
PageSize: pagination.PageSize,
|
|
List: result.List,
|
|
Total: result.Total,
|
|
}
|
|
|
|
httputil.OkWithPage(w, &resp)
|
|
}
|