package book

import (
	"context"

	v1 "server/api/book/v1"
	"server/internal/model"
	"server/internal/service"

	"github.com/gogf/gf/v2/net/ghttp"
)

func (c *ControllerV1) MyList(ctx context.Context, req *v1.MyListReq) (res *v1.MyListRes, err error) {
	// 从ctx获取userId
	userId := ghttp.RequestFromCtx(ctx).GetCtxVar("id").Int64()
	in := &model.MyBookListIn{
		Type:   req.Type,
		Page:   req.Page,
		Size:   req.Size,
		UserId: userId,
		Sort:   req.Sort,
	}
	result, err := service.Book().MyList(ctx, in)
	if err != nil {
		return nil, err
	}
	res = &v1.MyListRes{
		Total: result.Total,
		List:  result.List,
	}
	return
}
