package user

import (
	"context"

	"github.com/gin-gonic/gin"
	"tutorial.sqlc.dev/app/internal/author/gen"
)

type Controller struct {
	queries gen.Queries
}

func NewController(conn gen.DBTX) Controller {
	return Controller{
		queries: *gen.New(conn),
	}
}

func (u *Controller) ListAuthors(ctx *gin.Context) {
	authors, err := u.queries.ListAuthors(context.Background())
	if err != nil {
		ctx.AbortWithError(500, err)
	}
	ctx.JSON(200, authors)
}
