domain_get.go, domain_list.go: clean up SQL
This commit is contained in:
parent
c94e5ca41f
commit
72a3f87c28
@ -2,41 +2,31 @@ package main
|
||||
|
||||
import ()
|
||||
|
||||
func domainGet(dmn string) (domain, error) {
|
||||
if dmn == "" {
|
||||
return domain{}, errorMissingField
|
||||
}
|
||||
|
||||
statement := `
|
||||
SELECT
|
||||
domain,
|
||||
ownerHex,
|
||||
name,
|
||||
creationDate,
|
||||
state,
|
||||
importedComments,
|
||||
autoSpamFilter,
|
||||
requireModeration,
|
||||
requireIdentification,
|
||||
moderateAllAnonymous,
|
||||
emailNotificationPolicy,
|
||||
commentoProvider,
|
||||
googleProvider,
|
||||
twitterProvider,
|
||||
githubProvider,
|
||||
gitlabProvider,
|
||||
ssoProvider,
|
||||
ssoSecret,
|
||||
ssoUrl,
|
||||
defaultSortPolicy
|
||||
FROM domains
|
||||
WHERE domain = $1;
|
||||
var domainsRowColumns = `
|
||||
domains.domain,
|
||||
domains.ownerHex,
|
||||
domains.name,
|
||||
domains.creationDate,
|
||||
domains.state,
|
||||
domains.importedComments,
|
||||
domains.autoSpamFilter,
|
||||
domains.requireModeration,
|
||||
domains.requireIdentification,
|
||||
domains.moderateAllAnonymous,
|
||||
domains.emailNotificationPolicy,
|
||||
domains.commentoProvider,
|
||||
domains.googleProvider,
|
||||
domains.twitterProvider,
|
||||
domains.githubProvider,
|
||||
domains.gitlabProvider,
|
||||
domains.ssoProvider,
|
||||
domains.ssoSecret,
|
||||
domains.ssoUrl,
|
||||
domains.defaultSortPolicy
|
||||
`
|
||||
row := db.QueryRow(statement, dmn)
|
||||
|
||||
var err error
|
||||
d := domain{}
|
||||
if err = row.Scan(
|
||||
func domainsRowScan(s sqlScanner, d *domain) error {
|
||||
return s.Scan(
|
||||
&d.Domain,
|
||||
&d.OwnerHex,
|
||||
&d.Name,
|
||||
@ -56,7 +46,25 @@ func domainGet(dmn string) (domain, error) {
|
||||
&d.SsoProvider,
|
||||
&d.SsoSecret,
|
||||
&d.SsoUrl,
|
||||
&d.DefaultSortPolicy); err != nil {
|
||||
&d.DefaultSortPolicy,
|
||||
)
|
||||
}
|
||||
|
||||
func domainGet(dmn string) (domain, error) {
|
||||
if dmn == "" {
|
||||
return domain{}, errorMissingField
|
||||
}
|
||||
|
||||
statement := `
|
||||
SELECT ` + domainsRowColumns + `
|
||||
FROM domains
|
||||
WHERE domain = $1;
|
||||
`
|
||||
row := db.QueryRow(statement, dmn)
|
||||
|
||||
var err error
|
||||
d := domain{}
|
||||
if err = domainsRowScan(row, &d); err != nil {
|
||||
return d, errorNoSuchDomain
|
||||
}
|
||||
|
||||
|
@ -10,27 +10,7 @@ func domainList(ownerHex string) ([]domain, error) {
|
||||
}
|
||||
|
||||
statement := `
|
||||
SELECT
|
||||
domain,
|
||||
ownerHex,
|
||||
name,
|
||||
creationDate,
|
||||
state,
|
||||
importedComments,
|
||||
autoSpamFilter,
|
||||
requireModeration,
|
||||
requireIdentification,
|
||||
moderateAllAnonymous,
|
||||
emailNotificationPolicy,
|
||||
commentoProvider,
|
||||
googleProvider,
|
||||
twitterProvider,
|
||||
githubProvider,
|
||||
gitlabProvider,
|
||||
ssoProvider,
|
||||
ssoSecret,
|
||||
ssoUrl,
|
||||
defaultSortPolicy
|
||||
SELECT ` + domainsRowColumns + `
|
||||
FROM domains
|
||||
WHERE ownerHex=$1;
|
||||
`
|
||||
@ -43,28 +23,8 @@ func domainList(ownerHex string) ([]domain, error) {
|
||||
|
||||
domains := []domain{}
|
||||
for rows.Next() {
|
||||
d := domain{}
|
||||
if err = rows.Scan(
|
||||
&d.Domain,
|
||||
&d.OwnerHex,
|
||||
&d.Name,
|
||||
&d.CreationDate,
|
||||
&d.State,
|
||||
&d.ImportedComments,
|
||||
&d.AutoSpamFilter,
|
||||
&d.RequireModeration,
|
||||
&d.RequireIdentification,
|
||||
&d.ModerateAllAnonymous,
|
||||
&d.EmailNotificationPolicy,
|
||||
&d.CommentoProvider,
|
||||
&d.GoogleProvider,
|
||||
&d.TwitterProvider,
|
||||
&d.GithubProvider,
|
||||
&d.GitlabProvider,
|
||||
&d.SsoProvider,
|
||||
&d.SsoSecret,
|
||||
&d.SsoUrl,
|
||||
&d.DefaultSortPolicy); err != nil {
|
||||
var d domain
|
||||
if err = domainsRowScan(rows, &d); err != nil {
|
||||
logger.Errorf("cannot Scan domain: %v", err)
|
||||
return nil, errorInternal
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user