package book

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

func (c *ControllerV1) Edit(ctx context.Context, req *v1.EditReq) (res *v1.EditRes, err error) {
	out, err := service.Book().Update(ctx, &model.BookEditIn{
		Id:            req.Id,
		AuthorId:      req.AuthorId,
		CategoryId:    req.CategoryId,
		Title:         req.Title,
		CoverUrl:      req.CoverUrl,
		Description:   req.Description,
		Status:        req.Status,
		Tags:          req.Tags,
		IsRecommended: req.IsRecommended,
	})
	if err != nil {
		return nil, err
	}

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