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) AppRate(ctx context.Context, req *v1.AppRateReq) (res *v1.AppRateRes, err error) {
	userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
	out, err := service.Book().AppRate(ctx, &model.BookAppRateIn{
		BookId: req.BookId,
		Rating: req.Rating,
		UserId: userId,
	})
	if err != nil {
		return nil, err
	}

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