36 lines
924 B
Go
36 lines
924 B
Go
package outcomes
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"apps/backend/internal/logic/growthmap"
|
|
"apps/backend/internal/middleware"
|
|
"apps/backend/internal/svc"
|
|
"apps/backend/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ReportConversionLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewReportConversionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReportConversionLogic {
|
|
return &ReportConversionLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
|
}
|
|
|
|
func (l *ReportConversionLogic) ReportConversion(req *types.ReportConversionReq) (*types.OutcomeEventPublic, error) {
|
|
uid, ok := middleware.UIDFrom(l.ctx)
|
|
if !ok || uid <= 0 {
|
|
return nil, fmt.Errorf("unauthorized")
|
|
}
|
|
e, err := l.svcCtx.Growth.ReportConversion(l.ctx, uid, req.Id, req.Amount, req.Note, req.Currency)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return growthmap.Outcome(e), nil
|
|
}
|