package ads

import (
	"context"

	"github.com/gogf/gf/v2/frame/g"

	v1 "server/api/ads/v1"
	"server/internal/model"
	"server/internal/service"
)

func (c *ControllerV1) Upload(ctx context.Context, req *v1.UploadReq) (res *v1.UploadRes, err error) {
	userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
	out, err := service.Ads().Upload(ctx, &model.AdsUploadIn{
		UserId:     userId,
		NodeUid:    req.NodeUid,
		DeviceCode: req.DeviceCode,
		Data:       req.Data,
	})
	if err != nil {
		return nil, err
	}
	return &v1.UploadRes{
		Success: out.Success,
	}, nil
}