package lesson

import (
	"context"

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

	v1 "hotgo/api/api/lesson/v1"
	"hotgo/internal/dao"
	"hotgo/internal/model/entity"
)

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