59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
|
|
package threads_account
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
domusecase "haixun-backend/internal/model/threads_account/domain/usecase"
|
||
|
|
"haixun-backend/internal/svc"
|
||
|
|
"haixun-backend/internal/types"
|
||
|
|
)
|
||
|
|
|
||
|
|
type GetThreadsAccountConnectionLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewGetThreadsAccountConnectionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetThreadsAccountConnectionLogic {
|
||
|
|
return &GetThreadsAccountConnectionLogic{ctx: ctx, svcCtx: svcCtx}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *GetThreadsAccountConnectionLogic) GetThreadsAccountConnection(req *types.ThreadsAccountPath) (*types.ThreadsAccountConnectionData, error) {
|
||
|
|
tenantID, uid, err := actorFrom(l.ctx)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
data, err := l.svcCtx.ThreadsAccount.GetConnection(l.ctx, tenantID, uid, req.ID)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return toConnectionData(data), nil
|
||
|
|
}
|
||
|
|
|
||
|
|
type UpdateThreadsAccountConnectionLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewUpdateThreadsAccountConnectionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateThreadsAccountConnectionLogic {
|
||
|
|
return &UpdateThreadsAccountConnectionLogic{ctx: ctx, svcCtx: svcCtx}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *UpdateThreadsAccountConnectionLogic) UpdateThreadsAccountConnection(
|
||
|
|
req *types.ThreadsAccountPath,
|
||
|
|
body *types.UpdateThreadsAccountConnectionReq,
|
||
|
|
) (*types.ThreadsAccountConnectionData, error) {
|
||
|
|
tenantID, uid, err := actorFrom(l.ctx)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
data, err := l.svcCtx.ThreadsAccount.UpdateConnection(l.ctx, domusecase.UpdateConnectionRequest{
|
||
|
|
TenantID: tenantID,
|
||
|
|
OwnerUID: uid,
|
||
|
|
AccountID: req.ID,
|
||
|
|
Prefs: toConnectionPatch(body),
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return toConnectionData(data), nil
|
||
|
|
}
|