feat: add stickers delete api
This commit is contained in:
@@ -206,6 +206,29 @@ func (r *RewardRepo) CreateCustom(ctx context.Context, key, name, meaning, image
|
||||
return &w, nil
|
||||
}
|
||||
|
||||
// DeleteCustom removes an admin-made reward from the catalog.
|
||||
//
|
||||
// Both sadhna_reward_grants.reward_id and saved_stickers.reward_id are
|
||||
// ON DELETE CASCADE, so this also takes it out of every devotee's gallery and
|
||||
// sticker vault. Stickers already SENT in a chat are unaffected: those copy
|
||||
// the artwork onto the message rather than referencing the catalog, so history
|
||||
// stays intact.
|
||||
//
|
||||
// Restricted to custom keys. A seeded reward would come straight back on the
|
||||
// next Seed run, and deleting one would rip a streak reward out of the
|
||||
// galleries of everyone who earned it.
|
||||
func (r *RewardRepo) DeleteCustom(ctx context.Context, key string) error {
|
||||
tag, err := r.pg.Pool.Exec(ctx,
|
||||
`DELETE FROM sadhna_rewards WHERE key = $1 AND key LIKE 'custom\_%'`, key)
|
||||
if err != nil {
|
||||
return fmt.Errorf("delete custom reward: %w", err)
|
||||
}
|
||||
if tag.RowsAffected() == 0 {
|
||||
return ErrRewardNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ByKey looks up one reward from the catalog.
|
||||
func (r *RewardRepo) ByKey(ctx context.Context, key string) (*model.SadhnaReward, error) {
|
||||
var w model.SadhnaReward
|
||||
|
||||
Reference in New Issue
Block a user