package chapter

import (
	"context"
	v1 "server/api/chapter/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.Chapter().AppList(ctx, &model.ChapterAppListIn{
		BookId: req.BookId,
		IsDesc: req.IsDesc,
		Page:   req.Page,
		Size:   req.Size,
		UserId: userId,
	})
	if err != nil {
		return nil, err
	}

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