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) ShelfRemove(ctx context.Context, req *v1.ShelfRemoveReq) (res *v1.ShelfRemoveRes, err error) {
	// 从 ctx 获取用户ID
	userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
	if userId == 0 {
		return nil, ecode.Logout
	}

	out, err := service.Bookshelve().Delete(ctx, &model.BookshelveDelIn{
		UserId:  userId,
		BookIds: req.BookIds,
	})
	if err != nil {
		return nil, err
	}

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