package author

import (
	"context"
	"github.com/gogf/gf/v2/frame/g"
	"server/internal/model"
	"server/internal/service"

	"server/api/author/v1"
)

func (c *ControllerV1) AuthorInfo(ctx context.Context, req *v1.AuthorInfoReq) (res *v1.AuthorInfoRes, err error) {
	userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
	out, err := service.Author().AuthorInfo(ctx, &model.AuthorInfoIn{UserId: userId})
	if err != nil {
		return nil, err
	}
	return &v1.AuthorInfoRes{
		Id:      out.Id,
		PenName: out.PenName,
		Role:    out.Role,
	}, nil
}
