package book

import (
	"context"
	"server/internal/model"
	"server/internal/service"

	v1 "server/api/book/v1"

	"server/utility/ecode"

	"github.com/gogf/gf/v2/errors/gerror"
)

func (c *ControllerV1) BookCoverImage(ctx context.Context, req *v1.BookCoverImageReq) (res *v1.BookCoverImageRes, err error) {
	if req.File == nil {
		return nil, gerror.NewCode(ecode.Fail.Sub("image_file_required").Code())
	}
	image, err := service.Upload().UploadImage(ctx, &model.UploadImageIn{File: req.File, Type: "book"})
	if err != nil {
		return nil, err
	}
	return &v1.BookCoverImageRes{ImageUrl: image.ImageUrl}, nil
}
