fix: refactor system api (#3500)

* fix: refactor system api

* fix: search domains on get instance

* fix: search domains on get instance

* fix: return instance detail

* fix: implement user sorting column (#3469)

* fix: implement user sorting column

* fix: implement user sorting column

* fix: string column

* isOrderByLower

Co-authored-by: Livio Amstutz <livio.a@gmail.com>

* fix: user converter import

* Update instance.go

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
Fabi
2022-04-27 17:18:34 +02:00
committed by GitHub
parent fd1150f628
commit 70e98460ab
12 changed files with 422 additions and 132 deletions

View File

@@ -31,18 +31,16 @@ func (req *SearchRequest) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
}
if !req.SortingColumn.isZero() {
clause := "LOWER(" + sqlPlaceholder + ")"
clause := req.SortingColumn.orderBy()
if !req.Asc {
clause += " DESC"
}
query = query.OrderByClause(clause, req.SortingColumn.identifier())
query = query.OrderByClause(clause)
}
return query
}
const sqlPlaceholder = "?"
type SearchQuery interface {
toQuery(sq.SelectBuilder) sq.SelectBuilder
comp() sq.Sqlizer
@@ -367,8 +365,9 @@ func (t table) isZero() bool {
}
type Column struct {
name string
table table
name string
table table
isOrderByLower bool
}
func (c Column) identifier() string {
@@ -381,6 +380,13 @@ func (c Column) identifier() string {
return c.name
}
func (c Column) orderBy() string {
if !c.isOrderByLower {
return c.identifier()
}
return "LOWER(" + c.identifier() + ")"
}
func (c Column) setTable(t table) Column {
c.table = t
return c