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) AppPurchase(ctx context.Context, req *v1.AppPurchaseReq) (res *v1.AppPurchaseRes, err error) {
	userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
	out, err := service.Chapter().AppPurchase(ctx, &model.ChapterAppPurchaseIn{
		Id:     req.Id,
		UserId: userId,
	})
	if err != nil {
		return nil, err
	}

	return &v1.AppPurchaseRes{
		Success: out.Success,
	}, nil
}
