52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package system
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"management/internal/erpserver/model/dto"
|
|
v1 "management/internal/erpserver/service/v1"
|
|
"management/internal/pkg/convertor"
|
|
"management/internal/pkg/tpl"
|
|
)
|
|
|
|
type auditHandler struct {
|
|
render tpl.Renderer
|
|
svc v1.AuditLogService
|
|
}
|
|
|
|
func NewAuditHandler(render tpl.Renderer, svc v1.AuditLogService) *auditHandler {
|
|
return &auditHandler{
|
|
render: render,
|
|
svc: svc,
|
|
}
|
|
}
|
|
|
|
func (h *auditHandler) List(w http.ResponseWriter, r *http.Request) {
|
|
switch r.Method {
|
|
case http.MethodGet:
|
|
h.render.HTML(w, r, "audit_log/list.tmpl", nil)
|
|
case http.MethodPost:
|
|
var q dto.SearchDto
|
|
q.SearchTimeBegin, q.SearchTimeEnd = convertor.DefaultStartTimeAndEndTime(r.PostFormValue("timeBegin"), r.PostFormValue("timeEnd"))
|
|
q.SearchName = r.PostFormValue("name")
|
|
q.SearchEmail = r.PostFormValue("email")
|
|
q.Page = convertor.ConvertInt(r.PostFormValue("page"), 1)
|
|
q.Rows = convertor.ConvertInt(r.PostFormValue("rows"), 10)
|
|
res, count, err := h.svc.List(r.Context(), q)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
data := tpl.ResponseList{
|
|
Code: 0,
|
|
Message: "ok",
|
|
Count: count,
|
|
Data: res,
|
|
}
|
|
h.render.JSON(w, data)
|
|
default:
|
|
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
|
|
}
|
|
}
|