feat: update template
This commit is contained in:
48
internal/handler/admin/access_log.go
Normal file
48
internal/handler/admin/access_log.go
Normal file
@@ -0,0 +1,48 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user