@@ -30,7 +30,7 @@ func (r *accountSharePolicyRepository) ListAccountSharePolicies(ctx context.Cont
3030 }
3131
3232 query := `
33- SELECT id, scope_type, scope_id, platform, owner_share_ratio::text, version, enabled,
33+ SELECT id, scope_type, scope_id, platform, owner_share_ratio::text, invite_share_ratio::text, version, enabled,
3434 effective_at, created_by_admin_id, created_at, updated_at, deleted_at
3535 FROM account_share_policies
3636 WHERE deleted_at IS NULL` + where + `
@@ -60,7 +60,7 @@ func (r *accountSharePolicyRepository) ListAccountSharePolicies(ctx context.Cont
6060
6161func (r * accountSharePolicyRepository ) GetAccountSharePolicyByID (ctx context.Context , id int64 ) (* service.AccountSharePolicy , error ) {
6262 row := r .db .QueryRowContext (ctx , `
63- SELECT id, scope_type, scope_id, platform, owner_share_ratio::text, version, enabled,
63+ SELECT id, scope_type, scope_id, platform, owner_share_ratio::text, invite_share_ratio::text, version, enabled,
6464 effective_at, created_by_admin_id, created_at, updated_at, deleted_at
6565 FROM account_share_policies
6666 WHERE id = $1 AND deleted_at IS NULL
@@ -85,7 +85,7 @@ func (r *accountSharePolicyRepository) ResolveEnabledAccountSharePolicy(ctx cont
8585
8686func (r * accountSharePolicyRepository ) queryEnabledAccountSharePolicy (ctx context.Context , predicate string , args ... any ) (* service.AccountSharePolicy , bool , error ) {
8787 query := `
88- SELECT id, scope_type, scope_id, platform, owner_share_ratio::text, version, enabled,
88+ SELECT id, scope_type, scope_id, platform, owner_share_ratio::text, invite_share_ratio::text, version, enabled,
8989 effective_at, created_by_admin_id, created_at, updated_at, deleted_at
9090 FROM account_share_policies
9191 WHERE deleted_at IS NULL
@@ -108,17 +108,18 @@ func (r *accountSharePolicyRepository) queryEnabledAccountSharePolicy(ctx contex
108108func (r * accountSharePolicyRepository ) CreateAccountSharePolicy (ctx context.Context , input service.CreateAccountSharePolicyInput ) (* service.AccountSharePolicy , error ) {
109109 row := r .db .QueryRowContext (ctx , `
110110 INSERT INTO account_share_policies (
111- scope_type, scope_id, platform, owner_share_ratio, enabled, effective_at, created_by_admin_id
111+ scope_type, scope_id, platform, owner_share_ratio, invite_share_ratio, enabled, effective_at, created_by_admin_id
112112 ) VALUES (
113- $1, $2, $3, $4::numeric, $5, $6, $7
113+ $1, $2, $3, $4::numeric, $5::numeric , $6, $7, $8
114114 )
115- RETURNING id, scope_type, scope_id, platform, owner_share_ratio::text, version, enabled,
115+ RETURNING id, scope_type, scope_id, platform, owner_share_ratio::text, invite_share_ratio::text, version, enabled,
116116 effective_at, created_by_admin_id, created_at, updated_at, deleted_at
117117 ` ,
118118 input .ScopeType ,
119119 nullablePtrInt64 (input .ScopeID ),
120120 nullableStringPtr (input .Platform ),
121121 strconv .FormatFloat (input .OwnerShareRatio , 'f' , 6 , 64 ),
122+ strconv .FormatFloat (input .InviteShareRatio , 'f' , 6 , 64 ),
122123 * input .Enabled ,
123124 * input .EffectiveAt ,
124125 nullablePtrInt64 (input .CreatedByAdminID ),
@@ -135,6 +136,7 @@ func (r *accountSharePolicyRepository) UpdateAccountSharePolicy(ctx context.Cont
135136 scopeID := current .ScopeID
136137 platform := current .Platform
137138 ratio := current .OwnerShareRatio
139+ inviteRatio := current .InviteShareRatio
138140 enabled := current .Enabled
139141 effectiveAt := current .EffectiveAt
140142 if input .ScopeType != nil {
@@ -160,6 +162,9 @@ func (r *accountSharePolicyRepository) UpdateAccountSharePolicy(ctx context.Cont
160162 if input .OwnerShareRatio != nil {
161163 ratio = * input .OwnerShareRatio
162164 }
165+ if input .InviteShareRatio != nil {
166+ inviteRatio = * input .InviteShareRatio
167+ }
163168 if input .Enabled != nil {
164169 enabled = * input .Enabled
165170 }
@@ -173,14 +178,15 @@ func (r *accountSharePolicyRepository) UpdateAccountSharePolicy(ctx context.Cont
173178 scope_id = $3,
174179 platform = $4,
175180 owner_share_ratio = $5::numeric,
176- enabled = $6,
177- effective_at = $7,
181+ invite_share_ratio = $6::numeric,
182+ enabled = $7,
183+ effective_at = $8,
178184 version = version + 1,
179185 updated_at = NOW()
180186 WHERE id = $1 AND deleted_at IS NULL
181- RETURNING id, scope_type, scope_id, platform, owner_share_ratio::text, version, enabled,
187+ RETURNING id, scope_type, scope_id, platform, owner_share_ratio::text, invite_share_ratio::text, version, enabled,
182188 effective_at, created_by_admin_id, created_at, updated_at, deleted_at
183- ` , id , scopeType , nullablePtrInt64 (scopeID ), nullableStringPtr (platform ), strconv .FormatFloat (ratio , 'f' , 6 , 64 ), enabled , effectiveAt )
189+ ` , id , scopeType , nullablePtrInt64 (scopeID ), nullableStringPtr (platform ), strconv .FormatFloat (ratio , 'f' , 6 , 64 ), strconv . FormatFloat ( inviteRatio , 'f' , 6 , 64 ), enabled , effectiveAt )
184190 policy , err := scanAccountSharePolicy (row )
185191 if errors .Is (err , sql .ErrNoRows ) {
186192 return nil , service .ErrAccountNotFound
@@ -237,6 +243,7 @@ func scanAccountSharePolicy(scanner sqlScanner) (*service.AccountSharePolicy, er
237243 scopeID sql.NullInt64
238244 platform sql.NullString
239245 ratioRaw string
246+ inviteRatioRaw string
240247 createdByAdmin sql.NullInt64
241248 deletedAt sql.NullTime
242249 )
@@ -246,6 +253,7 @@ func scanAccountSharePolicy(scanner sqlScanner) (*service.AccountSharePolicy, er
246253 & scopeID ,
247254 & platform ,
248255 & ratioRaw ,
256+ & inviteRatioRaw ,
249257 & policy .Version ,
250258 & policy .Enabled ,
251259 & policy .EffectiveAt ,
@@ -261,6 +269,11 @@ func scanAccountSharePolicy(scanner sqlScanner) (*service.AccountSharePolicy, er
261269 return nil , err
262270 }
263271 policy .OwnerShareRatio = ratio
272+ inviteRatio , err := strconv .ParseFloat (strings .TrimSpace (inviteRatioRaw ), 64 )
273+ if err != nil {
274+ return nil , err
275+ }
276+ policy .InviteShareRatio = inviteRatio
264277 if scopeID .Valid {
265278 policy .ScopeID = & scopeID .Int64
266279 }
0 commit comments