Skip to content

Commit

Permalink
fix:modify delete rival
Browse files Browse the repository at this point in the history
  • Loading branch information
superjcd committed Sep 25, 2023
1 parent 14d55ed commit 1c75169
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions service/sql_store/sql/rivals.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package sql

import (
"context"
"fmt"
"strings"

v1 "github.com/superjcd/rivalservice/genproto/v1"
"github.com/superjcd/rivalservice/service/sql_store"
Expand Down Expand Up @@ -76,6 +78,16 @@ func (ur *rivals) Delete(ctx context.Context, rq *v1.DeleteRivalRequest) error {
tx = tx.Where("asin = ?", rq.Asin)
}

if len(rq.Rivals) > 0 { // a, b, c =? 'a' 'b'
rivalAsins := make([]string, 0, 16)

for _, rival := range rq.Rivals {
rivalAsins = append(rivalAsins, fmt.Sprintf("'%s'", rival))
}
tx = tx.Where("rival_asin in (?)", strings.Join(rivalAsins, ", "))

}

return tx.Unscoped().Delete(&sql_store.Rival{}).Error

}

0 comments on commit 1c75169

Please sign in to comment.