package book

import (
	"context"
	v1 "server/api/book/v1"
	"server/internal/model"
	"server/internal/service"

	"github.com/gogf/gf/v2/frame/g"
)

func (c *ControllerV1) AppList(ctx context.Context, req *v1.AppListReq) (res *v1.AppListRes, err error) {
	userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
	out, err := service.Book().AppList(ctx, &model.BookAppListIn{
		Page:          req.Page,
		Size:          req.Size,
		IsRecommended: req.IsRecommended,
		IsFeatured:    req.IsFeatured,
		IsLatest:      req.IsLatest,
		IsHot:         req.IsHot,
		CategoryId:    req.CategoryId,
		Title:         req.Title,
		AuthorId:      req.AuthorId,
		UserId:        userId,
		Language:      req.Language,
		Sort:          req.Sort,
	})
	if err != nil {
		return nil, err
	}

	return &v1.AppListRes{
		Total: out.Total,
		List:  out.List,
	}, nil
}
