-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
42 lines (32 loc) · 1.21 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package repository
import (
"time"
"github.com/artem-malko/auth-and-go/infrastructure/database"
"github.com/google/uuid"
sq "github.com/Masterminds/squirrel"
"github.com/artem-malko/auth-and-go/models"
)
// DeactivateAccountByID set status "Deleted" for account and drop all account data
func (r *repository) DeactivateAccountByID(executor database.QueryExecutor, accountID uuid.UUID) error {
valuesToUpdate := map[string]interface{}{}
valuesToUpdate[accountStatusFieldName] = models.AccountStatusDeleted
valuesToUpdate[accountNameFieldName] = "Anonymous"
// @TODO remove settings
valuesToUpdate[updatedAtFieldName] = time.Now()
queryBuilder := r.psql.Update(accountsTableName).
SetMap(valuesToUpdate).
Where(sq.And{sq.Eq{idFieldName: accountID}, sq.NotEq{accountStatusFieldName: models.AccountStatusDeleted}}).
Suffix("")
return r.exec(executor, queryBuilder)
}
func (r *repository) DeleteUnconfirmedAccountsByAccountIDs(
executor database.QueryExecutor,
accountIDs []uuid.UUID,
) error {
queryBuilder := r.psql.Delete(accountsTableName).
Where(sq.And{
sq.Eq{idFieldName: accountIDs},
sq.Eq{accountStatusFieldName: models.AccountStatusUnconfirmed},
})
return r.exec(executor, queryBuilder)
}