diff options
| author | 2023-07-07 11:34:12 +0200 | |
|---|---|---|
| committer | 2023-07-07 11:34:12 +0200 | |
| commit | e70bf8a6c82e3d5c943550b364fc6f8120f6f07e (patch) | |
| tree | f408ccff2e6f2451bf95ee9a5d96e5b678d686d5 /internal/db/bundb/domain.go | |
| parent | [chore/performance] Remove remaining 'whereEmptyOrNull' funcs (#1946) (diff) | |
| download | gotosocial-e70bf8a6c82e3d5c943550b364fc6f8120f6f07e.tar.xz | |
[chore/bugfix] Domain block tidying up, Implement first pass of `207 Multi-Status` (#1886)
* [chore/refactor] update domain block processing
* expose domain block import errors a lil better
* move/remove unused query keys
Diffstat (limited to 'internal/db/bundb/domain.go')
| -rw-r--r-- | internal/db/bundb/domain.go | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/internal/db/bundb/domain.go b/internal/db/bundb/domain.go index 5c92645de..2e8ce2a6b 100644 --- a/internal/db/bundb/domain.go +++ b/internal/db/bundb/domain.go @@ -42,7 +42,7 @@ func (d *domainDB) CreateDomainBlock(ctx context.Context, block *gtsmodel.Domain return err } - // Attempt to store domain in DB + // Attempt to store domain block in DB if _, err := d.conn.NewInsert(). Model(block). Exec(ctx); err != nil { @@ -82,6 +82,33 @@ func (d *domainDB) GetDomainBlock(ctx context.Context, domain string) (*gtsmodel return &block, nil } +func (d *domainDB) GetDomainBlocks(ctx context.Context) ([]*gtsmodel.DomainBlock, error) { + blocks := []*gtsmodel.DomainBlock{} + + if err := d.conn. + NewSelect(). + Model(&blocks). + Scan(ctx); err != nil { + return nil, d.conn.ProcessError(err) + } + + return blocks, nil +} + +func (d *domainDB) GetDomainBlockByID(ctx context.Context, id string) (*gtsmodel.DomainBlock, db.Error) { + var block gtsmodel.DomainBlock + + q := d.conn. + NewSelect(). + Model(&block). + Where("? = ?", bun.Ident("domain_block.id"), id) + if err := q.Scan(ctx); err != nil { + return nil, d.conn.ProcessError(err) + } + + return &block, nil +} + func (d *domainDB) DeleteDomainBlock(ctx context.Context, domain string) db.Error { // Normalize the domain as punycode domain, err := util.Punify(domain) |
