53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package system
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"management/internal/erpserver/handler"
|
|
"management/internal/erpserver/model/dto"
|
|
v1 "management/internal/erpserver/service/v1"
|
|
"management/internal/erpserver/templ/system/loginlog"
|
|
"management/internal/pkg/convertor"
|
|
)
|
|
|
|
type LoginLogHandler struct {
|
|
*handler.Handler
|
|
loginLogService v1.LoginLogService
|
|
}
|
|
|
|
func NewLoginLogHandler(handler *handler.Handler, loginLogService v1.LoginLogService) *LoginLogHandler {
|
|
return &LoginLogHandler{
|
|
Handler: handler,
|
|
loginLogService: loginLogService,
|
|
}
|
|
}
|
|
|
|
func (h *LoginLogHandler) List(w http.ResponseWriter, r *http.Request) {
|
|
switch r.Method {
|
|
case http.MethodGet:
|
|
ctx := r.Context()
|
|
h.Render(ctx, w, loginlog.List(ctx))
|
|
case http.MethodPost:
|
|
var q dto.SearchDto
|
|
q.SearchTimeBegin, q.SearchTimeEnd = convertor.DefaultStartTimeAndEndTime(r.PostFormValue("timeBegin"), r.PostFormValue("timeEnd"))
|
|
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.loginLogService.List(r.Context(), q)
|
|
if err != nil {
|
|
h.JSONErr(w, err.Error())
|
|
return
|
|
}
|
|
|
|
data := handler.ResponseList{
|
|
Code: 0,
|
|
Message: "ok",
|
|
Count: count,
|
|
Data: res,
|
|
}
|
|
h.JSON(w, data)
|
|
default:
|
|
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
|
|
}
|
|
}
|