package book

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

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

func (c *ControllerV1) ShelfAdd(ctx context.Context, req *v1.ShelfAddReq) (res *v1.ShelfAddRes, err error) {
	// 从 ctx 获取用户ID
	userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
	if userId == 0 {
		return nil, ecode.Logout
	}

	out, err := service.Bookshelve().Add(ctx, &model.BookshelveAddIn{
		UserId: userId,
		BookId: req.BookId,
	})
	if err != nil {
		return nil, err
	}

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