package fronted

import (
	"go-admin/app/admin/service/appservice"
	"go-admin/app/admin/service/common"
	"go-admin/app/admin/service/dto"

	"github.com/gin-gonic/gin"
	"github.com/go-admin-team/go-admin-core/sdk/api"
)

type InviteLog struct {
	api.Api
}

// GetPage 获取InviteLog列表
func (e InviteLog) GetPersonnalPage(c *gin.Context) {
	s := appservice.InviteLog{}
	req := dto.PersonnalInviteLogPageReq{}
	err := e.MakeContext(c).
		MakeOrm().
		Bind(&req).
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}

	datas := make([]dto.InviteLogResp, 0)
	req.UserId = common.GetUserId(c)

	if req.UserId == 0 {
		req.UserId = -1
	}
	var count int64
	err = s.GetPage(&req, &datas, &count)

	if err != nil {
		e.Error(500, err, err.Error())
		return
	}

	e.PageOK(datas, int(count), req.PageIndex, req.PageSize, "success")
}
