package lesson

import (
	"context"

	"hotgo/internal/dao"
	"hotgo/internal/model/entity"

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

	v1 "hotgo/api/api/lesson/v1"
)

func (c *ControllerV1) LessonSectionDetail(ctx context.Context, req *v1.LessonSectionDetailReq) (res *v1.LessonSectionDetailRes, err error) {
	section := new(entity.LessonSection)
	err = dao.LessonSection.Ctx(ctx).Where("id = ?", req.Id).Scan(section)
	if err != nil {
		return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误")
	}
	if section.Id == 0 {
		return nil, gerror.NewCode(gcode.CodeNotFound, "课程章节不存在")
	}
	res = &v1.LessonSectionDetailRes{
		LessonSection: section,
	}
	return
}
